mirror of
https://github.com/discourse/discourse.git
synced 2024-12-10 06:03:46 +08:00
189bebb2e4
* Use QUnit `module` instead of `discourseModule` * Use QUnit `test` instead of `componentTest` * Use angle-bracket syntax * Remove jQuery usage * Improve assertions (and actually fix some of them)
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import { render } from "@ember/test-helpers";
|
|
import { count } from "discourse/tests/helpers/qunit-helpers";
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
module(
|
|
"Integration | Component | Widget | discourse-poll-option",
|
|
function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
const template = hbs`
|
|
<MountWidget
|
|
@widget="discourse-poll-option"
|
|
@args={{hash
|
|
option=this.option
|
|
isMultiple=this.isMultiple
|
|
vote=this.vote
|
|
}}
|
|
/>
|
|
`;
|
|
|
|
test("single, not selected", async function (assert) {
|
|
this.set("option", { id: "opt-id" });
|
|
this.set("vote", []);
|
|
|
|
await render(template);
|
|
|
|
assert.strictEqual(count("li .d-icon-far-circle:nth-of-type(1)"), 1);
|
|
});
|
|
|
|
test("single, selected", async function (assert) {
|
|
this.set("option", { id: "opt-id" });
|
|
this.set("vote", ["opt-id"]);
|
|
|
|
await render(template);
|
|
|
|
assert.strictEqual(count("li .d-icon-circle:nth-of-type(1)"), 1);
|
|
});
|
|
|
|
test("multi, not selected", async function (assert) {
|
|
this.setProperties({
|
|
option: { id: "opt-id" },
|
|
isMultiple: true,
|
|
vote: [],
|
|
});
|
|
|
|
await render(template);
|
|
|
|
assert.strictEqual(count("li .d-icon-far-square:nth-of-type(1)"), 1);
|
|
});
|
|
|
|
test("multi, selected", async function (assert) {
|
|
this.setProperties({
|
|
option: { id: "opt-id" },
|
|
isMultiple: true,
|
|
vote: ["opt-id"],
|
|
});
|
|
|
|
await render(template);
|
|
|
|
assert.strictEqual(
|
|
count("li .d-icon-far-check-square:nth-of-type(1)"),
|
|
1
|
|
);
|
|
});
|
|
}
|
|
);
|