2021-06-09 10:58:55 -04:00
|
|
|
import componentTest, {
|
|
|
|
setupRenderingTest,
|
|
|
|
} from "discourse/tests/helpers/component-test";
|
2020-03-06 17:49:28 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2021-06-09 10:58:55 -04:00
|
|
|
import {
|
|
|
|
discourseModule,
|
|
|
|
queryAll,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2021-06-21 15:52:15 -04:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2020-03-06 17:49:28 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
discourseModule(
|
|
|
|
"Integration | Component | Widget | discourse-poll-standard-results",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-21 15:52:15 -04:00
|
|
|
const template = hbs`{{mount-widget
|
2016-12-07 15:48:47 -05:00
|
|
|
widget="discourse-poll-standard-results"
|
|
|
|
args=(hash poll=poll isMultiple=isMultiple)}}`;
|
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
componentTest("options in descending order", {
|
|
|
|
template,
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
beforeEach() {
|
|
|
|
this.set(
|
|
|
|
"poll",
|
|
|
|
EmberObject.create({
|
|
|
|
options: [{ votes: 5 }, { votes: 4 }],
|
|
|
|
voters: 9,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
test(assert) {
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(queryAll(".option .percentage")[0].innerText, "56%");
|
|
|
|
assert.strictEqual(queryAll(".option .percentage")[1].innerText, "44%");
|
2021-06-09 10:58:55 -04:00
|
|
|
},
|
|
|
|
});
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
componentTest("options in ascending order", {
|
|
|
|
template,
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
beforeEach() {
|
|
|
|
this.set(
|
|
|
|
"poll",
|
|
|
|
EmberObject.create({
|
|
|
|
options: [{ votes: 4 }, { votes: 5 }],
|
|
|
|
voters: 9,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
test(assert) {
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(queryAll(".option .percentage")[0].innerText, "56%");
|
|
|
|
assert.strictEqual(queryAll(".option .percentage")[1].innerText, "44%");
|
2021-06-09 10:58:55 -04:00
|
|
|
},
|
|
|
|
});
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
componentTest("multiple options in descending order", {
|
|
|
|
template,
|
2016-12-07 15:48:47 -05:00
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
beforeEach() {
|
|
|
|
this.set("isMultiple", true);
|
|
|
|
this.set(
|
|
|
|
"poll",
|
|
|
|
EmberObject.create({
|
|
|
|
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
|
|
|
|
2021-06-09 10:58:55 -04:00
|
|
|
test(assert) {
|
|
|
|
let percentages = queryAll(".option .percentage");
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(percentages[0].innerText, "41%");
|
|
|
|
assert.strictEqual(percentages[1].innerText, "33%");
|
|
|
|
assert.strictEqual(percentages[2].innerText, "16%");
|
|
|
|
assert.strictEqual(percentages[3].innerText, "8%");
|
2020-11-20 16:48:39 -05:00
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-06-09 10:58:55 -04:00
|
|
|
queryAll(".option")[3].querySelectorAll("span")[1].innerText,
|
|
|
|
"a"
|
|
|
|
);
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(percentages[4].innerText, "8%");
|
|
|
|
assert.strictEqual(
|
2021-06-09 10:58:55 -04:00
|
|
|
queryAll(".option")[4].querySelectorAll("span")[1].innerText,
|
|
|
|
"b"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|