From 022dba4727ebd030c7f3d0d24206d4828dfc672a Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 17 Dec 2021 09:55:54 +0100 Subject: [PATCH] DEV: supports actionClick for small actions (#15331) --- .../app/widgets/post-small-action.js | 17 ++++++++++++++++- .../widgets/post-small-action-test.js | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/widgets/post-small-action.js b/app/assets/javascripts/discourse/app/widgets/post-small-action.js index f7a0bb6df75..6434e4ba8d8 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-small-action.js +++ b/app/assets/javascripts/discourse/app/widgets/post-small-action.js @@ -79,8 +79,23 @@ export default createWidget("post-small-action", { }, buildClasses(attrs) { + const classes = []; + + if (attrs.actionClick) { + classes.push("clickable"); + } + if (attrs.deleted) { - return "deleted"; + classes.push("deleted"); + } + + return classes; + }, + + click(event) { + if (this.attrs.actionClick) { + event.preventDefault(); + this.attrs.actionClick(); } }, diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/post-small-action-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/post-small-action-test.js index 087835ab12e..11d814e1a13 100644 --- a/app/assets/javascripts/discourse/tests/integration/widgets/post-small-action-test.js +++ b/app/assets/javascripts/discourse/tests/integration/widgets/post-small-action-test.js @@ -3,6 +3,7 @@ import componentTest, { } from "discourse/tests/helpers/component-test"; import { discourseModule, exists } from "discourse/tests/helpers/qunit-helpers"; import hbs from "htmlbars-inline-precompile"; +import { click } from "@ember/test-helpers"; discourseModule( "Integration | Component | Widget | post-small-action", @@ -34,6 +35,24 @@ discourseModule( }, }); + componentTest("is clickable if actionClick", { + template: hbs`{{mount-widget widget="post-small-action" args=args}}`, + beforeEach() { + this.set("args", { + id: 123, + actionClick: () => { + document.querySelector(".small-action").style.background = "red"; + }, + }); + }, + async test(assert) { + const clickable = document.querySelector(".small-action.clickable"); + await click(clickable); + + assert.equal(clickable.style.background, "red", "it calls the action"); + }, + }); + componentTest("does not show edit button if canRecover even if canEdit", { template: hbs`{{mount-widget widget="post-small-action" args=args}}`, beforeEach() {