mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
parent
baf78d3d91
commit
5bd29b89dd
@ -87,6 +87,10 @@ export function addPostSmallActionClassesCallback(callback) {
|
|||||||
addPostSmallActionClassesCallbacks.push(callback);
|
addPostSmallActionClassesCallbacks.push(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetPostSmallActionClassesCallbacks() {
|
||||||
|
addPostSmallActionClassesCallbacks.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
export default createWidget("post-small-action", {
|
export default createWidget("post-small-action", {
|
||||||
buildKey: (attrs) => `post-small-act-${attrs.id}`,
|
buildKey: (attrs) => `post-small-act-${attrs.id}`,
|
||||||
tagName: "div.small-action.onscreen-post",
|
tagName: "div.small-action.onscreen-post",
|
||||||
@ -97,13 +101,15 @@ export default createWidget("post-small-action", {
|
|||||||
|
|
||||||
buildClasses(attrs) {
|
buildClasses(attrs) {
|
||||||
let classNames = [];
|
let classNames = [];
|
||||||
|
|
||||||
if (attrs.deleted) {
|
if (attrs.deleted) {
|
||||||
classNames.push("deleted");
|
classNames.push("deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addPostSmallActionClassesCallbacks) {
|
if (addPostSmallActionClassesCallbacks.length > 0) {
|
||||||
addPostSmallActionClassesCallbacks.forEach((callback) => {
|
addPostSmallActionClassesCallbacks.forEach((callback) => {
|
||||||
const additionalClasses = callback.call(this, attrs);
|
const additionalClasses = callback.call(this, attrs);
|
||||||
|
|
||||||
if (additionalClasses) {
|
if (additionalClasses) {
|
||||||
classNames.push(...additionalClasses);
|
classNames.push(...additionalClasses);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|||||||
import { render } from "@ember/test-helpers";
|
import { render } from "@ember/test-helpers";
|
||||||
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { hbs } from "ember-cli-htmlbars";
|
import { hbs } from "ember-cli-htmlbars";
|
||||||
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
|
import { resetPostSmallActionClassesCallbacks } from "discourse/widgets/post-small-action";
|
||||||
|
|
||||||
module(
|
module(
|
||||||
"Integration | Component | Widget | post-small-action",
|
"Integration | Component | Widget | post-small-action",
|
||||||
@ -89,5 +91,41 @@ module(
|
|||||||
"it adds the recover small action button"
|
"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();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user