2020-10-28 16:36:01 -04:00
|
|
|
import {
|
|
|
|
moduleForWidget,
|
|
|
|
widgetTest,
|
|
|
|
} from "discourse/tests/helpers/widget-test";
|
2020-03-06 17:49:28 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2020-10-28 16:36:01 -04:00
|
|
|
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
2020-03-06 17:49:28 -05:00
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
moduleForWidget("discourse-poll-standard-results");
|
2016-12-07 15:48:47 -05:00
|
|
|
|
|
|
|
const template = `{{mount-widget
|
|
|
|
widget="discourse-poll-standard-results"
|
|
|
|
args=(hash poll=poll isMultiple=isMultiple)}}`;
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
widgetTest("options in descending order", {
|
2016-12-07 15:48:47 -05:00
|
|
|
template,
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2018-06-15 12:42:20 -04:00
|
|
|
this.set(
|
|
|
|
"poll",
|
2020-03-06 17:49:28 -05:00
|
|
|
EmberObject.create({
|
2018-06-15 12:42:20 -04:00
|
|
|
options: [{ votes: 5 }, { votes: 4 }],
|
2020-09-04 14:01:14 -04:00
|
|
|
voters: 9,
|
2018-06-15 12:42:20 -04:00
|
|
|
})
|
|
|
|
);
|
2016-12-07 15:48:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2020-11-20 16:48:39 -05:00
|
|
|
assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
|
|
|
|
assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
|
2020-09-04 14:01:14 -04:00
|
|
|
},
|
2016-12-07 15:48:47 -05:00
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
widgetTest("options in ascending order", {
|
2016-12-07 15:48:47 -05:00
|
|
|
template,
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2018-06-15 12:42:20 -04:00
|
|
|
this.set(
|
|
|
|
"poll",
|
2020-03-06 17:49:28 -05:00
|
|
|
EmberObject.create({
|
2018-06-15 12:42:20 -04:00
|
|
|
options: [{ votes: 4 }, { votes: 5 }],
|
2020-09-04 14:01:14 -04:00
|
|
|
voters: 9,
|
2018-06-15 12:42:20 -04:00
|
|
|
})
|
|
|
|
);
|
2016-12-07 15:48:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2020-11-20 16:48:39 -05:00
|
|
|
assert.equal(queryAll(".option .percentage")[0].innerText, "56%");
|
|
|
|
assert.equal(queryAll(".option .percentage")[1].innerText, "44%");
|
2020-09-04 14:01:14 -04:00
|
|
|
},
|
2016-12-07 15:48:47 -05:00
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
widgetTest("multiple options in descending order", {
|
2016-12-07 15:48:47 -05:00
|
|
|
template,
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2018-06-15 12:42:20 -04:00
|
|
|
this.set("isMultiple", true);
|
|
|
|
this.set(
|
|
|
|
"poll",
|
2020-03-06 17:49:28 -05:00
|
|
|
EmberObject.create({
|
2018-06-15 12:42:20 -04:00
|
|
|
type: "multiple",
|
|
|
|
options: [
|
|
|
|
{ votes: 5, html: "a" },
|
|
|
|
{ votes: 2, html: "b" },
|
|
|
|
{ votes: 4, html: "c" },
|
|
|
|
{ votes: 1, html: "b" },
|
2020-09-04 14:01:14 -04:00
|
|
|
{ votes: 1, html: "a" },
|
2018-06-15 12:42:20 -04:00
|
|
|
],
|
2020-09-04 14:01:14 -04:00
|
|
|
voters: 12,
|
2018-06-15 12:42:20 -04:00
|
|
|
})
|
|
|
|
);
|
2016-12-07 15:48:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2020-11-20 16:48:39 -05:00
|
|
|
let percentages = queryAll(".option .percentage");
|
|
|
|
assert.equal(percentages[0].innerText, "41%");
|
|
|
|
assert.equal(percentages[1].innerText, "33%");
|
|
|
|
assert.equal(percentages[2].innerText, "16%");
|
|
|
|
assert.equal(percentages[3].innerText, "8%");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
queryAll(".option")[3].querySelectorAll("span")[1].innerText,
|
|
|
|
"a"
|
|
|
|
);
|
|
|
|
assert.equal(percentages[4].innerText, "8%");
|
|
|
|
assert.equal(
|
|
|
|
queryAll(".option")[4].querySelectorAll("span")[1].innerText,
|
|
|
|
"b"
|
|
|
|
);
|
2020-09-04 14:01:14 -04:00
|
|
|
},
|
2016-12-07 15:48:47 -05:00
|
|
|
});
|