discourse/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.1 KiB
Plaintext
Raw Normal View History

import EmberObject from "@ember/object";
import {
moduleForWidget,
widgetTest,
} from "discourse/tests/helpers/widget-test";
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
2018-06-16 00:42:20 +08:00
moduleForWidget("discourse-poll-standard-results");
const template = `{{mount-widget
widget="discourse-poll-standard-results"
args=(hash poll=poll isMultiple=isMultiple)}}`;
2018-06-16 00:42:20 +08:00
widgetTest("options in descending order", {
template,
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-16 00:42:20 +08:00
this.set(
"poll",
EmberObject.create({
2018-06-16 00:42:20 +08:00
options: [{ votes: 5 }, { votes: 4 }],
voters: 9,
2018-06-16 00:42:20 +08:00
})
);
},
test(assert) {
assert.equal(queryAll(".option .percentage:eq(0)").text(), "56%");
assert.equal(queryAll(".option .percentage:eq(1)").text(), "44%");
},
});
2018-06-16 00:42:20 +08:00
widgetTest("options in ascending order", {
template,
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-16 00:42:20 +08:00
this.set(
"poll",
EmberObject.create({
2018-06-16 00:42:20 +08:00
options: [{ votes: 4 }, { votes: 5 }],
voters: 9,
2018-06-16 00:42:20 +08:00
})
);
},
test(assert) {
assert.equal(queryAll(".option .percentage:eq(0)").text(), "56%");
assert.equal(queryAll(".option .percentage:eq(1)").text(), "44%");
},
});
2018-06-16 00:42:20 +08:00
widgetTest("multiple options in descending order", {
template,
2017-06-15 01:57:58 +08:00
beforeEach() {
2018-06-16 00:42:20 +08:00
this.set("isMultiple", true);
this.set(
"poll",
EmberObject.create({
2018-06-16 00:42:20 +08:00
type: "multiple",
options: [
{ votes: 5, html: "a" },
{ votes: 2, html: "b" },
{ votes: 4, html: "c" },
{ votes: 1, html: "b" },
{ votes: 1, html: "a" },
2018-06-16 00:42:20 +08:00
],
voters: 12,
2018-06-16 00:42:20 +08:00
})
);
},
test(assert) {
assert.equal(queryAll(".option .percentage:eq(0)").text(), "41%");
assert.equal(queryAll(".option .percentage:eq(1)").text(), "33%");
assert.equal(queryAll(".option .percentage:eq(2)").text(), "16%");
assert.equal(queryAll(".option .percentage:eq(3)").text(), "8%");
assert.equal(queryAll(".option span:nth-child(2):eq(3)").text(), "a");
assert.equal(queryAll(".option .percentage:eq(4)").text(), "8%");
assert.equal(queryAll(".option span:nth-child(2):eq(4)").text(), "b");
},
});