2023-10-11 02:38:59 +08:00
|
|
|
import { click } from "@ember/test-helpers";
|
|
|
|
import { test } from "qunit";
|
2024-01-23 09:35:14 +08:00
|
|
|
import { AUTO_GROUPS } from "discourse/lib/constants";
|
2020-10-21 01:56:52 +08:00
|
|
|
import {
|
|
|
|
acceptance,
|
2020-11-27 22:30:16 +08:00
|
|
|
exists,
|
2020-10-21 01:56:52 +08:00
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2023-10-18 18:07:09 +08:00
|
|
|
import I18n from "discourse-i18n";
|
2017-12-04 21:47:11 +08:00
|
|
|
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
|
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
acceptance("Poll Builder - polls are enabled", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
2017-12-04 21:47:11 +08:00
|
|
|
poll_enabled: true,
|
2024-01-23 09:35:14 +08:00
|
|
|
poll_create_allowed_groups: AUTO_GROUPS.trust_level_1,
|
2020-10-21 01:56:52 +08:00
|
|
|
});
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2020-10-31 00:37:32 +08:00
|
|
|
test("regular user - sufficient trust level", async function (assert) {
|
2024-01-23 09:35:14 +08:00
|
|
|
updateCurrentUser({
|
|
|
|
moderator: false,
|
|
|
|
admin: false,
|
|
|
|
trust_level: 1,
|
|
|
|
can_create_poll: true,
|
|
|
|
});
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2023-10-06 07:43:40 +08:00
|
|
|
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);
|
2022-10-11 18:20:18 +08:00
|
|
|
|
|
|
|
assert.true(
|
|
|
|
exists(".poll-type-value-regular.active"),
|
|
|
|
"regular type is active"
|
|
|
|
);
|
2023-10-06 07:43:40 +08:00
|
|
|
|
2022-10-11 18:20:18 +08:00
|
|
|
await click(".poll-type-value-multiple");
|
2023-10-06 07:43:40 +08:00
|
|
|
|
2022-10-11 18:20:18 +08:00
|
|
|
assert.true(
|
|
|
|
exists(".poll-type-value-multiple.active"),
|
|
|
|
"multiple type is active"
|
|
|
|
);
|
2023-10-06 07:43:40 +08:00
|
|
|
|
2022-10-11 18:20:18 +08:00
|
|
|
await click(".poll-type-value-regular");
|
2023-10-06 07:43:40 +08:00
|
|
|
|
2022-10-11 18:20:18 +08:00
|
|
|
assert.true(
|
|
|
|
exists(".poll-type-value-regular.active"),
|
|
|
|
"regular type is active"
|
|
|
|
);
|
2020-10-21 01:56:52 +08:00
|
|
|
});
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2020-10-31 00:37:32 +08:00
|
|
|
test("regular user - insufficient trust level", async function (assert) {
|
2024-01-23 09:35:14 +08:00
|
|
|
updateCurrentUser({
|
|
|
|
moderator: false,
|
|
|
|
admin: false,
|
|
|
|
trust_level: 0,
|
|
|
|
can_create_poll: false,
|
|
|
|
});
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
assert.ok(
|
2021-06-09 22:58:55 +08:00
|
|
|
!exists(".select-kit-row[data-value='showPollBuilder]"),
|
2020-10-21 01:56:52 +08:00
|
|
|
"it hides the builder button"
|
|
|
|
);
|
|
|
|
});
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2020-10-31 00:37:32 +08:00
|
|
|
test("staff - with insufficient trust level", async function (assert) {
|
2020-10-21 01:56:52 +08:00
|
|
|
updateCurrentUser({ moderator: true, trust_level: 0 });
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 21:47:11 +08:00
|
|
|
|
2023-10-06 07:43:40 +08:00
|
|
|
assert
|
|
|
|
.dom(`.select-kit-row[data-name='${I18n.t("poll.ui_builder.title")}']`)
|
|
|
|
.exists("it shows the builder button");
|
2020-10-21 01:56:52 +08:00
|
|
|
});
|
2019-08-13 21:49:40 +08:00
|
|
|
});
|