mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 17:23:44 +08:00
48ba65f406
Includes: * Import `computed` helpers * Import `@ember/application` * Import `isBlank` from `@ember/utils` * Import `A` from `@ember/array` * Import `EmberArray` from `@ember/array` * Import `ArrayProxy` from `@ember/array/proxy` * Import `warn` from `@ember/debug` * Import `EmberObject` from `@ember/object` * Import `Application` from `@ember/application` * Import `EmberRouter` from `@ember/routing/router` * Import `isPresent` from `@ember/utils` * Import `computed` from `@ember/object` * Import `guidFor` from `@ember/object` * Import `isArray` from `@ember/array` * Import `TextField` from `@ember/component` * Import `TextArea` from `@ember/component` * Import `Promise` from `rsvp` * Import `Evented` from `@ember/object/evented` * Replace deprecated `ember-addons/ember-computed-decorators` imports
79 lines
2.0 KiB
JavaScript
79 lines
2.0 KiB
JavaScript
import EmberObject from "@ember/object";
|
|
import { moduleForWidget, widgetTest } from "helpers/widget-test";
|
|
|
|
moduleForWidget("discourse-poll-standard-results");
|
|
|
|
const template = `{{mount-widget
|
|
widget="discourse-poll-standard-results"
|
|
args=(hash poll=poll isMultiple=isMultiple)}}`;
|
|
|
|
widgetTest("options in descending order", {
|
|
template,
|
|
|
|
beforeEach() {
|
|
this.set(
|
|
"poll",
|
|
EmberObject.create({
|
|
options: [{ votes: 5 }, { votes: 4 }],
|
|
voters: 9
|
|
})
|
|
);
|
|
},
|
|
|
|
test(assert) {
|
|
assert.equal(find(".option .percentage:eq(0)").text(), "56%");
|
|
assert.equal(find(".option .percentage:eq(1)").text(), "44%");
|
|
}
|
|
});
|
|
|
|
widgetTest("options in ascending order", {
|
|
template,
|
|
|
|
beforeEach() {
|
|
this.set(
|
|
"poll",
|
|
EmberObject.create({
|
|
options: [{ votes: 4 }, { votes: 5 }],
|
|
voters: 9
|
|
})
|
|
);
|
|
},
|
|
|
|
test(assert) {
|
|
assert.equal(find(".option .percentage:eq(0)").text(), "56%");
|
|
assert.equal(find(".option .percentage:eq(1)").text(), "44%");
|
|
}
|
|
});
|
|
|
|
widgetTest("multiple options in descending order", {
|
|
template,
|
|
|
|
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
|
|
})
|
|
);
|
|
},
|
|
|
|
test(assert) {
|
|
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");
|
|
}
|
|
});
|