Files
discourse/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js
T

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

69 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-10-10 19:38:59 +01:00
import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
2022-07-11 12:29:44 +02:00
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count } from "discourse/tests/helpers/qunit-helpers";
2020-10-28 16:36:01 -04:00
2022-07-11 12:29:44 +02:00
module(
"Integration | Component | Widget | discourse-poll-option",
function (hooks) {
setupRenderingTest(hooks);
2022-07-11 12:29:44 +02:00
const template = hbs`
<MountWidget
@widget="discourse-poll-option"
@args={{hash
option=this.option
isMultiple=this.isMultiple
vote=this.vote
}}
/>
`;
2022-07-11 12:29:44 +02:00
test("single, not selected", async function (assert) {
this.set("option", { id: "opt-id" });
this.set("vote", []);
2022-07-11 12:29:44 +02:00
await render(template);
assert.strictEqual(count("li .d-icon-far-circle:nth-of-type(1)"), 1);
});
2022-07-11 12:29:44 +02:00
test("single, selected", async function (assert) {
this.set("option", { id: "opt-id" });
this.set("vote", ["opt-id"]);
2022-07-11 12:29:44 +02:00
await render(template);
2022-07-11 12:29:44 +02:00
assert.strictEqual(count("li .d-icon-circle:nth-of-type(1)"), 1);
});
2022-07-11 12:29:44 +02:00
test("multi, not selected", async function (assert) {
this.setProperties({
option: { id: "opt-id" },
isMultiple: true,
vote: [],
});
2022-07-11 12:29:44 +02:00
await render(template);
2022-07-11 12:29:44 +02:00
assert.strictEqual(count("li .d-icon-far-square:nth-of-type(1)"), 1);
});
2022-07-11 12:29:44 +02:00
test("multi, selected", async function (assert) {
this.setProperties({
option: { id: "opt-id" },
isMultiple: true,
vote: ["opt-id"],
});
2022-07-11 12:29:44 +02:00
await render(template);
2022-07-11 12:29:44 +02:00
assert.strictEqual(
count("li .d-icon-far-check-square:nth-of-type(1)"),
1
);
});
}
);