2019-08-13 08:49:40 -05:00
|
|
|
import selectKit from "helpers/select-kit-helper";
|
2019-06-14 07:54:20 -05:00
|
|
|
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
2017-12-04 07:47:11 -06:00
|
|
|
import { displayPollBuilderButton } from "discourse/plugins/poll/helpers/display-poll-builder-button";
|
2017-12-22 06:08:12 -06:00
|
|
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
2017-12-04 07:47:11 -06:00
|
|
|
|
|
|
|
acceptance("Poll Builder - polls are enabled", {
|
|
|
|
loggedIn: true,
|
|
|
|
settings: {
|
|
|
|
poll_enabled: true,
|
2020-09-04 13:01:14 -05:00
|
|
|
poll_minimum_trust_level_to_create: 1,
|
2017-12-22 06:08:12 -06:00
|
|
|
},
|
2020-02-03 07:22:14 -06:00
|
|
|
beforeEach() {
|
2017-12-22 06:08:12 -06:00
|
|
|
clearPopupMenuOptionsCallback();
|
2020-09-04 13:01:14 -05:00
|
|
|
},
|
2017-12-04 07:47:11 -06:00
|
|
|
});
|
|
|
|
|
2020-09-04 13:01:14 -05:00
|
|
|
test("regular user - sufficient trust level", async (assert) => {
|
2019-07-24 15:01:08 -05:00
|
|
|
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
|
2017-12-04 07:47:11 -06:00
|
|
|
|
2020-02-03 07:22:14 -06:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 07:47:11 -06:00
|
|
|
|
2020-02-03 07:22:14 -06:00
|
|
|
assert.ok(
|
|
|
|
exists(".select-kit-row[title='Build Poll']"),
|
|
|
|
"it shows the builder button"
|
|
|
|
);
|
2017-12-04 07:47:11 -06:00
|
|
|
});
|
|
|
|
|
2020-09-04 13:01:14 -05:00
|
|
|
test("regular user - insufficient trust level", async (assert) => {
|
2019-07-24 15:01:08 -05:00
|
|
|
updateCurrentUser({ moderator: false, admin: false, trust_level: 0 });
|
2017-12-04 07:47:11 -06:00
|
|
|
|
2020-02-03 07:22:14 -06:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 07:47:11 -06:00
|
|
|
|
2020-02-03 07:22:14 -06:00
|
|
|
assert.ok(
|
|
|
|
!exists(".select-kit-row[title='Build Poll']"),
|
|
|
|
"it hides the builder button"
|
|
|
|
);
|
2017-12-04 07:47:11 -06:00
|
|
|
});
|
|
|
|
|
2020-09-04 13:01:14 -05:00
|
|
|
test("staff - with insufficient trust level", async (assert) => {
|
2019-07-24 15:01:08 -05:00
|
|
|
updateCurrentUser({ moderator: true, trust_level: 0 });
|
2017-12-04 07:47:11 -06:00
|
|
|
|
2020-02-03 07:22:14 -06:00
|
|
|
await displayPollBuilderButton();
|
2017-12-04 07:47:11 -06:00
|
|
|
|
2020-02-03 07:22:14 -06:00
|
|
|
assert.ok(
|
|
|
|
exists(".select-kit-row[title='Build Poll']"),
|
|
|
|
"it shows the builder button"
|
|
|
|
);
|
2017-12-04 07:47:11 -06:00
|
|
|
});
|
2019-08-13 08:49:40 -05:00
|
|
|
|
2020-09-04 13:01:14 -05:00
|
|
|
test("poll preview", async (assert) => {
|
2020-02-03 07:22:14 -06:00
|
|
|
await displayPollBuilderButton();
|
|
|
|
|
2019-08-13 08:49:40 -05:00
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
|
|
|
await popupMenu.selectRowByValue("showPollBuilder");
|
|
|
|
|
|
|
|
await fillIn(".poll-textarea textarea", "First option\nSecond option");
|
|
|
|
|
|
|
|
assert.equal(find(".d-editor-preview li:first-child").text(), "First option");
|
|
|
|
assert.equal(find(".d-editor-preview li:last-child").text(), "Second option");
|
|
|
|
});
|