A platform for community discussion. Free, open, simple.
DEV: Add missing test case (#19510)
Alan Guo Xiang Tan5bd29b89dd32
diff --git a/app/assets/javascripts/discourse/app/widgets/post-small-action.js b/app/assets/javascripts/discourse/app/widgets/post-small-action.jsindex bc23ebf97ab..cf502373f6c 100644--- a/app/assets/javascripts/discourse/app/widgets/post-small-action.js+++ b/app/assets/javascripts/discourse/app/widgets/post-small-action.js@@ -87,6 +87,10 @@ export function addPostSmallActionClassesCallback(callback) {addPostSmallActionClassesCallbacks.push(callback);}+export function resetPostSmallActionClassesCallbacks() {+ addPostSmallActionClassesCallbacks.length = 0;+}+export default createWidget("post-small-action", {buildKey: (attrs) => `post-small-act-${attrs.id}`,tagName: "div.small-action.onscreen-post",@@ -97,13 +101,15 @@ export default createWidget("post-small-action", {buildClasses(attrs) {let classNames = [];+if (attrs.deleted) {classNames.push("deleted");}- if (addPostSmallActionClassesCallbacks) {+ if (addPostSmallActionClassesCallbacks.length > 0) {addPostSmallActionClassesCallbacks.forEach((callback) => {const additionalClasses = callback.call(this, attrs);+if (additionalClasses) {classNames.push(...additionalClasses);}diff --git a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.js b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.jsindex 90a7658f136..2de44cca90d 100644--- a/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/widgets/post-small-action-test.js@@ -3,6 +3,8 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";import { render } from "@ember/test-helpers";import { exists } from "discourse/tests/helpers/qunit-helpers";import { hbs } from "ember-cli-htmlbars";+import { withPluginApi } from "discourse/lib/plugin-api";+import { resetPostSmallActionClassesCallbacks } from "discourse/widgets/post-small-action";module("Integration | Component | Widget | post-small-action",@@ -89,5 +91,41 @@ module("it adds the recover small action button");});++ test("`addPostSmallActionClassesCallback` plugin api", async function (assert) {+ try {+ withPluginApi("1.6.0", (api) => {+ api.addPostSmallActionClassesCallback((postAttrs) => {+ if (postAttrs.canRecover) {+ return ["abcde"];+ }+ });+ });++ this.set("args", { id: 123, canRecover: false });++ await render(+ hbs`<MountWidget @widget="post-small-action" @args={{this.args}} />`+ );++ assert.notOk(+ exists(".abcde"),+ "custom CSS class is not added when condition is not met"+ );++ this.set("args", { id: 123, canRecover: true });++ await render(+ hbs`<MountWidget @widget="post-small-action" @args={{this.args}} />`+ );++ assert.ok(+ exists(".abcde"),+ "it adds custom CSS class as registered from the plugin API"+ );+ } finally {+ resetPostSmallActionClassesCallbacks();+ }+ });});