This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/integration/widgets/post-menu-test.js
Alan Guo Xiang Tan 057ef55684
DEV: Allow callback to be registered to remove post menu button. (#15061)
This will allow buttons in the post menu to be remove based on a post's
attributes or site settings.
2021-11-24 13:26:52 +08:00

100 lines
2.6 KiB
JavaScript

import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import {
count,
discourseModule,
exists,
} from "discourse/tests/helpers/qunit-helpers";
import hbs from "htmlbars-inline-precompile";
import { resetPostMenuExtraButtons } from "discourse/widgets/post-menu";
import { withPluginApi } from "discourse/lib/plugin-api";
discourseModule(
"Integration | Component | Widget | post-menu",
function (hooks) {
hooks.afterEach(() => {
resetPostMenuExtraButtons();
});
setupRenderingTest(hooks);
componentTest("add extra button", {
template: hbs`{{mount-widget widget="post-menu" args=args}}`,
beforeEach() {
this.set("args", {});
withPluginApi("0.14.0", (api) => {
api.addPostMenuButton("coffee", () => {
return {
action: "drinkCoffee",
icon: "coffee",
className: "hot-coffee",
title: "coffee.title",
position: "first",
};
});
});
},
async test(assert) {
assert.strictEqual(
count(".actions .extra-buttons .hot-coffee"),
1,
"It renders extra button"
);
},
});
componentTest("removes button based on callback", {
template: hbs`{{mount-widget widget="post-menu" args=args}}`,
beforeEach() {
this.set("args", { canCreatePost: true, canRemoveReply: true });
withPluginApi("0.14.0", (api) => {
api.removePostMenuButton("reply", (attrs) => {
return attrs.canRemoveReply;
});
});
},
async test(assert) {
assert.ok(!exists(".actions .reply"), "it removes reply button");
},
});
componentTest("does not remove butto", {
template: hbs`{{mount-widget widget="post-menu" args=args}}`,
beforeEach() {
this.set("args", { canCreatePost: true, canRemoveReply: false });
withPluginApi("0.14.0", (api) => {
api.removePostMenuButton("reply", (attrs) => {
return attrs.canRemoveReply;
});
});
},
async test(assert) {
assert.ok(exists(".actions .reply"), "it does not remove reply button");
},
});
componentTest("removes button", {
template: hbs`{{mount-widget widget="post-menu" args=args}}`,
beforeEach() {
this.set("args", { canCreatePost: true });
withPluginApi("0.14.0", (api) => {
api.removePostMenuButton("reply");
});
},
async test(assert) {
assert.ok(!exists(".actions .reply"), "it removes reply button");
},
});
}
);