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 { 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";
function assertNoSecondary(assert) {
assert.strictEqual(
query(".display-row.email .value a").innerText,
"eviltrout@example.com",
"it should display the primary email"
);
assert
.dom(".display-row.email .value a")
.hasText("eviltrout@example.com", "displays the primary email");
assert.strictEqual(
query(".display-row.secondary-emails .value").innerText.trim(),
assert
.dom(".display-row.secondary-emails .value")
.hasText(
i18n("user.email.no_secondary"),
"it should not display secondary emails"
"does not display secondary emails"
);
}
function assertMultipleSecondary(assert, firstEmail, secondEmail) {
assert.strictEqual(
query(".display-row.secondary-emails .value li:first-of-type a").innerText,
firstEmail,
"it should display the first secondary email"
);
assert
.dom(".display-row.secondary-emails .value li:first-of-type a")
.hasText(firstEmail, "displays the first secondary email");
assert.strictEqual(
query(".display-row.secondary-emails .value li:last-of-type a").innerText,
secondEmail,
"it should display the second secondary email"
);
assert
.dom(".display-row.secondary-emails .value li:last-of-type a")
.hasText(secondEmail, "displays the second secondary email");
}
acceptance("Admin - User Emails", function (needs) {
@ -45,10 +40,7 @@ acceptance("Admin - User Emails", function (needs) {
assert
.dom(".display-row.email .value a")
.hasText(
"markvanlan@example.com",
"it should display the user's primary email"
);
.hasText("markvanlan@example.com", "displays the user's primary email");
assertMultipleSecondary(
assert,

View File

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

View File

@ -14,10 +14,7 @@ acceptance("Category Edit - Security", function (needs) {
test("default", async function (assert) {
await visit("/c/bug/edit/security");
const firstRow = query(".row-body");
const badgeName = firstRow.querySelector(".group-name-label").innerText;
assert.strictEqual(badgeName, "everyone");
assert.dom(".row-body .group-name-label").hasText("everyone");
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);
assert.strictEqual(
addedRow.querySelector(".group-name-link").innerText,
"staff"
);
assert.dom(".group-name-link", addedRow).hasText("staff");
assert.strictEqual(
addedRow.querySelectorAll(".d-icon-square-check").length,
3,
@ -85,10 +79,7 @@ acceptance("Category Edit - Security", function (needs) {
const firstRow = query(".row-body");
assert.strictEqual(
firstRow.querySelector(".group-name-label").innerText,
"everyone"
);
assert.dom(".group-name-label", firstRow).hasText("everyone");
assert.strictEqual(
firstRow.querySelectorAll(".d-icon-square-check").length,
1,

View File

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

View File

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

View File

@ -111,18 +111,16 @@ acceptance(
await formKit().submit();
await click(".group-manage-save");
assert.strictEqual(
query(".group-manage-save-button > span").innerText,
"Saved!"
);
assert.dom(".group-manage-save-button > span").hasText("Saved!");
assert
.dom("#enable_imap")
.isEnabled("IMAP is able to be enabled now that SMTP is saved");
await click("#enable_smtp");
assert.strictEqual(
query(".dialog-body").innerText.trim(),
assert
.dom(".dialog-body")
.hasText(
i18n("groups.manage.email.smtp_disable_confirm"),
"shows a confirm dialogue warning SMTP settings will be wiped"
);
@ -172,10 +170,7 @@ acceptance(
await click(".group-manage-save");
assert.strictEqual(
query(".group-manage-save-button > span").innerText,
"Saved!"
);
assert.dom(".group-manage-save-button > span").hasText("Saved!");
assert
.dom(".imap-no-mailbox-selected")
@ -194,8 +189,9 @@ acceptance(
.doesNotExist("no longer shows a no mailbox selected message");
await click("#enable_imap");
assert.strictEqual(
query(".dialog-body").innerText.trim(),
assert
.dom(".dialog-body")
.hasText(
i18n("groups.manage.email.imap_disable_confirm"),
"shows a confirm dialogue warning IMAP settings will be wiped"
);
@ -349,8 +345,7 @@ acceptance(
await formKit().field("email_password").fillIn("password");
await formKit().submit();
assert.strictEqual(
query(".dialog-body").innerText.trim(),
assert.dom(".dialog-body").hasText(
i18n("generic_error_with_reason", {
error:
"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 { 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";
acceptance("New Group - Anonymous", function () {
@ -69,12 +69,11 @@ acceptance("New Group - Authenticated", function (needs) {
.dom("groups-new-allow-membership-requests")
.doesNotExist("it should disable the membership requests checkbox");
assert.strictEqual(
query(
".groups-form-default-notification-level .selected-name .name"
).innerText.trim(),
assert
.dom(".groups-form-default-notification-level .selected-name .name")
.hasText(
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,
loggedInUser,
publishToMessageBus,
query,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { i18n } from "discourse-i18n";
@ -133,20 +132,10 @@ acceptance("Review", function (needs) {
assert.dom(`${topic} .reviewable-action.approve`).exists();
assert.dom(`${topic} .badge-category__name`).doesNotExist();
assert.strictEqual(
query(`${topic} .discourse-tag:nth-of-type(1)`).innerText,
"hello"
);
assert.dom(`${topic} .discourse-tag:nth-of-type(1)`).hasText("hello");
assert.dom(`${topic} .discourse-tag:nth-of-type(2)`).hasText("world");
assert.strictEqual(
query(`${topic} .discourse-tag:nth-of-type(2)`).innerText,
"world"
);
assert.strictEqual(
query(`${topic} .post-body`).innerText.trim(),
"existing body"
);
assert.dom(`${topic} .post-body`).hasText("existing body");
await click(`${topic} .reviewable-action.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 click(`${topic} .reviewable-action.cancel-edit`);
assert.strictEqual(
query(`${topic} .post-body`).innerText.trim(),
"existing body",
"cancelling does not update the value"
);
assert
.dom(`${topic} .post-body`)
.hasText("existing body", "cancelling does not update the value");
await click(`${topic} .reviewable-action.edit`);
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 click(`${topic} .reviewable-action.save-edit`);
assert.strictEqual(
query(`${topic} .discourse-tag:nth-of-type(1)`).innerText,
"hello"
);
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.dom(`${topic} .discourse-tag:nth-of-type(1)`).hasText("hello");
assert.dom(`${topic} .discourse-tag:nth-of-type(2)`).hasText("world");
assert.dom(`${topic} .discourse-tag:nth-of-type(3)`).hasText("monkey");
assert.strictEqual(
query(`${topic} .post-body`).innerText.trim(),
"new raw contents"
);
assert.strictEqual(
query(`${topic} .badge-category__name`).innerText.trim(),
"support"
);
assert.dom(`${topic} .post-body`).hasText("new raw contents");
assert.dom(`${topic} .badge-category__name`).hasText("support");
});
test("Reviewables can become stale", async function (assert) {

View File

@ -119,18 +119,17 @@ acceptance("Search - Anonymous", function (needs) {
await click("#search-button");
await fillIn("#search-term", "dev");
assert.strictEqual(
query(
assert
.dom(
".search-menu .results ul.search-menu-initial-options li:first-child .search-item-prefix"
).innerText.trim(),
"dev",
"first dropdown item includes correct prefix"
);
)
.hasText("dev", "first dropdown item includes correct prefix");
assert.strictEqual(
query(
assert
.dom(
".search-menu .results ul.search-menu-initial-options li:first-child .search-item-slug"
).innerText.trim(),
)
.hasText(
i18n("search.in_topics_posts"),
"first dropdown item includes correct suffix"
);
@ -866,20 +865,15 @@ acceptance("Search - with tagging enabled", function (needs) {
await visit("/tags/c/bug/dev");
await click("#search-button");
assert.strictEqual(
query(
assert
.dom(
".search-menu .results ul.search-menu-assistant .badge-category__name"
).innerText,
"bug",
"Category is displayed"
);
)
.hasText("bug", "Category is displayed");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"dev",
"Tag is displayed"
);
assert
.dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.hasText("dev", "Tag is displayed");
});
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 fillIn("#search-term", "foo bar");
assert.strictEqual(
query(
".search-menu .results ul.search-menu-assistant .search-item-prefix"
).innerText,
"foo bar",
"Input is applied to search query"
);
assert
.dom(".search-menu .results ul.search-menu-assistant .search-item-prefix")
.hasText("foo bar", "Input is applied to search query");
assert.strictEqual(
query(
assert
.dom(
".search-menu .results ul.search-menu-assistant .badge-category__name"
).innerText,
"bug"
);
)
.hasText("bug");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"dev",
"Tag is displayed"
);
assert
.dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.hasText("dev", "Tag is displayed");
});
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 click("#search-button");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"tags:dev+foo",
"Tags are displayed"
);
assert
.dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.hasText("tags:dev+foo", "Tags are displayed");
});
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 fillIn("#search-term", "foo bar");
assert.strictEqual(
query(
".search-menu .results ul.search-menu-assistant .search-item-prefix"
).innerText,
"foo bar",
"Input is applied to search query"
);
assert
.dom(".search-menu .results ul.search-menu-assistant .search-item-prefix")
.hasText("foo bar", "Input is applied to search query");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"tags:dev+foo",
"Tags are displayed"
);
assert
.dom(".search-menu .results ul.search-menu-assistant .search-item-tag")
.hasText("tags:dev+foo", "Tags are displayed");
});
});
@ -1135,38 +1111,31 @@ acceptance("Search - assistant", function (needs) {
await click("#search-button");
await fillIn("#search-term", "#");
assert.strictEqual(
query(
assert
.dom(
".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) {
await visit("/");
await click("#search-button");
const firstTarget =
".search-menu .results ul.search-menu-assistant .search-link ";
".search-menu .results ul.search-menu-assistant .search-link";
await fillIn("#search-term", "in:");
assert.strictEqual(
query(firstTarget.concat(".search-item-slug")).innerText,
"in:title",
"keyword is present in suggestion"
);
assert
.dom(`${firstTarget} .search-item-slug`)
.hasText("in:title", "keyword is present in suggestion");
await fillIn("#search-term", "sam in:");
assert.strictEqual(
query(firstTarget.concat(".search-item-prefix")).innerText,
"sam",
"term is present in suggestion"
);
assert.strictEqual(
query(firstTarget.concat(".search-item-slug")).innerText,
"in:title",
"keyword is present in suggestion"
);
assert
.dom(`${firstTarget} .search-item-prefix`)
.hasText("sam", "term is present in suggestion");
assert
.dom(`${firstTarget} .search-item-slug`)
.hasText("in:title", "keyword is present in suggestion");
await fillIn("#search-term", "in:mess");
assert.dom(firstTarget).hasText("in:messages");
@ -1176,13 +1145,22 @@ acceptance("Search - assistant", function (needs) {
await visit("/");
await click("#search-button");
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"
);
const username = firstUser.querySelector(".username").innerText.trim();
assert.strictEqual(username, "TeaMoe");
await click(firstUser);
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");
});
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 click("#search-button");
await fillIn("#search-term", "sam #");
const firstCategory =
".search-menu .results ul.search-menu-assistant .search-link";
const firstCategoryName = query(
const firstCategoryName = document.querySelector(
`${firstCategory} .badge-category__name`
).innerText;
await click(firstCategory);
await click(`${firstCategory} .badge-category__name`);
assert.strictEqual(
query("#search-term").value,

View File

@ -5,7 +5,6 @@ import {
acceptance,
fakeTime,
loggedInUser,
query,
queryAll,
updateCurrentUser,
} 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");
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
// plain text version of a translation with HTML
let el = document.createElement("p");
@ -172,7 +167,9 @@ acceptance("Topic - Edit timer", function (needs) {
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) {
@ -196,10 +193,6 @@ acceptance("Topic - Edit timer", function (needs) {
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
// plain text version of a translation with HTML
let el = document.createElement("p");
@ -209,7 +202,9 @@ acceptance("Topic - Edit timer", function (needs) {
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) {
@ -237,10 +232,6 @@ acceptance("Topic - Edit timer", function (needs) {
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
// plain text version of a translation with HTML
let el = document.createElement("p");
@ -250,7 +241,9 @@ acceptance("Topic - Edit timer", function (needs) {
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) {

View File

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

View File

@ -2,7 +2,6 @@ import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
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) {
await visit("/u/eviltrout/preferences/security");
assert.strictEqual(
query(
".auth-tokens > .auth-token:nth-of-type(1) .auth-token-device"
).innerText.trim(),
"Linux Computer",
"it should display active token first"
);
assert
.dom(".auth-tokens > .auth-token:nth-of-type(1) .auth-token-device")
.hasText("Linux Computer", "displays active token first");
assert
.dom(".pref-auth-tokens > a:nth-of-type(1)")

View File

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

View File

@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit";
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";
module(
@ -63,11 +63,9 @@ module(
.dom(".form-template-field__dropdown")
.exists("a dropdown component exists");
assert.strictEqual(
query(".form-template-field__dropdown-placeholder").innerText,
attributes.none_label,
"None label is correct"
);
assert
.dom(".form-template-field__dropdown-placeholder")
.hasText(attributes.none_label, "None label is correct");
});
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 { module, test } from "qunit";
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";
module(
@ -64,11 +64,9 @@ module(
.dom(".form-template-field__multi-select")
.exists("a multiselect dropdown component exists");
assert.strictEqual(
query(".form-template-field__multi-select-placeholder").innerText,
attributes.none_label,
"None label is correct"
);
assert
.dom(".form-template-field__multi-select-placeholder")
.hasText(attributes.none_label, "None label is correct");
});
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 { withPluginApi } from "discourse/lib/plugin-api";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import selectKit, {
DEFAULT_CONTENT,
setDefaultState,
@ -89,7 +88,7 @@ module("Integration | Component | select-kit/api", function (hooks) {
withPluginApi("0.8.43", (api) => {
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();
assert.strictEqual(
this.subject.rowByIndex(0).el().querySelector(".category-desc")
.innerText,
'baz "bar foo'
);
assert
.dom(".category-desc", this.subject.rowByIndex(0).el())
.hasText('baz "bar foo');
});
}
);

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
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}} />`);
assert.deepEqual(
query(".components")
.innerText.trim()
.split(",")
.map((n) => n.trim())
.join(","),
this.childrenList
.splice(0, 4)
.map((theme) => theme.get("name"))
.join(","),
document
.querySelector(".components")
.innerText.split(",")
.map((n) => n.trim()),
this.childrenList.splice(0, 4).map((theme) => theme.get("name")),
"lists the first 4 children"
);
assert.deepEqual(
query(".others-count").innerText.trim(),
assert
.dom(".others-count")
.hasText(
i18n("admin.customize.theme.and_x_more", { count: 1 }),
"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 { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import {
fakeTime,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { fakeTime, queryAll } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
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")
.hasText("Next Monday");
assert.strictEqual(
query("div#tap_tile_start_of_next_business_week div.tap-tile-date")
.innerText,
"Feb 1, 8:00 am"
);
assert
.dom("div#tap_tile_start_of_next_business_week div.tap-tile-date")
.hasText("Feb 1, 8:00 am");
});
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")
.hasText("Next Monday");
assert.strictEqual(
query("div#tap_tile_start_of_next_business_week div.tap-tile-date")
.innerText,
"Feb 1, 8:00 am"
);
assert
.dom("div#tap_tile_start_of_next_business_week div.tap-tile-date")
.hasText("Feb 1, 8:00 am");
});
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 { module, test } from "qunit";
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";
module(
@ -721,8 +721,7 @@ module(
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
assert.strictEqual(
query(".post-notice.returning-user:not(.old)").innerText.trim(),
assert.dom(".post-notice.returning-user:not(.old)").hasText(
i18n("post.notice.returning_user", {
user: "codinghorror",
time: "2 days ago",
@ -744,8 +743,9 @@ module(
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
assert.strictEqual(
query(".post-notice.old.new-user").innerText.trim(),
assert
.dom(".post-notice.old.new-user")
.hasText(
i18n("post.notice.new_user", { user: "Jeff", time: "Jan '10" })
);
});
@ -759,12 +759,10 @@ module(
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
const link = query(".group-request a");
assert.strictEqual(link.innerText.trim(), i18n("groups.requests.handle"));
assert.strictEqual(
link.getAttribute("href"),
"/g/testGroup/requests?filter=foo"
);
assert.dom(".group-request a").hasText(i18n("groups.requests.handle"));
assert
.dom(".group-request a")
.hasAttribute("href", "/g/testGroup/requests?filter=foo");
});
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 { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
module("Integration | Component | Widget | post", function (hooks) {
@ -1155,8 +1154,7 @@ module("Integration | Component | Widget | post", function (hooks) {
await render(hbs`
<MountWidget @widget="post" @args={{this.args}} />`);
const link = query(".group-request a");
assert.strictEqual(link.innerText.trim(), i18n("groups.requests.handle"));
assert.dom(".group-request a").hasText(i18n("groups.requests.handle"));
assert
.dom(".group-request a")
.hasAttribute("href", "/g/testGroup/requests?filter=foo");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,6 @@ import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import CoreFabricators from "discourse/lib/fabricators";
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 ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
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>);
assert.strictEqual(
query(CHANNEL_NAME_LABEL).innerText.trim(),
user.username
);
assert.dom(CHANNEL_NAME_LABEL).hasText(user.username);
});
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>);
assert.strictEqual(
query(CHANNEL_NAME_LABEL).innerText.trim(),
users.mapBy("username").join(", ")
);
assert.dom(CHANNEL_NAME_LABEL).hasText(users.mapBy("username").join(", "));
});
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>);
assert.strictEqual(
query(CHANNEL_NAME_LABEL).innerText.trim(),
this.currentUser.username
);
assert.dom(CHANNEL_NAME_LABEL).hasText(this.currentUser.username);
});
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>);
assert.strictEqual(
query(CHANNEL_NAME_LABEL).innerText.trim(),
users.mapBy("name").join(", ")
);
assert.dom(CHANNEL_NAME_LABEL).hasText(users.mapBy("name").join(", "));
});
test("unreadIndicator", async function (assert) {

View File

@ -3,7 +3,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 { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module(
@ -29,11 +28,9 @@ module(
test("channel title", async function (assert) {
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
assert.strictEqual(
query(".chat-channel-name__label").innerText,
this.channel.title,
"it shows the channel title"
);
assert
.dom(".chat-channel-name__label")
.hasText(this.channel.title, "shows the channel title");
assert
.dom(".chat-channel-icon.--category-badge")
@ -43,11 +40,9 @@ module(
test("channel description", async function (assert) {
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
assert.strictEqual(
query(".chat-channel-preview-card__description").innerText,
this.channel.description,
"the channel description is shown"
);
assert
.dom(".chat-channel-preview-card__description")
.hasText(this.channel.description, "the channel description is shown");
});
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 { module, skip, test } from "qunit";
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 =
"<p>written text</p>" +
@ -107,21 +107,13 @@ module(
const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 3, "shows all written text");
assert.strictEqual(
text[0].innerText,
"written text",
"first line of written text"
);
assert.strictEqual(
text[1].innerText,
"more written text",
"third line of written text"
);
assert.strictEqual(
text[2].innerText,
"and even more",
"fifth line of written text"
);
assert.dom(text[0]).hasText("written text", "first line of written text");
assert
.dom(text[1])
.hasText("more written text", "third line of written text");
assert
.dom(text[2])
.hasText("and even more", "fifth line of written text");
});
test("collapses and expands cooked youtube", async function (assert) {
@ -188,11 +180,9 @@ module(
hbs`<ChatMessageCollapser @cooked={{this.cooked}} @uploads={{this.uploads}} />`
);
assert.true(
query(".chat-message-collapser-link-small").innerText.includes(
"tomtom.jpeg"
)
);
assert
.dom(".chat-message-collapser-link-small")
.includesText("tomtom.jpeg");
});
test("shows number of files for multiple images", async function (assert) {
@ -203,11 +193,7 @@ module(
hbs`<ChatMessageCollapser @cooked={{this.cooked}} @uploads={{this.uploads}} />`
);
assert.true(
query(".chat-message-collapser-link-small").innerText.includes(
"2 files"
)
);
assert.dom(".chat-message-collapser-link-small").includesText("2 files");
});
test("collapses and expands images", async function (assert) {
@ -251,12 +237,10 @@ module(
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.true(
links[1].innerText.trim().includes("d-logo-sketch-small.png")
);
assert.dom(links[1]).includesText("d-logo-sketch-small.png");
assert
.dom(links[1])
.hasAttribute("href", "/images/d-logo-sketch-small.png");
@ -270,9 +254,9 @@ module(
const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 5, "shows all written text");
assert.strictEqual(text[0].innerText, "written text");
assert.strictEqual(text[2].innerText, "more written text");
assert.strictEqual(text[4].innerText, "and even more");
assert.dom(text[0]).hasText("written text");
assert.dom(text[2]).hasText("more written text");
assert.dom(text[4]).hasText("and even more");
});
test("collapses and expands animated image onebox", async function (assert) {
@ -325,10 +309,10 @@ module(
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.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/");
});
@ -340,9 +324,9 @@ module(
const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 5, "shows all written text");
assert.strictEqual(text[0].innerText, "written text");
assert.strictEqual(text[2].innerText, "more written text");
assert.strictEqual(text[4].innerText, "and even more");
assert.dom(text[0]).hasText("written text");
assert.dom(text[2]).hasText("more written text");
assert.dom(text[4]).hasText("and even more");
});
test("collapses and expands image oneboxes", async function (assert) {
@ -414,12 +398,10 @@ module(
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.true(
links[1].innerText.trim().includes("/images/d-logo-sketch-small.png")
);
assert.dom(links[1]).includesText("/images/d-logo-sketch-small.png");
assert
.dom(links[1])
.hasAttribute("href", "/images/d-logo-sketch-small.png");
@ -433,9 +415,9 @@ module(
const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 6, "shows all written text");
assert.strictEqual(text[0].innerText, "written text");
assert.strictEqual(text[2].innerText, "more written text");
assert.strictEqual(text[4].innerText, "and even more");
assert.dom(text[0]).hasText("written text");
assert.dom(text[2]).hasText("more written text");
assert.dom(text[4]).hasText("and even more");
});
test("collapses and expands images", async function (assert) {
@ -523,11 +505,9 @@ module(
await render(hbs`<ChatMessageCollapser @cooked={{this.cooked}} />`);
assert.true(
query(".chat-message-collapser-link-small").innerText.includes(
"Le tomtom album"
)
);
assert
.dom(".chat-message-collapser-link-small")
.includesText("Le tomtom album");
});
test("shows all user written text", async function (assert) {
@ -538,8 +518,8 @@ module(
const text = queryAll(".chat-message-collapser p");
assert.strictEqual(text.length, 2, "shows all written text");
assert.strictEqual(text[0].innerText, "written text");
assert.strictEqual(text[1].innerText, "more written text");
assert.dom(text[0]).hasText("written text");
assert.dom(text[1]).hasText("more written text");
});
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 pretender from "discourse/tests/helpers/create-pretender";
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";
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.true(notices[0].innerText.includes("hello"));
assert.true(notices[1].innerText.includes("goodbye"));
assert.dom(notices[0]).includesText("hello");
assert.dom(notices[1]).includesText("goodbye");
});
test("Notices can be cleared", async function (assert) {

View File

@ -7,7 +7,6 @@ import {
joinChannel,
leaveChannel,
} from "discourse/tests/helpers/presence-pretender";
import { query } from "discourse/tests/helpers/qunit-helpers";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
async function addUser(id, username, channelName = "/chat-reply/1") {
@ -44,10 +43,7 @@ module(
await addUser(1, "sam", "/chat-reply/1/thread/1");
assert.strictEqual(
query(".chat-replying-indicator__text").innerText,
"sam is typing"
);
assert.dom(".chat-replying-indicator__text").hasText("sam is typing");
});
test("doesnt leak in other indicators", async function (assert) {
@ -81,10 +77,7 @@ module(
await addUser(1, "sam");
assert.strictEqual(
query(".chat-replying-indicator__text").innerText,
`sam is typing`
);
assert.dom(".chat-replying-indicator__text").hasText("sam is typing");
});
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 { module, test } from "qunit";
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(
"Discourse Chat | Component | chat-user-display-name | prioritize username in UX",
@ -19,7 +14,7 @@ module(
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) {
@ -28,7 +23,7 @@ module(
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}} />`);
assert.strictEqual(displayName(), "bob");
assert.dom(".chat-user-display-name").hasText("bob");
});
test("name and username", async function (assert) {
@ -53,7 +48,7 @@ module(
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 {
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) {