DEV: Extensively use qunit-dom's hasText (#30012)

This commit is contained in:
Jarek Radosz
2024-11-30 16:44:51 +01:00
committed by GitHub
parent d93967e2fb
commit dfb74d90c3
37 changed files with 348 additions and 563 deletions

View File

@ -3,9 +3,8 @@ import { test } from "qunit";
import {
acceptance,
publishToMessageBus,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { i18n } from 'discourse-i18n';
import { i18n } from "discourse-i18n";
acceptance("Poll results", function (needs) {
needs.user();
@ -1117,25 +1116,21 @@ acceptance("Poll results", function (needs) {
test("can load more voters - ranked choice", async function (assert) {
await visit("/t/load-more-poll-voters-ranked-choice/135");
assert.strictEqual(
query(
assert
.dom(
".poll-container .discourse-poll-ranked_choice-results .tab-container .tab.nav-item.active button"
).innerText,
i18n("poll.results.tabs.outcome"),
"Outcome tab is active"
);
)
.hasText(i18n("poll.results.tabs.outcome"), "Outcome tab is active");
await click(
".poll-container .discourse-poll-ranked_choice-results .tab-container .tab.nav-item:not(.active) button"
);
assert.strictEqual(
query(
assert
.dom(
".poll-container .discourse-poll-ranked_choice-results .tab-container .tab.nav-item.active button"
).innerText,
i18n("poll.results.tabs.votes"),
"Votes tab is active"
);
)
.hasText(i18n("poll.results.tabs.votes"), "Votes tab is active");
assert
.dom(

View File

@ -3,7 +3,7 @@ import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from 'discourse-i18n';
import { i18n } from "discourse-i18n";
const TWO_OPTIONS = [
{ id: "1ddc47be0d2315b9711ee8526ca9d83f", html: "This", votes: 5, rank: 0 },
@ -62,8 +62,8 @@ module("Poll | Component | poll-results-standard", function (hooks) {
@fetchVoters={{this.fetchVoters}}
/>`);
assert.strictEqual(queryAll(".option .percentage")[0].innerText, "56%");
assert.strictEqual(queryAll(".option .percentage")[1].innerText, "44%");
assert.dom(queryAll(".option .percentage")[0]).hasText("56%");
assert.dom(queryAll(".option .percentage")[1]).hasText("44%");
assert.dom("ul.poll-voters-list").exists();
});
@ -118,8 +118,8 @@ module("Poll | Component | poll-results-standard", function (hooks) {
@fetchVoters={{this.fetchVoters}}
/>`);
assert.strictEqual(queryAll(".option .percentage")[0].innerText, "56%");
assert.strictEqual(queryAll(".option .percentage")[1].innerText, "44%");
assert.dom(queryAll(".option .percentage")[0]).hasText("56%");
assert.dom(queryAll(".option .percentage")[1]).hasText("44%");
});
test("options in ascending order", async function (assert) {
@ -146,20 +146,14 @@ module("Poll | Component | poll-results-standard", function (hooks) {
/>`);
let percentages = queryAll(".option .percentage");
assert.strictEqual(percentages[0].innerText, "41%");
assert.strictEqual(percentages[1].innerText, "33%");
assert.strictEqual(percentages[2].innerText, "16%");
assert.strictEqual(percentages[3].innerText, "8%");
assert.dom(percentages[0]).hasText("41%");
assert.dom(percentages[1]).hasText("33%");
assert.dom(percentages[2]).hasText("16%");
assert.dom(percentages[3]).hasText("8%");
assert.strictEqual(
queryAll(".option")[3].querySelectorAll("span")[1].innerText,
"a"
);
assert.strictEqual(percentages[4].innerText, "8%");
assert.strictEqual(
queryAll(".option")[4].querySelectorAll("span")[1].innerText,
"b"
);
assert.dom(queryAll(".option")[3].querySelectorAll("span")[1]).hasText("a");
assert.dom(percentages[4]).hasText("8%");
assert.dom(queryAll(".option")[4].querySelectorAll("span")[1]).hasText("b");
});
test("options in ascending order, showing absolute vote number", async function (assert) {