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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 348 additions and 563 deletions

View File

@ -1,34 +1,29 @@
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
function assertNoSecondary(assert) { function assertNoSecondary(assert) {
assert.strictEqual( assert
query(".display-row.email .value a").innerText, .dom(".display-row.email .value a")
"eviltrout@example.com", .hasText("eviltrout@example.com", "displays the primary email");
"it should display the primary email"
);
assert.strictEqual( assert
query(".display-row.secondary-emails .value").innerText.trim(), .dom(".display-row.secondary-emails .value")
.hasText(
i18n("user.email.no_secondary"), i18n("user.email.no_secondary"),
"it should not display secondary emails" "does not display secondary emails"
); );
} }
function assertMultipleSecondary(assert, firstEmail, secondEmail) { function assertMultipleSecondary(assert, firstEmail, secondEmail) {
assert.strictEqual( assert
query(".display-row.secondary-emails .value li:first-of-type a").innerText, .dom(".display-row.secondary-emails .value li:first-of-type a")
firstEmail, .hasText(firstEmail, "displays the first secondary email");
"it should display the first secondary email"
);
assert.strictEqual( assert
query(".display-row.secondary-emails .value li:last-of-type a").innerText, .dom(".display-row.secondary-emails .value li:last-of-type a")
secondEmail, .hasText(secondEmail, "displays the second secondary email");
"it should display the second secondary email"
);
} }
acceptance("Admin - User Emails", function (needs) { acceptance("Admin - User Emails", function (needs) {
@ -45,10 +40,7 @@ acceptance("Admin - User Emails", function (needs) {
assert assert
.dom(".display-row.email .value a") .dom(".display-row.email .value a")
.hasText( .hasText("markvanlan@example.com", "displays the user's primary email");
"markvanlan@example.com",
"it should display the user's primary email"
);
assertMultipleSecondary( assertMultipleSecondary(
assert, assert,

View File

@ -1,6 +1,6 @@
import { click, fillIn, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
acceptance("Admin - Users List", function (needs) { acceptance("Admin - Users List", function (needs) {
@ -58,12 +58,9 @@ acceptance("Admin - Users List", function (needs) {
await click(".hide-emails"); await click(".hide-emails");
assert.strictEqual( assert
query(".users-list .user:nth-child(1) .email .directory-table__value") .dom(".users-list .user:nth-child(1) .email .directory-table__value")
.innerText, .hasNoText("hides the emails");
"",
"hides the emails"
);
}); });
test("switching tabs", async function (assert) { test("switching tabs", async function (assert) {

View File

@ -14,10 +14,7 @@ acceptance("Category Edit - Security", function (needs) {
test("default", async function (assert) { test("default", async function (assert) {
await visit("/c/bug/edit/security"); await visit("/c/bug/edit/security");
const firstRow = query(".row-body"); assert.dom(".row-body .group-name-label").hasText("everyone");
const badgeName = firstRow.querySelector(".group-name-label").innerText;
assert.strictEqual(badgeName, "everyone");
assert.dom(".d-icon-square-check").exists({ count: 3 }); assert.dom(".d-icon-square-check").exists({ count: 3 });
}); });
@ -57,10 +54,7 @@ acceptance("Category Edit - Security", function (needs) {
const addedRow = [...queryAll(".row-body")].at(-1); const addedRow = [...queryAll(".row-body")].at(-1);
assert.strictEqual( assert.dom(".group-name-link", addedRow).hasText("staff");
addedRow.querySelector(".group-name-link").innerText,
"staff"
);
assert.strictEqual( assert.strictEqual(
addedRow.querySelectorAll(".d-icon-square-check").length, addedRow.querySelectorAll(".d-icon-square-check").length,
3, 3,
@ -85,10 +79,7 @@ acceptance("Category Edit - Security", function (needs) {
const firstRow = query(".row-body"); const firstRow = query(".row-body");
assert.strictEqual( assert.dom(".group-name-label", firstRow).hasText("everyone");
firstRow.querySelector(".group-name-label").innerText,
"everyone"
);
assert.strictEqual( assert.strictEqual(
firstRow.querySelectorAll(".d-icon-square-check").length, firstRow.querySelectorAll(".d-icon-square-check").length,
1, 1,

View File

@ -521,10 +521,9 @@ acceptance("Composer", function (needs) {
// at this point, request is in flight, so post is staged // at this point, request is in flight, so post is staged
assert.dom(".topic-post").exists(); assert.dom(".topic-post").exists();
assert.dom(".topic-post").hasClass("staged"); assert.dom(".topic-post").hasClass("staged");
assert.strictEqual( assert
query(".topic-post.staged .cooked").innerText.trim(), .dom(".topic-post.staged .cooked")
"will return empty json" .hasText("will return empty json");
);
return response(200, {}); return response(200, {});
}); });

View File

@ -1,7 +1,7 @@
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { registerTemporaryModule } from "discourse/tests/helpers/temporary-module-helper"; import { registerTemporaryModule } from "discourse/tests/helpers/temporary-module-helper";
import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated"; import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated";
@ -18,11 +18,7 @@ acceptance("CustomHTML template", function (needs) {
"discourse.custom_html_template", "discourse.custom_html_template",
async () => { async () => {
await visit("/static/faq"); await visit("/static/faq");
assert.strictEqual( assert.dom("span.top-span").hasText("TOP", "inserted the template");
query("span.top-span").innerText,
"TOP",
"it inserted the template"
);
} }
); );
}); });

View File

@ -111,18 +111,16 @@ acceptance(
await formKit().submit(); await formKit().submit();
await click(".group-manage-save"); await click(".group-manage-save");
assert.strictEqual( assert.dom(".group-manage-save-button > span").hasText("Saved!");
query(".group-manage-save-button > span").innerText,
"Saved!"
);
assert assert
.dom("#enable_imap") .dom("#enable_imap")
.isEnabled("IMAP is able to be enabled now that SMTP is saved"); .isEnabled("IMAP is able to be enabled now that SMTP is saved");
await click("#enable_smtp"); await click("#enable_smtp");
assert.strictEqual( assert
query(".dialog-body").innerText.trim(), .dom(".dialog-body")
.hasText(
i18n("groups.manage.email.smtp_disable_confirm"), i18n("groups.manage.email.smtp_disable_confirm"),
"shows a confirm dialogue warning SMTP settings will be wiped" "shows a confirm dialogue warning SMTP settings will be wiped"
); );
@ -172,10 +170,7 @@ acceptance(
await click(".group-manage-save"); await click(".group-manage-save");
assert.strictEqual( assert.dom(".group-manage-save-button > span").hasText("Saved!");
query(".group-manage-save-button > span").innerText,
"Saved!"
);
assert assert
.dom(".imap-no-mailbox-selected") .dom(".imap-no-mailbox-selected")
@ -194,8 +189,9 @@ acceptance(
.doesNotExist("no longer shows a no mailbox selected message"); .doesNotExist("no longer shows a no mailbox selected message");
await click("#enable_imap"); await click("#enable_imap");
assert.strictEqual( assert
query(".dialog-body").innerText.trim(), .dom(".dialog-body")
.hasText(
i18n("groups.manage.email.imap_disable_confirm"), i18n("groups.manage.email.imap_disable_confirm"),
"shows a confirm dialogue warning IMAP settings will be wiped" "shows a confirm dialogue warning IMAP settings will be wiped"
); );
@ -349,8 +345,7 @@ acceptance(
await formKit().field("email_password").fillIn("password"); await formKit().field("email_password").fillIn("password");
await formKit().submit(); await formKit().submit();
assert.strictEqual( assert.dom(".dialog-body").hasText(
query(".dialog-body").innerText.trim(),
i18n("generic_error_with_reason", { i18n("generic_error_with_reason", {
error: error:
"There was an issue with the SMTP credentials provided, check the username and password and try again.", "There was an issue with the SMTP credentials provided, check the username and password and try again.",

View File

@ -1,6 +1,6 @@
import { click, fillIn, visit } from "@ember/test-helpers"; import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
acceptance("New Group - Anonymous", function () { acceptance("New Group - Anonymous", function () {
@ -69,12 +69,11 @@ acceptance("New Group - Authenticated", function (needs) {
.dom("groups-new-allow-membership-requests") .dom("groups-new-allow-membership-requests")
.doesNotExist("it should disable the membership requests checkbox"); .doesNotExist("it should disable the membership requests checkbox");
assert.strictEqual( assert
query( .dom(".groups-form-default-notification-level .selected-name .name")
".groups-form-default-notification-level .selected-name .name" .hasText(
).innerText.trim(),
i18n("groups.notifications.watching.title"), i18n("groups.notifications.watching.title"),
"it has a default selection for notification level" "has a default selection for notification level"
); );
}); });
}); });

View File

@ -4,7 +4,6 @@ import {
acceptance, acceptance,
loggedInUser, loggedInUser,
publishToMessageBus, publishToMessageBus,
query,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
@ -133,20 +132,10 @@ acceptance("Review", function (needs) {
assert.dom(`${topic} .reviewable-action.approve`).exists(); assert.dom(`${topic} .reviewable-action.approve`).exists();
assert.dom(`${topic} .badge-category__name`).doesNotExist(); assert.dom(`${topic} .badge-category__name`).doesNotExist();
assert.strictEqual( assert.dom(`${topic} .discourse-tag:nth-of-type(1)`).hasText("hello");
query(`${topic} .discourse-tag:nth-of-type(1)`).innerText, assert.dom(`${topic} .discourse-tag:nth-of-type(2)`).hasText("world");
"hello"
);
assert.strictEqual( assert.dom(`${topic} .post-body`).hasText("existing body");
query(`${topic} .discourse-tag:nth-of-type(2)`).innerText,
"world"
);
assert.strictEqual(
query(`${topic} .post-body`).innerText.trim(),
"existing body"
);
await click(`${topic} .reviewable-action.edit`); await click(`${topic} .reviewable-action.edit`);
await click(`${topic} .reviewable-action.save-edit`); await click(`${topic} .reviewable-action.save-edit`);
@ -164,11 +153,9 @@ acceptance("Review", function (needs) {
await fillIn(".editable-field.payload-raw textarea", "new raw contents"); await fillIn(".editable-field.payload-raw textarea", "new raw contents");
await click(`${topic} .reviewable-action.cancel-edit`); await click(`${topic} .reviewable-action.cancel-edit`);
assert.strictEqual( assert
query(`${topic} .post-body`).innerText.trim(), .dom(`${topic} .post-body`)
"existing body", .hasText("existing body", "cancelling does not update the value");
"cancelling does not update the value"
);
await click(`${topic} .reviewable-action.edit`); await click(`${topic} .reviewable-action.edit`);
let category = selectKit(`${topic} .category-id .select-kit`); let category = selectKit(`${topic} .category-id .select-kit`);
@ -193,27 +180,12 @@ acceptance("Review", function (needs) {
await fillIn(".editable-field.payload-raw textarea", "new raw contents"); await fillIn(".editable-field.payload-raw textarea", "new raw contents");
await click(`${topic} .reviewable-action.save-edit`); await click(`${topic} .reviewable-action.save-edit`);
assert.strictEqual( assert.dom(`${topic} .discourse-tag:nth-of-type(1)`).hasText("hello");
query(`${topic} .discourse-tag:nth-of-type(1)`).innerText, assert.dom(`${topic} .discourse-tag:nth-of-type(2)`).hasText("world");
"hello" assert.dom(`${topic} .discourse-tag:nth-of-type(3)`).hasText("monkey");
);
assert.strictEqual(
query(`${topic} .discourse-tag:nth-of-type(2)`).innerText,
"world"
);
assert.strictEqual(
query(`${topic} .discourse-tag:nth-of-type(3)`).innerText,
"monkey"
);
assert.strictEqual( assert.dom(`${topic} .post-body`).hasText("new raw contents");
query(`${topic} .post-body`).innerText.trim(), assert.dom(`${topic} .badge-category__name`).hasText("support");
"new raw contents"
);
assert.strictEqual(
query(`${topic} .badge-category__name`).innerText.trim(),
"support"
);
}); });
test("Reviewables can become stale", async function (assert) { test("Reviewables can become stale", async function (assert) {

View File

@ -119,18 +119,17 @@ acceptance("Search - Anonymous", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "dev"); await fillIn("#search-term", "dev");
assert.strictEqual( assert
query( .dom(
".search-menu .results ul.search-menu-initial-options li:first-child .search-item-prefix" ".search-menu .results ul.search-menu-initial-options li:first-child .search-item-prefix"
).innerText.trim(), )
"dev", .hasText("dev", "first dropdown item includes correct prefix");
"first dropdown item includes correct prefix"
);
assert.strictEqual( assert
query( .dom(
".search-menu .results ul.search-menu-initial-options li:first-child .search-item-slug" ".search-menu .results ul.search-menu-initial-options li:first-child .search-item-slug"
).innerText.trim(), )
.hasText(
i18n("search.in_topics_posts"), i18n("search.in_topics_posts"),
"first dropdown item includes correct suffix" "first dropdown item includes correct suffix"
); );
@ -866,20 +865,15 @@ acceptance("Search - with tagging enabled", function (needs) {
await visit("/tags/c/bug/dev"); await visit("/tags/c/bug/dev");
await click("#search-button"); await click("#search-button");
assert.strictEqual( assert
query( .dom(
".search-menu .results ul.search-menu-assistant .badge-category__name" ".search-menu .results ul.search-menu-assistant .badge-category__name"
).innerText, )
"bug", .hasText("bug", "Category is displayed");
"Category is displayed"
);
assert.strictEqual( assert
query(".search-menu .results ul.search-menu-assistant .search-item-tag") .dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText, .hasText("dev", "Tag is displayed");
"dev",
"Tag is displayed"
);
}); });
test("initial options - tag and category search scope - updates tag / category combination search suggestion when typing", async function (assert) { test("initial options - tag and category search scope - updates tag / category combination search suggestion when typing", async function (assert) {
@ -887,27 +881,19 @@ acceptance("Search - with tagging enabled", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "foo bar"); await fillIn("#search-term", "foo bar");
assert.strictEqual( assert
query( .dom(".search-menu .results ul.search-menu-assistant .search-item-prefix")
".search-menu .results ul.search-menu-assistant .search-item-prefix" .hasText("foo bar", "Input is applied to search query");
).innerText,
"foo bar",
"Input is applied to search query"
);
assert.strictEqual( assert
query( .dom(
".search-menu .results ul.search-menu-assistant .badge-category__name" ".search-menu .results ul.search-menu-assistant .badge-category__name"
).innerText, )
"bug" .hasText("bug");
);
assert.strictEqual( assert
query(".search-menu .results ul.search-menu-assistant .search-item-tag") .dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText, .hasText("dev", "Tag is displayed");
"dev",
"Tag is displayed"
);
}); });
test("initial options - search history - tag intersection context", async function (assert) { test("initial options - search history - tag intersection context", async function (assert) {
@ -923,12 +909,9 @@ acceptance("Search - with tagging enabled", function (needs) {
await visit("/tags/intersection/dev/foo"); await visit("/tags/intersection/dev/foo");
await click("#search-button"); await click("#search-button");
assert.strictEqual( assert
query(".search-menu .results ul.search-menu-assistant .search-item-tag") .dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText, .hasText("tags:dev+foo", "Tags are displayed");
"tags:dev+foo",
"Tags are displayed"
);
}); });
test("initial options - tag intersection search scope - updates tag intersection search suggestion when typing", async function (assert) { test("initial options - tag intersection search scope - updates tag intersection search suggestion when typing", async function (assert) {
@ -936,20 +919,13 @@ acceptance("Search - with tagging enabled", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "foo bar"); await fillIn("#search-term", "foo bar");
assert.strictEqual( assert
query( .dom(".search-menu .results ul.search-menu-assistant .search-item-prefix")
".search-menu .results ul.search-menu-assistant .search-item-prefix" .hasText("foo bar", "Input is applied to search query");
).innerText,
"foo bar",
"Input is applied to search query"
);
assert.strictEqual( assert
query(".search-menu .results ul.search-menu-assistant .search-item-tag") .dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText, .hasText("tags:dev+foo", "Tags are displayed");
"tags:dev+foo",
"Tags are displayed"
);
}); });
}); });
@ -1135,12 +1111,11 @@ acceptance("Search - assistant", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "#"); await fillIn("#search-term", "#");
assert.strictEqual( assert
query( .dom(
".search-menu .results ul.search-menu-assistant .search-link .badge-category__name" ".search-menu .results ul.search-menu-assistant .search-link .badge-category__name"
).innerText, )
"support" .hasText("support");
);
}); });
test("initial options - shows in: shortcuts", async function (assert) { test("initial options - shows in: shortcuts", async function (assert) {
@ -1150,23 +1125,17 @@ acceptance("Search - assistant", function (needs) {
".search-menu .results ul.search-menu-assistant .search-link"; ".search-menu .results ul.search-menu-assistant .search-link";
await fillIn("#search-term", "in:"); await fillIn("#search-term", "in:");
assert.strictEqual( assert
query(firstTarget.concat(".search-item-slug")).innerText, .dom(`${firstTarget} .search-item-slug`)
"in:title", .hasText("in:title", "keyword is present in suggestion");
"keyword is present in suggestion"
);
await fillIn("#search-term", "sam in:"); await fillIn("#search-term", "sam in:");
assert.strictEqual( assert
query(firstTarget.concat(".search-item-prefix")).innerText, .dom(`${firstTarget} .search-item-prefix`)
"sam", .hasText("sam", "term is present in suggestion");
"term is present in suggestion" assert
); .dom(`${firstTarget} .search-item-slug`)
assert.strictEqual( .hasText("in:title", "keyword is present in suggestion");
query(firstTarget.concat(".search-item-slug")).innerText,
"in:title",
"keyword is present in suggestion"
);
await fillIn("#search-term", "in:mess"); await fillIn("#search-term", "in:mess");
assert.dom(firstTarget).hasText("in:messages"); assert.dom(firstTarget).hasText("in:messages");
@ -1176,13 +1145,22 @@ acceptance("Search - assistant", function (needs) {
await visit("/"); await visit("/");
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "@"); await fillIn("#search-term", "@");
const firstUser = query( assert
.dom(
".search-menu .results ul.search-menu-assistant .search-item-user .username"
)
.hasText("TeaMoe");
const username = document
.querySelector(
".search-menu .results ul.search-menu-assistant .search-item-user .username"
)
.innerText.trim();
await click(
".search-menu .results ul.search-menu-assistant .search-item-user" ".search-menu .results ul.search-menu-assistant .search-item-user"
); );
const username = firstUser.querySelector(".username").innerText.trim();
assert.strictEqual(username, "TeaMoe");
await click(firstUser);
assert.dom("#search-term").hasValue(`@${username}`); assert.dom("#search-term").hasValue(`@${username}`);
}); });
@ -1244,16 +1222,18 @@ acceptance("Search - assistant", function (needs) {
.exists({ count: 1 }, "passes the PM search context to the search query"); .exists({ count: 1 }, "passes the PM search context to the search query");
}); });
test("topic results - updates search term when selecting a initial category option", async function (assert) { test("topic results - updates search term when selecting an initial category option", async function (assert) {
await visit("/"); await visit("/");
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "sam #"); await fillIn("#search-term", "sam #");
const firstCategory = const firstCategory =
".search-menu .results ul.search-menu-assistant .search-link"; ".search-menu .results ul.search-menu-assistant .search-link";
const firstCategoryName = query( const firstCategoryName = document.querySelector(
`${firstCategory} .badge-category__name` `${firstCategory} .badge-category__name`
).innerText; ).innerText;
await click(firstCategory);
await click(`${firstCategory} .badge-category__name`);
assert.strictEqual( assert.strictEqual(
query("#search-term").value, query("#search-term").value,

View File

@ -5,7 +5,6 @@ import {
acceptance, acceptance,
fakeTime, fakeTime,
loggedInUser, loggedInUser,
query,
queryAll, queryAll,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -159,10 +158,6 @@ acceptance("Topic - Edit timer", function (needs) {
await click("#tap_tile_start_of_next_business_week"); await click("#tap_tile_start_of_next_business_week");
const text = query(
".edit-topic-timer-modal .topic-timer-info"
).innerText.trim();
// this needs to be done because there is no simple way to get the // this needs to be done because there is no simple way to get the
// plain text version of a translation with HTML // plain text version of a translation with HTML
let el = document.createElement("p"); let el = document.createElement("p");
@ -172,7 +167,9 @@ acceptance("Topic - Edit timer", function (needs) {
timeLeft: "in 6 days", timeLeft: "in 6 days",
}); });
assert.strictEqual(text, el.innerText); assert
.dom(".edit-topic-timer-modal .topic-timer-info")
.hasText(el.innerText);
}); });
test("schedule publish to category - visible for a private category", async function (assert) { test("schedule publish to category - visible for a private category", async function (assert) {
@ -196,10 +193,6 @@ acceptance("Topic - Edit timer", function (needs) {
await click("#tap_tile_start_of_next_business_week"); await click("#tap_tile_start_of_next_business_week");
const text = query(
".edit-topic-timer-modal .topic-timer-info"
).innerText.trim();
// this needs to be done because there is no simple way to get the // this needs to be done because there is no simple way to get the
// plain text version of a translation with HTML // plain text version of a translation with HTML
let el = document.createElement("p"); let el = document.createElement("p");
@ -209,7 +202,9 @@ acceptance("Topic - Edit timer", function (needs) {
timeLeft: "in 6 days", timeLeft: "in 6 days",
}); });
assert.strictEqual(text, el.innerText); assert
.dom(".edit-topic-timer-modal .topic-timer-info")
.hasText(el.innerText);
}); });
test("schedule publish to category - visible for an unlisted public topic", async function (assert) { test("schedule publish to category - visible for an unlisted public topic", async function (assert) {
@ -237,10 +232,6 @@ acceptance("Topic - Edit timer", function (needs) {
await click("#tap_tile_start_of_next_business_week"); await click("#tap_tile_start_of_next_business_week");
const text = query(
".edit-topic-timer-modal .topic-timer-info"
).innerText.trim();
// this needs to be done because there is no simple way to get the // this needs to be done because there is no simple way to get the
// plain text version of a translation with HTML // plain text version of a translation with HTML
let el = document.createElement("p"); let el = document.createElement("p");
@ -250,7 +241,9 @@ acceptance("Topic - Edit timer", function (needs) {
timeLeft: "in 6 days", timeLeft: "in 6 days",
}); });
assert.strictEqual(text, el.innerText); assert
.dom(".edit-topic-timer-modal .topic-timer-info")
.hasText(el.innerText);
}); });
test("schedule publish to category - last custom date and time", async function (assert) { test("schedule publish to category - last custom date and time", async function (assert) {

View File

@ -273,8 +273,7 @@ acceptance("Topic featured links", function (needs) {
test("remove nofollow attribute", async function (assert) { test("remove nofollow attribute", async function (assert) {
await visit("/t/-/299/1"); await visit("/t/-/299/1");
const link = query(".title-wrapper .topic-featured-link"); assert.dom(".title-wrapper .topic-featured-link").hasText("example.com");
assert.strictEqual(link.innerText, "example.com");
assert assert
.dom(".title-wrapper .topic-featured-link") .dom(".title-wrapper .topic-featured-link")
.hasAttribute("rel", "ugc"); .hasAttribute("rel", "ugc");

View File

@ -2,7 +2,6 @@ import { click, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { import {
acceptance, acceptance,
query,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
@ -28,13 +27,9 @@ acceptance("User Preferences - Security", function (needs) {
test("recently connected devices", async function (assert) { test("recently connected devices", async function (assert) {
await visit("/u/eviltrout/preferences/security"); await visit("/u/eviltrout/preferences/security");
assert.strictEqual( assert
query( .dom(".auth-tokens > .auth-token:nth-of-type(1) .auth-token-device")
".auth-tokens > .auth-token:nth-of-type(1) .auth-token-device" .hasText("Linux Computer", "displays active token first");
).innerText.trim(),
"Linux Computer",
"it should display active token first"
);
assert assert
.dom(".pref-auth-tokens > a:nth-of-type(1)") .dom(".pref-auth-tokens > a:nth-of-type(1)")

View File

@ -356,14 +356,16 @@ acceptance(
await publishUnreadToMessageBus({ topicId: 1 }); await publishUnreadToMessageBus({ topicId: 1 });
await publishNewToMessageBus({ topicId: 2 }); await publishNewToMessageBus({ topicId: 2 });
assert.strictEqual( assert
query(".user-nav__messages-new").innerText.trim(), .dom(".user-nav__messages-new")
.hasText(
i18n("user.messages.new_with_count", { count: 1 }), i18n("user.messages.new_with_count", { count: 1 }),
"displays the right count" "displays the right count"
); );
assert.strictEqual( assert
query(".user-nav__messages-unread").innerText.trim(), .dom(".user-nav__messages-unread")
.hasText(
i18n("user.messages.unread_with_count", { count: 1 }), i18n("user.messages.unread_with_count", { count: 1 }),
"displays the right count" "displays the right count"
); );
@ -374,8 +376,9 @@ acceptance(
await publishNewToMessageBus({ topicId: 1 }); await publishNewToMessageBus({ topicId: 1 });
assert.strictEqual( assert
query(".messages-nav .user-nav__messages-new").innerText.trim(), .dom(".messages-nav .user-nav__messages-new")
.hasText(
i18n("user.messages.new_with_count", { count: 1 }), i18n("user.messages.new_with_count", { count: 1 }),
"displays the right count" "displays the right count"
); );
@ -384,8 +387,9 @@ acceptance(
await publishNewToMessageBus({ topicId: 2 }); await publishNewToMessageBus({ topicId: 2 });
assert.strictEqual( assert
query(".messages-nav .user-nav__messages-new").innerText.trim(), .dom(".messages-nav .user-nav__messages-new")
.hasText(
i18n("user.messages.new_with_count", { count: 2 }), i18n("user.messages.new_with_count", { count: 2 }),
"displays the right count" "displays the right count"
); );
@ -398,8 +402,9 @@ acceptance(
await publishUnreadToMessageBus(); await publishUnreadToMessageBus();
assert.strictEqual( assert
query(".messages-nav .user-nav__messages-unread").innerText.trim(), .dom(".messages-nav .user-nav__messages-unread")
.hasText(
i18n("user.messages.unread_with_count", { count: 1 }), i18n("user.messages.unread_with_count", { count: 1 }),
"displays the right count" "displays the right count"
); );
@ -413,16 +418,16 @@ acceptance(
await publishUnreadToMessageBus({ groupIds: [14], topicId: 1 }); await publishUnreadToMessageBus({ groupIds: [14], topicId: 1 });
await publishNewToMessageBus({ groupIds: [14], topicId: 2 }); await publishNewToMessageBus({ groupIds: [14], topicId: 2 });
assert.strictEqual( assert
query( .dom(".messages-nav .user-nav__messages-group-unread")
".messages-nav .user-nav__messages-group-unread" .hasText(
).innerText.trim(),
i18n("user.messages.unread_with_count", { count: 1 }), i18n("user.messages.unread_with_count", { count: 1 }),
"displays the right count" "displays the right count"
); );
assert.strictEqual( assert
query(".messages-nav .user-nav__messages-group-new").innerText.trim(), .dom(".messages-nav .user-nav__messages-group-new")
.hasText(
i18n("user.messages.new_with_count", { count: 1 }), i18n("user.messages.new_with_count", { count: 1 }),
"displays the right count" "displays the right count"
); );
@ -431,17 +436,13 @@ acceptance(
await visit("/u/charlie/messages/unread"); await visit("/u/charlie/messages/unread");
assert.strictEqual( assert
query(".messages-nav .user-nav__messages-unread").innerText.trim(), .dom(".messages-nav .user-nav__messages-unread")
i18n("user.messages.unread"), .hasText(i18n("user.messages.unread"), "displays the right count");
"displays the right count"
);
assert.strictEqual( assert
query(".messages-nav .user-nav__messages-new").innerText.trim(), .dom(".messages-nav .user-nav__messages-new")
i18n("user.messages.new"), .hasText(i18n("user.messages.new"), "displays the right count");
"displays the right count"
);
}); });
test("incoming messages is not tracked on non user messages route", async function (assert) { test("incoming messages is not tracked on non user messages route", async function (assert) {
@ -471,11 +472,9 @@ acceptance(
await click(".btn.dismiss-read"); await click(".btn.dismiss-read");
await click("#dismiss-read-confirm"); await click("#dismiss-read-confirm");
assert.strictEqual( assert
query(".user-nav__messages-unread").innerText.trim(), .dom(".user-nav__messages-unread")
i18n("user.messages.unread"), .hasText(i18n("user.messages.unread"), "displays the right count");
"displays the right count"
);
assert assert
.dom(".topic-list-item") .dom(".topic-list-item")
@ -525,11 +524,9 @@ acceptance(
await click(".btn.dismiss-read"); await click(".btn.dismiss-read");
assert.strictEqual( assert
query(".messages-nav .user-nav__messages-new").innerText.trim(), .dom(".messages-nav .user-nav__messages-new")
i18n("user.messages.new"), .hasText(i18n("user.messages.new"), "displays the right count");
"displays the right count"
);
assert assert
.dom(".topic-list-item") .dom(".topic-list-item")

View File

@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
module( module(
@ -63,11 +63,9 @@ module(
.dom(".form-template-field__dropdown") .dom(".form-template-field__dropdown")
.exists("a dropdown component exists"); .exists("a dropdown component exists");
assert.strictEqual( assert
query(".form-template-field__dropdown-placeholder").innerText, .dom(".form-template-field__dropdown-placeholder")
attributes.none_label, .hasText(attributes.none_label, "None label is correct");
"None label is correct"
);
}); });
test("doesn't render a label when attribute is missing", async function (assert) { test("doesn't render a label when attribute is missing", async function (assert) {

View File

@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper"; import selectKit from "discourse/tests/helpers/select-kit-helper";
module( module(
@ -64,11 +64,9 @@ module(
.dom(".form-template-field__multi-select") .dom(".form-template-field__multi-select")
.exists("a multiselect dropdown component exists"); .exists("a multiselect dropdown component exists");
assert.strictEqual( assert
query(".form-template-field__multi-select-placeholder").innerText, .dom(".form-template-field__multi-select-placeholder")
attributes.none_label, .hasText(attributes.none_label, "None label is correct");
"None label is correct"
);
}); });
test("doesn't render a label when attribute is missing", async function (assert) { test("doesn't render a label when attribute is missing", async function (assert) {

View File

@ -3,7 +3,6 @@ import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api"; import { withPluginApi } from "discourse/lib/plugin-api";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import selectKit, { import selectKit, {
DEFAULT_CONTENT, DEFAULT_CONTENT,
setDefaultState, setDefaultState,
@ -89,7 +88,7 @@ module("Integration | Component | select-kit/api", function (hooks) {
withPluginApi("0.8.43", (api) => { withPluginApi("0.8.43", (api) => {
api.modifySelectKit("combo-box").onChange((component, value, item) => { api.modifySelectKit("combo-box").onChange((component, value, item) => {
query("#test").innerText = item.name; document.querySelector("#test").innerText = item.name;
}); });
}); });

View File

@ -303,11 +303,9 @@ module(
await this.subject.expand(); await this.subject.expand();
assert.strictEqual( assert
this.subject.rowByIndex(0).el().querySelector(".category-desc") .dom(".category-desc", this.subject.rowByIndex(0).el())
.innerText, .hasText('baz "bar foo');
'baz "bar foo'
);
}); });
} }
); );

View File

@ -234,13 +234,10 @@ module("Integration | Component | select-kit/category-drop", function (hooks) {
const category = Category.findById(7); const category = Category.findById(7);
const row = this.subject.rowByValue(category.id); const row = this.subject.rowByValue(category.id);
const topicCount = row.el().querySelector(".topic-count").innerText.trim();
assert.strictEqual( assert
topicCount, .dom(".topic-count", row.el())
"× 481", .hasText("× 481", "doesn't include the topic count of subcategories");
"doesn't include the topic count of subcategories"
);
}); });
test("countSubcategories (true)", async function (assert) { test("countSubcategories (true)", async function (assert) {
@ -261,13 +258,10 @@ module("Integration | Component | select-kit/category-drop", function (hooks) {
const category = Category.findById(7); const category = Category.findById(7);
const row = this.subject.rowByValue(category.id); const row = this.subject.rowByValue(category.id);
const topicCount = row.el().querySelector(".topic-count").innerText.trim();
assert.strictEqual( assert
topicCount, .dom(".topic-count", row.el())
"× 584", .hasText("× 584", "includes the topic count of subcategories");
"includes the topic count of subcategories"
);
}); });
test("shortcuts:default", async function (assert) { test("shortcuts:default", async function (assert) {

View File

@ -44,14 +44,12 @@ module(
await this.subject.fillInFilter("Parent Category"); await this.subject.fillInFilter("Parent Category");
assert.strictEqual(this.subject.rows().length, 2); assert.strictEqual(this.subject.rows().length, 2);
assert.strictEqual( assert
this.subject.rowByIndex(0).el().innerText.replace("\n", " "), .dom(this.subject.rowByIndex(0).el())
"Parent Category × 95" .hasText("Parent Category× 95");
); assert
assert.strictEqual( .dom(this.subject.rowByIndex(1).el())
this.subject.rowByIndex(1).el().innerText.replaceAll("\n", " "), .hasText("Parent Category× 95+2 subcategories");
"Parent Category × 95 +2 subcategories"
);
}); });
} }
); );

View File

@ -58,9 +58,7 @@ module(
await this.subject.fillInFilter("baz"); await this.subject.fillInFilter("baz");
await this.subject.selectRowByValue("monkey"); await this.subject.selectRowByValue("monkey");
const error = query(".select-kit-error").innerText; assert.dom(".select-kit-error").hasText(
assert.strictEqual(
error,
i18n("select_kit.max_content_reached", { i18n("select_kit.max_content_reached", {
count: this.siteSettings.max_tags_per_topic, count: this.siteSettings.max_tags_per_topic,
}) })
@ -76,9 +74,7 @@ module(
assert.strictEqual(this.subject.header().value(), "cat,kit"); assert.strictEqual(this.subject.header().value(), "cat,kit");
await this.subject.expand(); await this.subject.expand();
const error = query(".select-kit-error").innerText; assert.dom(".select-kit-error").hasText(
assert.strictEqual(
error,
i18n("select_kit.max_content_reached", { i18n("select_kit.max_content_reached", {
count: 0, count: 0,
}) })

View File

@ -2,7 +2,6 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
import Theme from "admin/models/theme"; import Theme from "admin/models/theme";
@ -59,19 +58,16 @@ module("Integration | Component | themes-list-item", function (hooks) {
await render(hbs`<ThemesListItem @theme={{this.theme}} />`); await render(hbs`<ThemesListItem @theme={{this.theme}} />`);
assert.deepEqual( assert.deepEqual(
query(".components") document
.innerText.trim() .querySelector(".components")
.split(",") .innerText.split(",")
.map((n) => n.trim()) .map((n) => n.trim()),
.join(","), this.childrenList.splice(0, 4).map((theme) => theme.get("name")),
this.childrenList
.splice(0, 4)
.map((theme) => theme.get("name"))
.join(","),
"lists the first 4 children" "lists the first 4 children"
); );
assert.deepEqual( assert
query(".others-count").innerText.trim(), .dom(".others-count")
.hasText(
i18n("admin.customize.theme.and_x_more", { count: 1 }), i18n("admin.customize.theme.and_x_more", { count: 1 }),
"shows count of remaining children" "shows count of remaining children"
); );

View File

@ -2,11 +2,7 @@ import { click, render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { import { fakeTime, queryAll } from "discourse/tests/helpers/qunit-helpers";
fakeTime,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
module("Integration | Component | time-shortcut-picker", function (hooks) { module("Integration | Component | time-shortcut-picker", function (hooks) {
@ -140,11 +136,9 @@ module("Integration | Component | time-shortcut-picker", function (hooks) {
.dom("#tap_tile_start_of_next_business_week .tap-tile-title") .dom("#tap_tile_start_of_next_business_week .tap-tile-title")
.hasText("Next Monday"); .hasText("Next Monday");
assert.strictEqual( assert
query("div#tap_tile_start_of_next_business_week div.tap-tile-date") .dom("div#tap_tile_start_of_next_business_week div.tap-tile-date")
.innerText, .hasText("Feb 1, 8:00 am");
"Feb 1, 8:00 am"
);
}); });
test("shows 'Next Monday' instead of 'Monday' on Mondays", async function (assert) { test("shows 'Next Monday' instead of 'Monday' on Mondays", async function (assert) {
@ -157,11 +151,9 @@ module("Integration | Component | time-shortcut-picker", function (hooks) {
.dom("#tap_tile_start_of_next_business_week .tap-tile-title") .dom("#tap_tile_start_of_next_business_week .tap-tile-title")
.hasText("Next Monday"); .hasText("Next Monday");
assert.strictEqual( assert
query("div#tap_tile_start_of_next_business_week div.tap-tile-date") .dom("div#tap_tile_start_of_next_business_week div.tap-tile-date")
.innerText, .hasText("Feb 1, 8:00 am");
"Feb 1, 8:00 am"
);
}); });
test("the 'Next Month' option points to the first day of the next month", async function (assert) { test("the 'Next Month' option points to the first day of the next month", async function (assert) {

View File

@ -4,7 +4,7 @@ import { click, render, triggerEvent } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { count, query, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { count, queryAll } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
module( module(
@ -721,8 +721,7 @@ module(
await render(hbs` await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`); <MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
assert.strictEqual( assert.dom(".post-notice.returning-user:not(.old)").hasText(
query(".post-notice.returning-user:not(.old)").innerText.trim(),
i18n("post.notice.returning_user", { i18n("post.notice.returning_user", {
user: "codinghorror", user: "codinghorror",
time: "2 days ago", time: "2 days ago",
@ -744,8 +743,9 @@ module(
await render(hbs` await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`); <MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
assert.strictEqual( assert
query(".post-notice.old.new-user").innerText.trim(), .dom(".post-notice.old.new-user")
.hasText(
i18n("post.notice.new_user", { user: "Jeff", time: "Jan '10" }) i18n("post.notice.new_user", { user: "Jeff", time: "Jan '10" })
); );
}); });
@ -759,12 +759,10 @@ module(
await render(hbs` await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`); <MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
const link = query(".group-request a"); assert.dom(".group-request a").hasText(i18n("groups.requests.handle"));
assert.strictEqual(link.innerText.trim(), i18n("groups.requests.handle")); assert
assert.strictEqual( .dom(".group-request a")
link.getAttribute("href"), .hasAttribute("href", "/g/testGroup/requests?filter=foo");
"/g/testGroup/requests?filter=foo"
);
}); });
test("shows user status if enabled in site settings", async function (assert) { test("shows user status if enabled in site settings", async function (assert) {

View File

@ -6,7 +6,6 @@ import { click, render, triggerEvent } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
module("Integration | Component | Widget | post", function (hooks) { module("Integration | Component | Widget | post", function (hooks) {
@ -1155,8 +1154,7 @@ module("Integration | Component | Widget | post", function (hooks) {
await render(hbs` await render(hbs`
<MountWidget @widget="post" @args={{this.args}} />`); <MountWidget @widget="post" @args={{this.args}} />`);
const link = query(".group-request a"); assert.dom(".group-request a").hasText(i18n("groups.requests.handle"));
assert.strictEqual(link.innerText.trim(), i18n("groups.requests.handle"));
assert assert
.dom(".group-request a") .dom(".group-request a")
.hasAttribute("href", "/g/testGroup/requests?filter=foo"); .hasAttribute("href", "/g/testGroup/requests?filter=foo");

View File

@ -29,10 +29,6 @@ async function toggle() {
await click("#my-dropdown .widget-dropdown-header"); await click("#my-dropdown .widget-dropdown-header");
} }
function headerLabel() {
return query("#my-dropdown .widget-dropdown-header .label").innerText.trim();
}
function header() { function header() {
return query("#my-dropdown .widget-dropdown-header"); return query("#my-dropdown .widget-dropdown-header");
} }
@ -79,7 +75,7 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
await render(TEMPLATE); await render(TEMPLATE);
assert.strictEqual(headerLabel(), "FooBaz"); assert.dom("#my-dropdown .widget-dropdown-header .label").hasText("FooBaz");
}); });
test("translatedLabel", async function (assert) { test("translatedLabel", async function (assert) {
@ -89,7 +85,7 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
await render(TEMPLATE); await render(TEMPLATE);
assert.strictEqual(headerLabel(), this.translatedLabel); assert.dom("#my-dropdown .widget-dropdown-header .label").hasText("BazFoo");
}); });
test("content", async function (assert) { test("content", async function (assert) {
@ -105,7 +101,10 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
test("onChange action", async function (assert) { test("onChange action", async function (assert) {
this.setProperties(DEFAULT_CONTENT); this.setProperties(DEFAULT_CONTENT);
this.set("onChange", (item) => (query("#test").innerText = item.id)); this.set(
"onChange",
(item) => (document.querySelector("#test").innerText = item.id)
);
await render(hbs` await render(hbs`
<div id="test"></div> <div id="test"></div>
@ -134,7 +133,7 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
assert.dom("#my-dropdown.closed").exists(); assert.dom("#my-dropdown.closed").exists();
assert.dom("#my-dropdown .widget-dropdown-body").doesNotExist(); assert.dom("#my-dropdown .widget-dropdown-body").doesNotExist();
await toggle(); await toggle();
assert.strictEqual(rowById(2).innerText.trim(), "FooBar"); assert.dom(rowById(2)).hasText("FooBar");
assert.dom("#my-dropdown.opened").exists(); assert.dom("#my-dropdown.opened").exists();
assert.dom("#my-dropdown .widget-dropdown-body").exists(); assert.dom("#my-dropdown .widget-dropdown-body").exists();
await toggle(); await toggle();
@ -166,7 +165,7 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
await render(TEMPLATE); await render(TEMPLATE);
await toggle(); await toggle();
assert.strictEqual(rowById(2).innerText.trim(), "FooBar"); assert.dom(rowById(2)).hasText("FooBar");
}); });
test("content with label", async function (assert) { test("content with label", async function (assert) {
@ -176,7 +175,7 @@ module("Integration | Component | Widget | widget-dropdown", function (hooks) {
await render(TEMPLATE); await render(TEMPLATE);
await toggle(); await toggle();
assert.strictEqual(rowById(1).innerText.trim(), "FooBaz"); assert.dom(rowById(1)).hasText("FooBaz");
}); });
test("content with icon", async function (assert) { test("content with icon", async function (assert) {

View File

@ -34,11 +34,7 @@ module("Unit | Utility | category-badge", function (hooks) {
assert assert
.dom(label) .dom(label)
.hasAttribute("title", "cool description", "has the correct title"); .hasAttribute("title", "cool description", "has the correct title");
assert.strictEqual( assert.dom(label.children[0]).hasText("hello", "has the category name");
label.children[0].innerText,
"hello",
"has the category name"
);
}); });
test("undefined color", function (assert) { test("undefined color", function (assert) {

View File

@ -3,8 +3,7 @@ import { module, test } from "qunit";
import highlightSyntax from "discourse/lib/highlight-syntax"; import highlightSyntax from "discourse/lib/highlight-syntax";
import { fixture } from "discourse/tests/helpers/qunit-helpers"; import { fixture } from "discourse/tests/helpers/qunit-helpers";
let siteSettings = { autohighlight_all_code: true }, const siteSettings = { autohighlight_all_code: true };
session = {};
module("Unit | Utility | highlight-syntax", function (hooks) { module("Unit | Utility | highlight-syntax", function (hooks) {
setupTest(hooks); setupTest(hooks);
@ -20,14 +19,9 @@ module("Unit | Utility | highlight-syntax", function (hooks) {
</pre> </pre>
`; `;
await highlightSyntax(fixture(), siteSettings, session); await highlightSyntax(fixture(), siteSettings, {});
assert.strictEqual( assert.dom("code.lang-ruby.hljs .hljs-keyword", fixture()).hasText("def");
document
.querySelector("code.lang-ruby.hljs .hljs-keyword")
.innerText.trim(),
"def"
);
}); });
test("highlighting code with HTML intermingled", async function (assert) { test("highlighting code with HTML intermingled", async function (assert) {
@ -43,19 +37,11 @@ module("Unit | Utility | highlight-syntax", function (hooks) {
</pre> </pre>
`; `;
await highlightSyntax(fixture(), siteSettings, session); await highlightSyntax(fixture(), siteSettings, {});
assert.strictEqual( assert.dom("code.lang-ruby.hljs .hljs-keyword", fixture()).hasText("def");
document
.querySelector("code.lang-ruby.hljs .hljs-keyword")
.innerText.trim(),
"def"
);
// Checks if HTML structure was preserved // Checks if HTML structure was preserved
assert.strictEqual( assert.dom("code.lang-ruby.hljs ol li", fixture()).exists({ count: 3 });
document.querySelectorAll("code.lang-ruby.hljs ol li").length,
3
);
}); });
}); });

View File

@ -38,12 +38,11 @@ module("Unit | Utility | link-mentions", function (hooks) {
`)[0]; `)[0];
await linkSeenMentions(root); await linkSeenMentions(root);
assert.strictEqual(root.querySelector("a").innerText, "@valid_user"); assert.dom(root.querySelectorAll("a")[0]).hasText("@valid_user");
assert.strictEqual(root.querySelectorAll("a")[1].innerText, "@valid_group"); assert.dom(root.querySelectorAll("a")[1]).hasText("@valid_group");
assert.strictEqual( assert
root.querySelector("a[data-mentionable-user-count]").innerText, .dom("a[data-mentionable-user-count]", root)
"@mentionable_group" .hasText("@mentionable_group");
);
assert.dom("span.mention", root).hasHtml("@invalid"); assert.dom("span.mention", root).hasHtml("@invalid");
}); });
}); });

View File

@ -79,13 +79,9 @@ module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
], ],
}); });
channel.chatable.group = true; channel.chatable.group = true;
const users = channel.chatable.users;
await render(<template><ChannelIcon @channel={{channel}} /></template>); await render(<template><ChannelIcon @channel={{channel}} /></template>);
assert.strictEqual( assert.dom(".chat-channel-icon.--users-count").hasText("3");
parseInt(query(".chat-channel-icon.--users-count").innerText.trim(), 10),
users.length
);
}); });
}); });

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import { module, test } from "qunit"; import { module, test } from "qunit";
import CoreFabricators from "discourse/lib/fabricators"; import CoreFabricators from "discourse/lib/fabricators";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChannelName from "discourse/plugins/chat/discourse/components/channel-name"; import ChannelName from "discourse/plugins/chat/discourse/components/channel-name";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators"; import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel"; import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
@ -42,10 +41,7 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
await render(<template><ChannelName @channel={{channel}} /></template>); await render(<template><ChannelName @channel={{channel}} /></template>);
assert.strictEqual( assert.dom(CHANNEL_NAME_LABEL).hasText(user.username);
query(CHANNEL_NAME_LABEL).innerText.trim(),
user.username
);
}); });
test("dm channel - multiple users", async function (assert) { test("dm channel - multiple users", async function (assert) {
@ -61,10 +57,7 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
await render(<template><ChannelName @channel={{channel}} /></template>); await render(<template><ChannelName @channel={{channel}} /></template>);
assert.strictEqual( assert.dom(CHANNEL_NAME_LABEL).hasText(users.mapBy("username").join(", "));
query(CHANNEL_NAME_LABEL).innerText.trim(),
users.mapBy("username").join(", ")
);
}); });
test("dm channel - self", async function (assert) { test("dm channel - self", async function (assert) {
@ -76,10 +69,7 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
await render(<template><ChannelName @channel={{channel}} /></template>); await render(<template><ChannelName @channel={{channel}} /></template>);
assert.strictEqual( assert.dom(CHANNEL_NAME_LABEL).hasText(this.currentUser.username);
query(CHANNEL_NAME_LABEL).innerText.trim(),
this.currentUser.username
);
}); });
test("dm channel - prefers name", async function (assert) { test("dm channel - prefers name", async function (assert) {
@ -99,10 +89,7 @@ module("Discourse Chat | Component | <ChannelName />", function (hooks) {
await render(<template><ChannelName @channel={{channel}} /></template>); await render(<template><ChannelName @channel={{channel}} /></template>);
assert.strictEqual( assert.dom(CHANNEL_NAME_LABEL).hasText(users.mapBy("name").join(", "));
query(CHANNEL_NAME_LABEL).innerText.trim(),
users.mapBy("name").join(", ")
);
}); });
test("unreadIndicator", async function (assert) { test("unreadIndicator", async function (assert) {

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators"; import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module( module(
@ -29,11 +28,9 @@ module(
test("channel title", async function (assert) { test("channel title", async function (assert) {
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`); await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
assert.strictEqual( assert
query(".chat-channel-name__label").innerText, .dom(".chat-channel-name__label")
this.channel.title, .hasText(this.channel.title, "shows the channel title");
"it shows the channel title"
);
assert assert
.dom(".chat-channel-icon.--category-badge") .dom(".chat-channel-icon.--category-badge")
@ -43,11 +40,9 @@ module(
test("channel description", async function (assert) { test("channel description", async function (assert) {
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`); await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
assert.strictEqual( assert
query(".chat-channel-preview-card__description").innerText, .dom(".chat-channel-preview-card__description")
this.channel.description, .hasText(this.channel.description, "the channel description is shown");
"the channel description is shown"
);
}); });
test("no channel description", async function (assert) { test("no channel description", async function (assert) {

View File

@ -2,7 +2,7 @@ import { click, render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import { module, skip, test } from "qunit"; import { module, skip, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
const youtubeCooked = const youtubeCooked =
"<p>written text</p>" + "<p>written text</p>" +
@ -107,21 +107,13 @@ module(
const text = queryAll(".chat-message-collapser p"); const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 3, "shows all written text"); assert.strictEqual(text.length, 3, "shows all written text");
assert.strictEqual( assert.dom(text[0]).hasText("written text", "first line of written text");
text[0].innerText, assert
"written text", .dom(text[1])
"first line of written text" .hasText("more written text", "third line of written text");
); assert
assert.strictEqual( .dom(text[2])
text[1].innerText, .hasText("and even more", "fifth line of written text");
"more written text",
"third line of written text"
);
assert.strictEqual(
text[2].innerText,
"and even more",
"fifth line of written text"
);
}); });
test("collapses and expands cooked youtube", async function (assert) { test("collapses and expands cooked youtube", async function (assert) {
@ -188,11 +180,9 @@ module(
hbs`<ChatMessageCollapser @cooked={{this.cooked}} @uploads={{this.uploads}} />` hbs`<ChatMessageCollapser @cooked={{this.cooked}} @uploads={{this.uploads}} />`
); );
assert.true( assert
query(".chat-message-collapser-link-small").innerText.includes( .dom(".chat-message-collapser-link-small")
"tomtom.jpeg" .includesText("tomtom.jpeg");
)
);
}); });
test("shows number of files for multiple images", async function (assert) { test("shows number of files for multiple images", async function (assert) {
@ -203,11 +193,7 @@ module(
hbs`<ChatMessageCollapser @cooked={{this.cooked}} @uploads={{this.uploads}} />` hbs`<ChatMessageCollapser @cooked={{this.cooked}} @uploads={{this.uploads}} />`
); );
assert.true( assert.dom(".chat-message-collapser-link-small").includesText("2 files");
query(".chat-message-collapser-link-small").innerText.includes(
"2 files"
)
);
}); });
test("collapses and expands images", async function (assert) { test("collapses and expands images", async function (assert) {
@ -251,12 +237,10 @@ module(
const links = queryAll("a.chat-message-collapser-link-small"); const links = queryAll("a.chat-message-collapser-link-small");
assert.true(links[0].innerText.trim().includes("avatar.png")); assert.dom(links[0]).includesText("avatar.png");
assert.dom(links[0]).hasAttribute("href", "/images/avatar.png"); assert.dom(links[0]).hasAttribute("href", "/images/avatar.png");
assert.true( assert.dom(links[1]).includesText("d-logo-sketch-small.png");
links[1].innerText.trim().includes("d-logo-sketch-small.png")
);
assert assert
.dom(links[1]) .dom(links[1])
.hasAttribute("href", "/images/d-logo-sketch-small.png"); .hasAttribute("href", "/images/d-logo-sketch-small.png");
@ -270,9 +254,9 @@ module(
const text = queryAll(".chat-message-collapser p"); const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 5, "shows all written text"); assert.strictEqual(text.length, 5, "shows all written text");
assert.strictEqual(text[0].innerText, "written text"); assert.dom(text[0]).hasText("written text");
assert.strictEqual(text[2].innerText, "more written text"); assert.dom(text[2]).hasText("more written text");
assert.strictEqual(text[4].innerText, "and even more"); assert.dom(text[4]).hasText("and even more");
}); });
test("collapses and expands animated image onebox", async function (assert) { test("collapses and expands animated image onebox", async function (assert) {
@ -325,10 +309,10 @@ module(
const links = queryAll("a.chat-message-collapser-link-small"); const links = queryAll("a.chat-message-collapser-link-small");
assert.true(links[0].innerText.trim().includes("http://cat1.com")); assert.dom(links[0]).includesText("http://cat1.com");
assert.dom(links[0]).hasAttribute("href", "http://cat1.com/"); assert.dom(links[0]).hasAttribute("href", "http://cat1.com/");
assert.true(links[1].innerText.trim().includes("http://cat2.com")); assert.dom(links[1]).includesText("http://cat2.com");
assert.dom(links[1]).hasAttribute("href", "http://cat2.com/"); assert.dom(links[1]).hasAttribute("href", "http://cat2.com/");
}); });
@ -340,9 +324,9 @@ module(
const text = queryAll(".chat-message-collapser p"); const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 5, "shows all written text"); assert.strictEqual(text.length, 5, "shows all written text");
assert.strictEqual(text[0].innerText, "written text"); assert.dom(text[0]).hasText("written text");
assert.strictEqual(text[2].innerText, "more written text"); assert.dom(text[2]).hasText("more written text");
assert.strictEqual(text[4].innerText, "and even more"); assert.dom(text[4]).hasText("and even more");
}); });
test("collapses and expands image oneboxes", async function (assert) { test("collapses and expands image oneboxes", async function (assert) {
@ -414,12 +398,10 @@ module(
const links = queryAll("a.chat-message-collapser-link-small"); const links = queryAll("a.chat-message-collapser-link-small");
assert.true(links[0].innerText.trim().includes("shows alt")); assert.dom(links[0]).includesText("shows alt");
assert.dom(links[0]).hasAttribute("href", "/images/avatar.png"); assert.dom(links[0]).hasAttribute("href", "/images/avatar.png");
assert.true( assert.dom(links[1]).includesText("/images/d-logo-sketch-small.png");
links[1].innerText.trim().includes("/images/d-logo-sketch-small.png")
);
assert assert
.dom(links[1]) .dom(links[1])
.hasAttribute("href", "/images/d-logo-sketch-small.png"); .hasAttribute("href", "/images/d-logo-sketch-small.png");
@ -433,9 +415,9 @@ module(
const text = queryAll(".chat-message-collapser p"); const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 6, "shows all written text"); assert.strictEqual(text.length, 6, "shows all written text");
assert.strictEqual(text[0].innerText, "written text"); assert.dom(text[0]).hasText("written text");
assert.strictEqual(text[2].innerText, "more written text"); assert.dom(text[2]).hasText("more written text");
assert.strictEqual(text[4].innerText, "and even more"); assert.dom(text[4]).hasText("and even more");
}); });
test("collapses and expands images", async function (assert) { test("collapses and expands images", async function (assert) {
@ -523,11 +505,9 @@ module(
await render(hbs`<ChatMessageCollapser @cooked={{this.cooked}} />`); await render(hbs`<ChatMessageCollapser @cooked={{this.cooked}} />`);
assert.true( assert
query(".chat-message-collapser-link-small").innerText.includes( .dom(".chat-message-collapser-link-small")
"Le tomtom album" .includesText("Le tomtom album");
)
);
}); });
test("shows all user written text", async function (assert) { test("shows all user written text", async function (assert) {
@ -538,8 +518,8 @@ module(
const text = queryAll(".chat-message-collapser p"); const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 2, "shows all written text"); assert.strictEqual(text.length, 2, "shows all written text");
assert.strictEqual(text[0].innerText, "written text"); assert.dom(text[0]).hasText("written text");
assert.strictEqual(text[1].innerText, "more written text"); assert.dom(text[1]).hasText("more written text");
}); });
test("collapses and expands images", async function (assert) { test("collapses and expands images", async function (assert) {

View File

@ -5,7 +5,7 @@ import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender from "discourse/tests/helpers/create-pretender"; import pretender from "discourse/tests/helpers/create-pretender";
import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from 'discourse-i18n'; import { i18n } from "discourse-i18n";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators"; import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-notice", function (hooks) { module("Discourse Chat | Component | chat-notice", function (hooks) {
@ -35,8 +35,8 @@ module("Discourse Chat | Component | chat-notice", function (hooks) {
assert.strictEqual(notices.length, 2, "Two notices are rendered"); assert.strictEqual(notices.length, 2, "Two notices are rendered");
assert.true(notices[0].innerText.includes("hello")); assert.dom(notices[0]).includesText("hello");
assert.true(notices[1].innerText.includes("goodbye")); assert.dom(notices[1]).includesText("goodbye");
}); });
test("Notices can be cleared", async function (assert) { test("Notices can be cleared", async function (assert) {

View File

@ -7,7 +7,6 @@ import {
joinChannel, joinChannel,
leaveChannel, leaveChannel,
} from "discourse/tests/helpers/presence-pretender"; } from "discourse/tests/helpers/presence-pretender";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators"; import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
async function addUser(id, username, channelName = "/chat-reply/1") { async function addUser(id, username, channelName = "/chat-reply/1") {
@ -44,10 +43,7 @@ module(
await addUser(1, "sam", "/chat-reply/1/thread/1"); await addUser(1, "sam", "/chat-reply/1/thread/1");
assert.strictEqual( assert.dom(".chat-replying-indicator__text").hasText("sam is typing");
query(".chat-replying-indicator__text").innerText,
"sam is typing"
);
}); });
test("doesnt leak in other indicators", async function (assert) { test("doesnt leak in other indicators", async function (assert) {
@ -81,10 +77,7 @@ module(
await addUser(1, "sam"); await addUser(1, "sam");
assert.strictEqual( assert.dom(".chat-replying-indicator__text").hasText("sam is typing");
query(".chat-replying-indicator__text").innerText,
`sam is typing`
);
}); });
test("displays indicator when 2 or 3 users are replying", async function (assert) { test("displays indicator when 2 or 3 users are replying", async function (assert) {

View File

@ -2,11 +2,6 @@ import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile"; import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
function displayName() {
return query(".chat-user-display-name").innerText.trim();
}
module( module(
"Discourse Chat | Component | chat-user-display-name | prioritize username in UX", "Discourse Chat | Component | chat-user-display-name | prioritize username in UX",
@ -19,7 +14,7 @@ module(
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`); await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
assert.strictEqual(displayName(), "bob"); assert.dom(".chat-user-display-name").hasText("bob");
}); });
test("username and name", async function (assert) { test("username and name", async function (assert) {
@ -28,7 +23,7 @@ module(
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`); await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
assert.strictEqual(displayName(), "bob Bobcat"); assert.dom(".chat-user-display-name").hasText("bob Bobcat");
}); });
} }
); );
@ -44,7 +39,7 @@ module(
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`); await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
assert.strictEqual(displayName(), "bob"); assert.dom(".chat-user-display-name").hasText("bob");
}); });
test("name and username", async function (assert) { test("name and username", async function (assert) {
@ -53,7 +48,7 @@ module(
await render(hbs`<ChatUserDisplayName @user={{this.user}} />`); await render(hbs`<ChatUserDisplayName @user={{this.user}} />`);
assert.strictEqual(displayName(), "Bobcat bob"); assert.dom(".chat-user-display-name").hasText("Bobcat bob");
}); });
} }
); );

View File

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

View File

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