2020-10-21 01:56:52 +08:00
|
|
|
import {
|
|
|
|
acceptance,
|
2020-11-27 22:30:16 +08:00
|
|
|
exists,
|
|
|
|
queryAll,
|
2020-10-21 01:56:52 +08:00
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2017-12-22 20:08:12 +08:00
|
|
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
2017-12-04 21:47:11 +08:00
|
|
|
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
|
2019-08-13 21:49:40 +08:00
|
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
2017-12-04 21:47:11 +08:00
|
|
|
|
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,
|
2020-09-05 02:01:14 +08:00
|
|
|
poll_minimum_trust_level_to_create: 1,
|
2020-10-21 01:56:52 +08:00
|
|
|
});
|
|
|
|
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
|
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) {
|
2020-10-21 01:56:52 +08:00
|
|
|
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
|
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(
|
|
|
|
exists(".select-kit-row[title='Build Poll']"),
|
|
|
|
"it shows the builder button"
|
|
|
|
);
|
|
|
|
});
|
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) {
|
2020-10-21 01:56:52 +08:00
|
|
|
updateCurrentUser({ moderator: false, admin: false, 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
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
assert.ok(
|
|
|
|
!exists(".select-kit-row[title='Build Poll']"),
|
|
|
|
"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
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
assert.ok(
|
|
|
|
exists(".select-kit-row[title='Build Poll']"),
|
|
|
|
"it shows the builder button"
|
|
|
|
);
|
|
|
|
});
|
2019-08-13 21:49:40 +08:00
|
|
|
|
2020-10-31 00:37:32 +08:00
|
|
|
test("poll preview", async function (assert) {
|
2020-10-21 01:56:52 +08:00
|
|
|
await displayPollBuilderButton();
|
2020-02-03 21:22:14 +08:00
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
|
|
|
await popupMenu.selectRowByValue("showPollBuilder");
|
2019-08-13 21:49:40 +08:00
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
await fillIn(".poll-textarea textarea", "First option\nSecond option");
|
2019-08-13 21:49:40 +08:00
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
assert.equal(
|
2020-10-29 04:36:01 +08:00
|
|
|
queryAll(".d-editor-preview li:first-child").text(),
|
2020-10-21 01:56:52 +08:00
|
|
|
"First option"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2020-10-29 04:36:01 +08:00
|
|
|
queryAll(".d-editor-preview li:last-child").text(),
|
2020-10-21 01:56:52 +08:00
|
|
|
"Second option"
|
|
|
|
);
|
|
|
|
});
|
2019-08-13 21:49:40 +08:00
|
|
|
});
|