2020-10-20 13:56:52 -04:00
|
|
|
import {
|
|
|
|
acceptance,
|
2020-11-27 09:30:16 -05:00
|
|
|
exists,
|
2020-10-20 13:56:52 -04:00
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2022-10-11 06:20:18 -04:00
|
|
|
import { click } from "@ember/test-helpers";
|
2017-12-22 07:08:12 -05:00
|
|
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
2017-12-04 08:47:11 -05:00
|
|
|
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
|
2021-06-09 10:58:55 -04:00
|
|
|
import { test } from "qunit";
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
acceptance("Poll Builder - polls are enabled", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
2017-12-04 08:47:11 -05:00
|
|
|
poll_enabled: true,
|
2020-09-04 14:01:14 -04:00
|
|
|
poll_minimum_trust_level_to_create: 1,
|
2020-10-20 13:56:52 -04:00
|
|
|
});
|
|
|
|
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("regular user - sufficient trust level", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
|
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
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
assert.ok(
|
2021-06-09 10:58:55 -04:00
|
|
|
exists(".select-kit-row[data-value='showPollBuilder']"),
|
2020-10-20 13:56:52 -04:00
|
|
|
"it shows the builder button"
|
|
|
|
);
|
2022-10-11 06:20:18 -04:00
|
|
|
|
|
|
|
await click(".select-kit-row[data-value='showPollBuilder']");
|
|
|
|
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"
|
|
|
|
);
|
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("regular user - insufficient trust level", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
|
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
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
assert.ok(
|
2021-06-09 10:58:55 -04:00
|
|
|
!exists(".select-kit-row[data-value='showPollBuilder]"),
|
2020-10-20 13:56:52 -04:00
|
|
|
"it hides the builder button"
|
|
|
|
);
|
|
|
|
});
|
2017-12-04 08:47:11 -05:00
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("staff - with insufficient trust level", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
updateCurrentUser({ moderator: true, trust_level: 0 });
|
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
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
assert.ok(
|
2021-06-09 10:58:55 -04:00
|
|
|
exists(".select-kit-row[data-value='showPollBuilder']"),
|
2020-10-20 13:56:52 -04:00
|
|
|
"it shows the builder button"
|
|
|
|
);
|
|
|
|
});
|
2019-08-13 09:49:40 -04:00
|
|
|
});
|