2016-11-09 03:29:50 +08:00
|
|
|
import { mapRoutes } from 'discourse/mapping-router';
|
|
|
|
|
2016-06-13 18:21:14 +08:00
|
|
|
moduleFor("controller:poll-ui-builder", "controller:poll-ui-builder", {
|
2016-11-09 03:29:50 +08:00
|
|
|
setup() {
|
|
|
|
this.registry.register('router:main', mapRoutes());
|
2016-11-22 03:49:00 +08:00
|
|
|
this.subject().set('toolbarEvent', {
|
|
|
|
getText: () => ""
|
|
|
|
});
|
2016-11-09 03:29:50 +08:00
|
|
|
},
|
2016-06-13 18:21:14 +08:00
|
|
|
needs: ['controller:modal']
|
|
|
|
});
|
|
|
|
|
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({
|
2016-06-20 12:40:24 +08:00
|
|
|
pollType: controller.get("multiplePollType"),
|
2016-06-13 18:21:14 +08:00
|
|
|
pollOptionsCount: 1
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("isMultiple"), true, "it should be true");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("pollOptionsCount", 0);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("isMultiple"), false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.setProperties({ pollType: "random", pollOptionsCount: 1 });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("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();
|
|
|
|
controller.siteSettings = Discourse.SiteSettings;
|
|
|
|
|
|
|
|
controller.set("pollType", "random");
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("isNumber"), false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2016-06-20 12:40:24 +08:00
|
|
|
controller.set("pollType", controller.get("numberPollType"));
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("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();
|
|
|
|
controller.siteSettings = Discourse.SiteSettings;
|
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
isNumber: true,
|
|
|
|
isMultiple: false
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("showMinMax"), true, "it should be true");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
isNumber: false,
|
|
|
|
isMultiple: true
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("showMinMax"), true, "it should be true");
|
2017-04-06 05:07:50 +08:00
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
isNumber: false,
|
|
|
|
isMultiple: false,
|
|
|
|
isRegular: true
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("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();
|
|
|
|
controller.siteSettings = Discourse.SiteSettings;
|
|
|
|
|
2016-07-20 03:14:55 +08:00
|
|
|
controller.set("pollOptions", "1\n2\n");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("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
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("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.siteSettings = Discourse.SiteSettings;
|
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
isMultiple: true,
|
|
|
|
pollOptionsCount: 1
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(controller.get("pollMinOptions"), [{ name: 1, value: 1 }], "it should return the right options");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("pollOptionsCount", 2);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(controller.get("pollMinOptions"), [
|
2016-06-13 18:21:14 +08:00
|
|
|
{ name: 1, value: 1 }, { name: 2, value: 2 }
|
|
|
|
], "it should return the right options");
|
|
|
|
|
|
|
|
controller.set("isNumber", true);
|
|
|
|
controller.siteSettings.poll_maximum_options = 2;
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(controller.get("pollMinOptions"), [
|
2016-06-13 18:21:14 +08:00
|
|
|
{ name: 1, value: 1 }, { name: 2, value: 2 }
|
|
|
|
], "it should return the right options");
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("pollMaxOptions", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
controller.siteSettings = Discourse.SiteSettings;
|
|
|
|
|
|
|
|
controller.setProperties({ isMultiple: true, pollOptionsCount: 1, pollMin: 1 });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(controller.get("pollMaxOptions"), [], "it should return the right options");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("pollOptionsCount", 2);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(controller.get("pollMaxOptions"), [
|
2016-06-13 18:21:14 +08:00
|
|
|
{ name: 2, value: 2 }
|
|
|
|
], "it should return the right options");
|
|
|
|
|
|
|
|
controller.siteSettings.poll_maximum_options = 3;
|
|
|
|
controller.setProperties({ isMultiple: false, isNumber: true, pollStep: 2, pollMin: 1 });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(controller.get("pollMaxOptions"), [
|
2016-06-13 18:21:14 +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");
|
|
|
|
});
|
|
|
|
|
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 = Discourse.SiteSettings;
|
|
|
|
controller.siteSettings.poll_maximum_options = 3;
|
|
|
|
|
|
|
|
controller.set("isNumber", false);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollStepOptions"), null, "is should return null");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.setProperties({ isNumber: true });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.deepEqual(controller.get("pollStepOptions"), [
|
2016-06-13 18:21:14 +08:00
|
|
|
{ name: 1, value: 1 },
|
|
|
|
{ name: 2, value: 2 },
|
|
|
|
{ name: 3, value: 3 }
|
|
|
|
], "it should return the right options");
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test("disableInsert", function(assert) {
|
2016-06-13 18:21:14 +08:00
|
|
|
const controller = this.subject();
|
|
|
|
controller.siteSettings = Discourse.SiteSettings;
|
|
|
|
|
2017-04-06 05:07:50 +08:00
|
|
|
controller.setProperties({ isRegular: true });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("disableInsert"), true, "it should be true");
|
2017-04-06 05:07:50 +08:00
|
|
|
|
|
|
|
controller.setProperties({ isRegular: true, pollOptionsCount: 2 });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("disableInsert"), false, "it should be false");
|
2017-04-06 05:07:50 +08:00
|
|
|
|
2016-06-13 18:21:14 +08:00
|
|
|
controller.setProperties({ isNumber: true });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("disableInsert"), false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.setProperties({ isNumber: false, pollOptionsCount: 3 });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("disableInsert"), false, "it should be false");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.setProperties({ isNumber: false, pollOptionsCount: 1 });
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("disableInsert"), true, "it should be true");
|
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 = Discourse.SiteSettings;
|
|
|
|
controller.siteSettings.poll_maximum_options = 20;
|
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
isNumber: true,
|
2016-06-20 12:40:24 +08:00
|
|
|
pollType: controller.get("numberPollType"),
|
2016-06-13 18:21:14 +08:00
|
|
|
pollMin: 1
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=1]\n[/poll]", "it should return the right output");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("pollStep", 2);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2]\n[/poll]", "it should return the right output");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("publicPoll", true);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2 public=true]\n[/poll]", "it should return the right output");
|
2017-12-01 00:04:41 +08:00
|
|
|
|
|
|
|
controller.set("pollStep", 0);
|
|
|
|
|
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=1 public=true]\n[/poll]", "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 = Discourse.SiteSettings;
|
|
|
|
controller.siteSettings.poll_maximum_options = 20;
|
|
|
|
|
|
|
|
controller.set("pollOptions", "1\n2");
|
2017-04-06 05:07:50 +08:00
|
|
|
controller.setProperties({
|
|
|
|
pollOptions: "1\n2",
|
|
|
|
pollType: controller.get("regularPollType")
|
|
|
|
});
|
2016-06-13 18:21:14 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=regular]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("publicPoll", "true");
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=regular public=true]\n* 1\n* 2\n[/poll]", "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 = Discourse.SiteSettings;
|
|
|
|
controller.siteSettings.poll_maximum_options = 20;
|
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
isMultiple: true,
|
2016-06-20 12:40:24 +08:00
|
|
|
pollType: controller.get("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
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
2016-06-13 18:21:14 +08:00
|
|
|
|
|
|
|
controller.set("publicPoll", "true");
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2 public=true]\n* 1\n* 2\n[/poll]", "it should return the right output");
|
2016-06-13 18:21:14 +08:00
|
|
|
});
|