2020-03-06 17:49:28 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2018-06-15 12:42:20 -04:00
|
|
|
import { moduleForWidget, widgetTest } from "helpers/widget-test";
|
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 }],
|
|
|
|
voters: 9
|
|
|
|
})
|
|
|
|
);
|
2016-12-07 15:48:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.equal(find(".option .percentage:eq(0)").text(), "56%");
|
|
|
|
assert.equal(find(".option .percentage:eq(1)").text(), "44%");
|
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 }],
|
|
|
|
voters: 9
|
|
|
|
})
|
|
|
|
);
|
2016-12-07 15:48:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.equal(find(".option .percentage:eq(0)").text(), "56%");
|
|
|
|
assert.equal(find(".option .percentage:eq(1)").text(), "44%");
|
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" },
|
|
|
|
{ votes: 1, html: "a" }
|
|
|
|
],
|
|
|
|
voters: 12
|
|
|
|
})
|
|
|
|
);
|
2016-12-07 15:48:47 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.equal(find(".option .percentage:eq(0)").text(), "41%");
|
|
|
|
assert.equal(find(".option .percentage:eq(1)").text(), "33%");
|
|
|
|
assert.equal(find(".option .percentage:eq(2)").text(), "16%");
|
|
|
|
assert.equal(find(".option .percentage:eq(3)").text(), "8%");
|
|
|
|
assert.equal(find(".option span:nth-child(2):eq(3)").text(), "a");
|
|
|
|
assert.equal(find(".option .percentage:eq(4)").text(), "8%");
|
|
|
|
assert.equal(find(".option span:nth-child(2):eq(4)").text(), "b");
|
2016-12-07 15:48:47 -05:00
|
|
|
}
|
|
|
|
});
|