mirror of
https://github.com/discourse/discourse.git
synced 2025-03-03 03:26:41 +08:00

Why this change? Previously just using the `addToolbarPopupMenuOptionsCallback` plugin API itself was insufficient because it required the return object to include an `action` key which only accepted a name of the action function as a string. This was highly problematic because the action function had to be defined on the `composer` service which means using the `modifyClass` API to add the action function. This made the API awkward to use leading to poor developer experiencec. What does this change do? This commit introduces a couple of improvemnts to the API. 1. First the API has been renamed to `addComposerToolbarPopupMenuOption` because the API no longer accepts a callback function which was quite redundant. Instead, it now accepts an Object. The `addToolbarPopupMenuOptionsCallback` API function is deprecated and will be dropped in Discourse 3.3. Note that passing the API a function is still supported but will be dropped when the `addToolbarPopupMenuOptionsCallback` is removed. 2. The `action` key in the Object passed to the function can now be a function and is passed the `toolbarEvent` object when called. 3. The `condition` on key in the Object passed to the function can now be a function and is passed the `composer` service when called.
72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
import I18n from "I18n";
|
|
import {
|
|
acceptance,
|
|
exists,
|
|
updateCurrentUser,
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
import { click } from "@ember/test-helpers";
|
|
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
|
|
import { test } from "qunit";
|
|
|
|
acceptance("Poll Builder - polls are enabled", function (needs) {
|
|
needs.user();
|
|
needs.settings({
|
|
poll_enabled: true,
|
|
poll_minimum_trust_level_to_create: 1,
|
|
});
|
|
|
|
test("regular user - sufficient trust level", async function (assert) {
|
|
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
|
|
|
|
await displayPollBuilderButton();
|
|
|
|
const pollBuilderButtonSelector = `.select-kit-row[data-name='${I18n.t(
|
|
"poll.ui_builder.title"
|
|
)}']`;
|
|
|
|
assert.dom(pollBuilderButtonSelector).exists("it shows the builder button");
|
|
|
|
await click(pollBuilderButtonSelector);
|
|
|
|
assert.true(
|
|
exists(".poll-type-value-regular.active"),
|
|
"regular type is active"
|
|
);
|
|
|
|
await click(".poll-type-value-multiple");
|
|
|
|
assert.true(
|
|
exists(".poll-type-value-multiple.active"),
|
|
"multiple type is active"
|
|
);
|
|
|
|
await click(".poll-type-value-regular");
|
|
|
|
assert.true(
|
|
exists(".poll-type-value-regular.active"),
|
|
"regular type is active"
|
|
);
|
|
});
|
|
|
|
test("regular user - insufficient trust level", async function (assert) {
|
|
updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
|
|
|
|
await displayPollBuilderButton();
|
|
|
|
assert.ok(
|
|
!exists(".select-kit-row[data-value='showPollBuilder]"),
|
|
"it hides the builder button"
|
|
);
|
|
});
|
|
|
|
test("staff - with insufficient trust level", async function (assert) {
|
|
updateCurrentUser({ moderator: true, trust_level: 0 });
|
|
|
|
await displayPollBuilderButton();
|
|
|
|
assert
|
|
.dom(`.select-kit-row[data-name='${I18n.t("poll.ui_builder.title")}']`)
|
|
.exists("it shows the builder button");
|
|
});
|
|
});
|