DEV: Replace count with qunit-dom (#29674)

This commit is contained in:
Jarek Radosz
2024-11-10 02:06:03 +01:00
committed by GitHub
parent f9e58938ce
commit d67a6002eb
71 changed files with 875 additions and 1380 deletions

View File

@ -1,10 +1,6 @@
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
count,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
acceptance("Poll breakdown", function (needs) {
needs.user();
@ -77,11 +73,12 @@ acceptance("Poll breakdown", function (needs) {
assert.dom(".poll-breakdown-total-votes").exists("displays the vote count");
assert.strictEqual(
count(".poll-breakdown-chart-container"),
2,
"renders a chart for each of the groups in group_results response"
);
assert
.dom(".poll-breakdown-chart-container")
.exists(
{ count: 2 },
"renders a chart for each of the groups in group_results response"
);
assert.ok(
query(".poll-breakdown-chart-container > canvas").$chartjs,

View File

@ -1,6 +1,6 @@
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Poll quote", function (needs) {
needs.user();
@ -427,7 +427,7 @@ acceptance("Poll quote", function (needs) {
test("renders and extends", async function (assert) {
await visit("/t/-/topic_with_two_quoted_polls");
await click(".quote-controls");
assert.strictEqual(count(".poll"), 2, "polls are rendered");
assert.strictEqual(count(".poll-buttons"), 2, "polls are extended");
assert.dom(".poll").exists({ count: 2 }, "polls are rendered");
assert.dom(".poll-buttons").exists({ count: 2 }, "polls are extended");
});
});

View File

@ -2,7 +2,6 @@ import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
count,
publishToMessageBus,
query,
} from "discourse/tests/helpers/qunit-helpers";
@ -1043,16 +1042,12 @@ acceptance("Poll results", function (needs) {
test("can load more voters", async function (assert) {
await visit("/t/load-more-poll-voters/134");
assert.strictEqual(
count(".poll-container .results li:nth-child(1) .poll-voters li"),
1,
"Initially, one voter shown on first option"
);
assert.strictEqual(
count(".poll-container .results li:nth-child(2) .poll-voters li"),
0,
"Initially, no voter shown on second option"
);
assert
.dom(".poll-container .results li:nth-child(1) .poll-voters li")
.exists({ count: 1 }, "initially, one voter shown on first option");
assert
.dom(".poll-container .results li:nth-child(2) .poll-voters li")
.doesNotExist("initially, no voter shown on second option");
await publishToMessageBus("/polls/134", {
post_id: "156",
@ -1093,30 +1088,30 @@ acceptance("Poll results", function (needs) {
],
});
assert.strictEqual(
count(".poll-container .results li:nth-child(1) .poll-voters li"),
1,
"after incoming message, one voter shown on first option"
);
assert
.dom(".poll-container .results li:nth-child(1) .poll-voters li")
.exists(
{ count: 1 },
"after incoming message, one voter shown on first option"
);
assert.strictEqual(
count(".poll-container .results li:nth-child(2) .poll-voters li"),
0,
"after incoming message, no voter shown on second option"
);
assert
.dom(".poll-container .results li:nth-child(2) .poll-voters li")
.doesNotExist("after incoming message, no voter shown on second option");
await click(".poll-voters-toggle-expand");
assert.strictEqual(
count(".poll-container .results li:nth-child(1) .poll-voters li"),
2,
"after clicking fetch voters button, two voters shown on first option"
);
assert.strictEqual(
count(".poll-container .results li:nth-child(2) .poll-voters li"),
0,
"after clicking fetch voters button, no voters shown on second option"
);
assert
.dom(".poll-container .results li:nth-child(1) .poll-voters li")
.exists(
{ count: 2 },
"after clicking fetch voters button, two voters shown on first option"
);
assert
.dom(".poll-container .results li:nth-child(2) .poll-voters li")
.doesNotExist(
"after clicking fetch voters button, no voters shown on second option"
);
});
test("can load more voters - ranked choice", async function (assert) {
@ -1142,23 +1137,22 @@ acceptance("Poll results", function (needs) {
"Votes tab is active"
);
assert.strictEqual(
count(
assert
.dom(
".poll-container .discourse-poll-ranked_choice-results .poll-voters li"
),
1,
"Initially, one voter shown on first option"
);
)
.exists({ count: 1 }, "Initially, one voter shown on first option");
await click(".poll-voters-toggle-expand");
assert.strictEqual(
count(
assert
.dom(
".poll-container .discourse-poll-ranked_choice-results .results li:nth-child(1) .poll-voters li"
),
2,
"after clicking fetch voters button, two voters shown on first option"
);
)
.exists(
{ count: 2 },
"after clicking fetch voters button, two voters shown on first option"
);
await publishToMessageBus("/polls/135", {
post_id: "158",
@ -1224,13 +1218,14 @@ acceptance("Poll results", function (needs) {
],
});
assert.strictEqual(
count(
assert
.dom(
".poll-container .discourse-poll-ranked_choice-results .results li:nth-child(1) .poll-voters li"
),
2,
"after incoming message containing 3 voters, only 2 voters shown on first option as bus updates are not supported once voters are expanded"
);
)
.exists(
{ count: 2 },
"after incoming message containing 3 voters, only 2 voters shown on first option as bus updates are not supported once voters are expanded"
);
});
test("can unvote", async function (assert) {
@ -1238,13 +1233,13 @@ acceptance("Poll results", function (needs) {
await click(".toggle-results");
assert.strictEqual(count(".poll-container .d-icon-circle"), 1);
assert.strictEqual(count(".poll-container .d-icon-far-circle"), 1);
assert.dom(".poll-container .d-icon-circle").exists({ count: 1 });
assert.dom(".poll-container .d-icon-far-circle").exists({ count: 1 });
await click(".remove-vote");
assert.strictEqual(count(".poll-container .d-icon-circle"), 0);
assert.strictEqual(count(".poll-container .d-icon-far-circle"), 2);
assert.dom(".poll-container .d-icon-circle").doesNotExist();
assert.dom(".poll-container .d-icon-far-circle").exists({ count: 2 });
});
});

View File

@ -2,7 +2,7 @@ import { click, render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count, query } from "discourse/tests/helpers/qunit-helpers";
import { query } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
module("Poll | Component | poll-buttons-dropdown", function (hooks) {
@ -38,7 +38,6 @@ module("Poll | Component | poll-buttons-dropdown", function (hooks) {
await click(".widget-dropdown-header");
assert.dom("li.dropdown-menu__item").exists({ count: 2 });
assert.strictEqual(
query("li.dropdown-menu__item span").textContent.trim(),
I18n.t("poll.export-results.label"),
@ -73,8 +72,7 @@ module("Poll | Component | poll-buttons-dropdown", function (hooks) {
await click(".widget-dropdown-header");
assert.strictEqual(count("li.dropdown-menu__item"), 2);
assert.dom("li.dropdown-menu__item").exists({ count: 2 });
assert
.dom(query("li.dropdown-menu__item span"))
.hasText(
@ -106,10 +104,8 @@ module("Poll | Component | poll-buttons-dropdown", function (hooks) {
@dropDownClick={{this.dropDownClick}}
/>`);
assert.strictEqual(count(".widget-dropdown-header"), 0);
assert.strictEqual(count("button.widget-button"), 1);
assert.dom(".widget-dropdown-header").doesNotExist();
assert.dom("button.widget-button").exists({ count: 1 });
assert.strictEqual(
query("button.widget-button span.d-button-label").textContent.trim(),
I18n.t("poll.breakdown.breakdown"),
@ -140,8 +136,7 @@ module("Poll | Component | poll-buttons-dropdown", function (hooks) {
@dropDownClick={{this.dropDownClick}}
/>`);
assert.strictEqual(count(".widget-dropdown-header"), 0);
assert.strictEqual(count("button.widget-button"), 0);
assert.dom(".widget-dropdown-header").doesNotExist();
assert.dom("button.widget-button").doesNotExist();
});
});

View File

@ -2,7 +2,6 @@ import { click, render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
const OPTIONS = [
@ -47,7 +46,7 @@ module("Poll | Component | poll-options", function (hooks) {
@sendRadioClick={{this.toggleOption}}
/>`);
assert.strictEqual(count("li .d-icon-far-circle:nth-of-type(1)"), 3);
assert.dom("li .d-icon-far-circle:nth-of-type(1)").exists({ count: 3 });
});
test("single, selected", async function (assert) {
@ -68,7 +67,7 @@ module("Poll | Component | poll-options", function (hooks) {
@sendRadioClick={{this.toggleOption}}
/>`);
assert.strictEqual(count("li .d-icon-circle:nth-of-type(1)"), 1);
assert.dom("li .d-icon-circle:nth-of-type(1)").exists({ count: 1 });
});
test("multi, not selected", async function (assert) {
@ -89,7 +88,7 @@ module("Poll | Component | poll-options", function (hooks) {
@sendRadioClick={{this.toggleOption}}
/>`);
assert.strictEqual(count("li .d-icon-far-square:nth-of-type(1)"), 3);
assert.dom("li .d-icon-far-square:nth-of-type(1)").exists({ count: 3 });
});
test("multi, selected", async function (assert) {
@ -110,7 +109,9 @@ module("Poll | Component | poll-options", function (hooks) {
@sendRadioClick={{this.toggleOption}}
/>`);
assert.strictEqual(count("li .d-icon-far-square-check:nth-of-type(1)"), 1);
assert
.dom("li .d-icon-far-square-check:nth-of-type(1)")
.exists({ count: 1 });
});
test("single with images", async function (assert) {
@ -127,7 +128,7 @@ module("Poll | Component | poll-options", function (hooks) {
@sendRadioClick={{this.toggleOption}}
/>`);
assert.strictEqual(count("li img"), 2);
assert.dom("li img").exists({ count: 2 });
});
test("ranked choice - priorities", async function (assert) {

View File

@ -2,7 +2,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count } from "discourse/tests/helpers/qunit-helpers";
const OPTIONS = [
{ id: "1ddc47be0d2315b9711ee8526ca9d83f", html: "This", votes: 3, rank: 0 },
@ -25,8 +24,7 @@ module("Poll | Component | poll-results-pie", function (hooks) {
hbs`<PollResultsPie @id={{this.id}} @options={{this.options}} />`
);
assert.strictEqual(count("li.legend"), 3);
assert.strictEqual(count("canvas.poll-results-canvas"), 1);
assert.dom("li.legend").exists({ count: 3 });
assert.dom("canvas.poll-results-canvas").exists({ count: 1 });
});
});

View File

@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count, query } from "discourse/tests/helpers/qunit-helpers";
import { query } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
const RANKED_CHOICE_OUTCOME = {
@ -43,11 +43,9 @@ module("Poll | Component | poll-results-ranked-choice", function (hooks) {
hbs`<PollResultsRankedChoice @rankedChoiceOutcome={{this.rankedChoiceOutcome}} />`
);
assert.strictEqual(
count("table.poll-results-ranked-choice tr"),
3,
"there are two rounds of ranked choice"
);
assert
.dom("table.poll-results-ranked-choice tr")
.exists({ count: 3 }, "there are two rounds of ranked choice");
assert.strictEqual(
query("span.poll-results-ranked-choice-info").textContent.trim(),
@ -66,10 +64,11 @@ module("Poll | Component | poll-results-ranked-choice", function (hooks) {
hbs`<PollResultsRankedChoice @rankedChoiceOutcome={{this.rankedChoiceOutcome}} />`
);
assert.strictEqual(
count("table.poll-results-ranked-choice tr"),
1,
"there are no rounds of ranked choice displayed, only the header"
);
assert
.dom("table.poll-results-ranked-choice tr")
.exists(
{ count: 1 },
"there are no rounds of ranked choice displayed, only the header"
);
});
});

View File

@ -2,7 +2,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count } from "discourse/tests/helpers/qunit-helpers";
const TWO_OPTIONS = [
{
@ -86,7 +85,7 @@ module("Poll | Component | poll-results-tabs", function (hooks) {
@fetchVoters={{this.fetchVoters}}
/>`);
assert.strictEqual(count("li.tab"), 1);
assert.dom("li.tab").exists({ count: 1 });
});
test("Renders two tabs for public ranked choice poll", async function (assert) {
@ -118,7 +117,7 @@ module("Poll | Component | poll-results-tabs", function (hooks) {
@fetchVoters={{this.fetchVoters}}
/>`);
assert.strictEqual(count("li.tab"), 2);
assert.dom("li.tab").exists({ count: 2 });
});
test("Renders one tab for private ranked choice poll", async function (assert) {
@ -150,6 +149,6 @@ module("Poll | Component | poll-results-tabs", function (hooks) {
@fetchVoters={{this.fetchVoters}}
/>`);
assert.strictEqual(count("li.tab"), 1);
assert.dom("li.tab").exists({ count: 1 });
});
});