2020-07-10 03:54:53 +08:00
|
|
|
import { controllerModule } from "helpers/qunit-helpers";
|
2016-11-09 03:29:50 +08:00
|
|
|
|
2020-07-10 03:54:53 +08:00
|
|
|
controllerModule("controller:poll-ui-builder", {
|
|
|
|
setupController(controller) {
|
|
|
|
controller.set("toolbarEvent", {
|
2016-11-22 03:49:00 +08:00
|
|
|
getText: () => ""
|
|
|
|
});
|
2016-11-09 03:29:50 +08:00
|
|
|
},
|
2018-06-16 00:42:20 +08:00
|
|
|
needs: ["controller:modal"]
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("isMultiple", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
|
|
|
|
controller.setProperties({
|
2020-02-03 21:22:14 +08:00
|
|
|
pollType: controller.multiplePollType,
|
2020-07-18 03:05:36 +08:00
|
|
|
pollOptions: "a"
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.isMultiple, true, "it should be true");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-07-18 03:05:36 +08:00
|
|
|
controller.set("pollOptions", "");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.isMultiple, false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-07-18 03:05:36 +08:00
|
|
|
controller.setProperties({ pollType: "random", pollOptions: "b" });
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.isMultiple, false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("isNumber", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.regularPollType);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.isNumber, false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.numberPollType);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.isNumber, true, "it should be true");
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("showMinMax", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.numberPollType);
|
|
|
|
assert.equal(controller.showMinMax, true, "it should be true");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.multiplePollType);
|
|
|
|
assert.equal(controller.showMinMax, true, "it should be true");
|
2017-04-06 05:07:50 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.regularPollType);
|
|
|
|
assert.equal(controller.showMinMax, false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("pollOptionsCount", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
|
2016-07-20 03:14:55 +08:00
|
|
|
controller.set("pollOptions", "1\n2\n");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.pollOptionsCount, 2, "it should equal 2");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2016-07-20 03:14:55 +08:00
|
|
|
controller.set("pollOptions", "");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.pollOptionsCount, 0, "it should equal 0");
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("pollMinOptions", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
|
|
|
|
controller.setProperties({
|
2020-02-03 21:22:14 +08:00
|
|
|
pollType: controller.multiplePollType,
|
2020-07-18 03:05:36 +08:00
|
|
|
pollOptions: "z"
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.deepEqual(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollMinOptions,
|
2018-06-16 00:42:20 +08:00
|
|
|
[{ name: 1, value: 1 }],
|
|
|
|
"it should return the right options"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-07-18 03:05:36 +08:00
|
|
|
controller.set("pollOptions", "z\nx");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.deepEqual(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollMinOptions,
|
2019-11-26 02:12:44 +08:00
|
|
|
[
|
|
|
|
{ name: 1, value: 1 },
|
|
|
|
{ name: 2, value: 2 }
|
|
|
|
],
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right options"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.numberPollType);
|
2016-06-13 18:21:14 +08:00
|
|
|
controller.siteSettings.poll_maximum_options = 2;
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.deepEqual(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollMinOptions,
|
2019-11-26 02:12:44 +08:00
|
|
|
[
|
|
|
|
{ name: 1, value: 1 },
|
|
|
|
{ name: 2, value: 2 }
|
|
|
|
],
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right options"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("pollMaxOptions", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
controller.setProperties({
|
2020-02-03 21:22:14 +08:00
|
|
|
pollType: controller.multiplePollType,
|
2020-07-18 03:05:36 +08:00
|
|
|
pollOptions: "y",
|
2018-06-16 00:42:20 +08:00
|
|
|
pollMin: 1
|
|
|
|
});
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.deepEqual(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollMaxOptions,
|
2018-06-16 00:42:20 +08:00
|
|
|
[],
|
|
|
|
"it should return the right options"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-07-18 03:05:36 +08:00
|
|
|
controller.set("pollOptions", "x\ny");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.deepEqual(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollMaxOptions,
|
2018-06-16 00:42:20 +08:00
|
|
|
[{ name: 2, value: 2 }],
|
|
|
|
"it should return the right options"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.siteSettings.poll_maximum_options = 3;
|
2018-06-16 00:42:20 +08:00
|
|
|
controller.setProperties({
|
2020-02-03 21:22:14 +08:00
|
|
|
pollType: controller.get("numberPollType"),
|
2018-06-16 00:42:20 +08:00
|
|
|
pollStep: 2,
|
|
|
|
pollMin: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollMaxOptions,
|
2018-06-16 00:42:20 +08:00
|
|
|
[
|
|
|
|
{ name: 2, value: 2 },
|
|
|
|
{ name: 3, value: 3 },
|
|
|
|
{ name: 4, value: 4 },
|
|
|
|
{ name: 5, value: 5 },
|
|
|
|
{ name: 6, value: 6 }
|
|
|
|
],
|
|
|
|
"it should return the right options"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("pollStepOptions", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
controller.siteSettings.poll_maximum_options = 3;
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.pollStepOptions, null, "is should return null");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.numberPollType);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.deepEqual(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollStepOptions,
|
2019-11-26 02:12:44 +08:00
|
|
|
[
|
|
|
|
{ name: 1, value: 1 },
|
|
|
|
{ name: 2, value: 2 },
|
|
|
|
{ name: 3, value: 3 }
|
|
|
|
],
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right options"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("disableInsert", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.disableInsert, true, "it should be true");
|
2017-04-06 05:07:50 +08:00
|
|
|
|
2020-07-18 03:05:36 +08:00
|
|
|
controller.set("pollOptions", "a\nb");
|
2017-04-06 05:07:50 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.disableInsert, false, "it should be false");
|
2017-04-06 05:07:50 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.set("pollType", controller.numberPollType);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.disableInsert, false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.setProperties({
|
|
|
|
pollType: controller.regularPollType,
|
2020-07-18 03:05:36 +08:00
|
|
|
pollOptions: "a\nb\nc"
|
2020-02-03 21:22:14 +08:00
|
|
|
});
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.disableInsert, false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.setProperties({
|
|
|
|
pollType: controller.regularPollType,
|
2020-07-18 03:05:36 +08:00
|
|
|
pollOptions: ""
|
2020-02-03 21:22:14 +08:00
|
|
|
});
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
assert.equal(controller.disableInsert, true, "it should be true");
|
2020-02-05 22:03:27 +08:00
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
pollType: controller.regularPollType,
|
2020-07-18 03:05:36 +08:00
|
|
|
pollOptions: "w"
|
2020-02-05 22:03:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(controller.disableInsert, false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("number pollOutput", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
controller.siteSettings.poll_maximum_options = 20;
|
|
|
|
|
|
|
|
controller.setProperties({
|
2020-02-03 21:22:14 +08:00
|
|
|
pollType: controller.numberPollType,
|
2016-06-13 18:21:14 +08:00
|
|
|
pollMin: 1
|
|
|
|
});
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=number results=always min=1 max=20 step=1]\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("pollStep", 2);
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=number results=always min=1 max=20 step=2]\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("publicPoll", true);
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=number results=always min=1 max=20 step=2 public=true]\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2017-12-01 00:04:41 +08:00
|
|
|
|
|
|
|
controller.set("pollStep", 0);
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=number results=always min=1 max=20 step=1 public=true]\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("regular pollOutput", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
controller.siteSettings.poll_maximum_options = 20;
|
|
|
|
|
|
|
|
controller.set("pollOptions", "1\n2");
|
2017-04-06 05:07:50 +08:00
|
|
|
controller.setProperties({
|
|
|
|
pollOptions: "1\n2",
|
2020-02-03 21:22:14 +08:00
|
|
|
pollType: controller.regularPollType
|
2017-04-06 05:07:50 +08:00
|
|
|
});
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=regular results=always chartType=bar]\n* 1\n* 2\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("publicPoll", "true");
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=regular results=always public=true chartType=bar]\n* 1\n* 2\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2020-01-28 20:30:04 +08:00
|
|
|
|
|
|
|
controller.set("pollGroups", "test");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
controller.get("pollOutput"),
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=regular results=always public=true chartType=bar groups=test]\n* 1\n* 2\n[/poll]\n",
|
2020-01-28 20:30:04 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("multiple pollOutput", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
controller.siteSettings.poll_maximum_options = 20;
|
|
|
|
|
|
|
|
controller.setProperties({
|
2020-02-03 21:22:14 +08:00
|
|
|
pollType: controller.multiplePollType,
|
2016-06-13 18:21:14 +08:00
|
|
|
pollMin: 1,
|
2016-07-14 15:10:31 +08:00
|
|
|
pollOptions: "\n\n1\n\n2"
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=multiple results=always min=1 max=2 chartType=bar]\n* 1\n* 2\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("publicPoll", "true");
|
|
|
|
|
2018-06-16 00:42:20 +08:00
|
|
|
assert.equal(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollOutput,
|
2020-07-07 22:23:21 +08:00
|
|
|
"[poll type=multiple results=always min=1 max=2 public=true chartType=bar]\n* 1\n* 2\n[/poll]\n",
|
2018-06-16 00:42:20 +08:00
|
|
|
"it should return the right output"
|
|
|
|
);
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|
2019-12-18 05:43:15 +08:00
|
|
|
|
|
|
|
test("staff_only option is not present for non-staff", function(assert) {
|
|
|
|
const controller = this.subject();
|
|
|
|
controller.currentUser = { staff: false };
|
|
|
|
|
|
|
|
assert.ok(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollResults.filterBy("value", "staff_only").length === 0,
|
2019-12-18 05:43:15 +08:00
|
|
|
"staff_only is not present"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-07-07 22:23:21 +08:00
|
|
|
test("poll result is always by default", function(assert) {
|
|
|
|
const controller = this.subject();
|
|
|
|
assert.equal(controller.pollResult, "always");
|
|
|
|
});
|
|
|
|
|
2019-12-18 05:43:15 +08:00
|
|
|
test("staff_only option is present for staff", function(assert) {
|
|
|
|
const controller = this.subject();
|
|
|
|
controller.currentUser = { staff: true };
|
|
|
|
|
|
|
|
assert.ok(
|
2020-02-03 21:22:14 +08:00
|
|
|
controller.pollResults.filterBy("value", "staff_only").length === 1,
|
2019-12-18 05:43:15 +08:00
|
|
|
"staff_only is present"
|
|
|
|
);
|
|
|
|
});
|