2023-10-10 14:38:59 -04:00
|
|
|
import { test } from "qunit";
|
2024-01-22 20:35:14 -05:00
|
|
|
import { AUTO_GROUPS } from "discourse/lib/constants";
|
2020-10-20 13:56:52 -04:00
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2017-12-04 08:47:11 -05:00
|
|
|
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
|
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
acceptance("Poll Builder - polls are disabled", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
2017-12-04 08:47:11 -05:00
|
|
|
poll_enabled: false,
|
2024-01-22 20:35:14 -05:00
|
|
|
poll_create_allowed_groups: AUTO_GROUPS.trust_level_2,
|
2020-10-20 13:56:52 -04:00
|
|
|
});
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2024-01-22 20:35:14 -05:00
|
|
|
test("regular user - sufficient permissions", async function (assert) {
|
|
|
|
updateCurrentUser({
|
|
|
|
moderator: false,
|
|
|
|
admin: false,
|
|
|
|
trust_level: 3,
|
|
|
|
can_create_poll: true,
|
|
|
|
});
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2024-10-22 05:34:23 -04:00
|
|
|
assert
|
|
|
|
.dom(".select-kit-row[data-value='showPollBuilder']")
|
|
|
|
.doesNotExist("it hides the builder button");
|
2020-10-20 13:56:52 -04:00
|
|
|
});
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2024-01-22 20:35:14 -05:00
|
|
|
test("regular user - insufficient permissions", async function (assert) {
|
|
|
|
updateCurrentUser({
|
|
|
|
moderator: false,
|
|
|
|
admin: false,
|
|
|
|
trust_level: 1,
|
|
|
|
can_create_poll: false,
|
|
|
|
});
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2024-10-22 05:34:23 -04:00
|
|
|
assert
|
|
|
|
.dom(".select-kit-row[data-value='showPollBuilder']")
|
|
|
|
.doesNotExist("it hides the builder button");
|
2020-10-20 13:56:52 -04:00
|
|
|
});
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("staff", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
updateCurrentUser({ moderator: true });
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2024-10-22 05:34:23 -04:00
|
|
|
assert
|
|
|
|
.dom(".select-kit-row[data-value='showPollBuilder']")
|
|
|
|
.doesNotExist("it hides the builder button");
|
2020-10-20 13:56:52 -04:00
|
|
|
});
|
2017-12-04 08:47:11 -05:00
|
|
|
});
|