From efa2589204fadd731278e516ed0d6ed76c3e534b Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sun, 1 Dec 2024 14:00:48 +0100 Subject: [PATCH] DEV: Finish qunit-dom hasText migration (#30017) --- .../acceptance/admin-badges-award-test.js | 14 +- .../admin-install-theme-modal-test.js | 15 +- .../tests/acceptance/admin-user-index-test.js | 14 +- .../acceptance/admin-watched-words-test.js | 12 +- .../acceptance/category-edit-security-test.js | 134 +++++----- .../tests/acceptance/category-edit-test.js | 8 +- .../tests/acceptance/composer-actions-test.js | 56 ++-- .../acceptance/composer-hyperlink-test.js | 4 +- .../acceptance/composer-uploads-uppy-test.js | 32 +-- .../tests/acceptance/do-not-disturb-test.js | 12 +- .../edit-notification-click-test.js | 22 +- .../discourse/tests/acceptance/group-test.js | 5 +- .../discourse/tests/acceptance/search-test.js | 173 +++++------- ...debar-anonymous-categories-section-test.js | 66 +---- ...idebar-anonymous-community-section-test.js | 72 ++--- .../sidebar-user-categories-section-test.js | 96 ++++--- .../sidebar-user-community-section-test.js | 139 +++++----- .../sidebar-user-messages-section-test.js | 112 ++++---- .../sidebar-user-tags-section-test.js | 103 ++++--- .../topic-discovery-tracked-test.js | 155 ++++++----- .../discourse/tests/acceptance/topic-test.js | 10 +- .../acceptance/user-drafts-stream-test.js | 5 +- .../tests/acceptance/user-menu-test.js | 253 +++++++----------- .../user-preferences-account-test.js | 10 +- .../acceptance/user-private-messages-test.js | 17 +- .../discourse/tests/acceptance/user-test.js | 7 +- .../discourse/tests/acceptance/users-test.js | 46 +--- .../admin-plugin-config-area-test.js | 35 ++- .../components/d-navigation-test.js | 6 +- .../components/pending-post-test.js | 7 +- .../components/search-menu-test.gjs | 11 +- .../select-kit/mini-tag-chooser-test.js | 5 +- .../user-menu/bookmarks-list-test.js | 21 +- .../components/user-menu/likes-list-test.js | 15 +- .../components/user-menu/menu-item-test.js | 135 ++++------ .../components/user-menu/menu-test.js | 21 +- .../user-menu/messages-list-test.js | 34 +-- .../user-menu/notifications-list-test.js | 63 +++-- .../other-notifications-list-test.js | 12 +- .../replies-notifications-list-test.js | 12 +- .../tests/unit/utils/decorators-test.js | 32 +-- .../components/chat-channel-card-test.js | 17 +- .../components/chat-message-info-test.js | 8 +- .../user-menu/chat-notifications-list-test.js | 10 +- .../component/poll-buttons-dropdown-test.js | 24 +- .../javascripts/component/poll-info-test.js | 44 ++- .../poll-results-ranked-choice-test.js | 6 +- 47 files changed, 922 insertions(+), 1188 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-badges-award-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-badges-award-test.js index 18bae12f2f6..9be7b626e4e 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/admin-badges-award-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/admin-badges-award-test.js @@ -1,20 +1,22 @@ 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"; acceptance("Admin - Badges - Mass Award", function (needs) { needs.user(); + test("when the badge can be granted multiple times", async function (assert) { await visit("/admin/badges/award/new"); await click( '.admin-badge-list-item span[data-badge-name="Both image and icon"]' ); - assert.strictEqual( - query("label.grant-existing-holders").textContent.trim(), - i18n("admin.badges.mass_award.grant_existing_holders"), - "checkbox for granting existing holders is displayed" - ); + assert + .dom("label.grant-existing-holders") + .hasText( + i18n("admin.badges.mass_award.grant_existing_holders"), + "checkbox for granting existing holders is displayed" + ); }); test("when the badge can not be granted multiple times", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js index 8c9c694b366..2c8aa0f5c89 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/admin-install-theme-modal-test.js @@ -80,11 +80,7 @@ acceptance("Admin - Themes - Install modal", function (needs) { test("modal can be auto-opened with the right query params", async function (assert) { await visit("/admin/customize/themes?repoUrl=testUrl&repoName=testName"); assert.dom(".admin-install-theme-modal").exists("modal is visible"); - assert.strictEqual( - query(".install-theme code").textContent.trim(), - "testUrl", - "repo url is visible" - ); + assert.dom(".install-theme code").hasText("testUrl", "repo url is visible"); await click(".d-modal-cancel"); assert.strictEqual( @@ -103,12 +99,9 @@ acceptance("Admin - Themes - Install modal", function (needs) { '.popular-theme-item[data-name="Graceful"] .popular-theme-buttons button' ) .doesNotExist("no install button is shown for installed themes"); - assert.strictEqual( - query( - '.popular-theme-item[data-name="Graceful"] .popular-theme-buttons' - ).textContent.trim(), - i18n("admin.customize.theme.installed") - ); + assert + .dom('.popular-theme-item[data-name="Graceful"] .popular-theme-buttons') + .hasText(i18n("admin.customize.theme.installed")); assert .dom( diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js index e8c6c5992a6..9c28edd2cfc 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/admin-user-index-test.js @@ -1,7 +1,7 @@ import { click, currentURL, fillIn, visit } from "@ember/test-helpers"; import { test } from "qunit"; import { SECOND_FACTOR_METHODS } from "discourse/models/user"; -import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import selectKit from "discourse/tests/helpers/select-kit-helper"; import { i18n } from "discourse-i18n"; @@ -245,10 +245,7 @@ acceptance("Admin - User Index", function (needs) { await visit("/admin/users/3/user1"); await click(".grant-admin"); assert.dom(".dialog-content").exists(); - assert.strictEqual( - i18n("admin.user.grant_admin_confirm"), - query(".dialog-body").textContent.trim() - ); + assert.dom(".dialog-body").hasText(i18n("admin.user.grant_admin_confirm")); await click(".dialog-footer .btn-primary"); }); @@ -277,10 +274,9 @@ acceptance("Admin - User Index", function (needs) { await visit("/admin/users/7/jimmy"); await click(".disable-second-factor"); assert.dom(".dialog-content").exists(); - assert.strictEqual( - i18n("admin.user.disable_second_factor_confirm"), - query(".dialog-body").textContent.trim() - ); + assert + .dom(".dialog-body") + .hasText(i18n("admin.user.disable_second_factor_confirm")); await click(".dialog-footer .btn-primary"); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-watched-words-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-watched-words-test.js index a912a346364..8352cbed86b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/admin-watched-words-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/admin-watched-words-test.js @@ -1,10 +1,6 @@ import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers"; import { test } from "qunit"; -import { - acceptance, - query, - queryAll, -} from "discourse/tests/helpers/qunit-helpers"; +import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { i18n } from "discourse-i18n"; acceptance("Admin - Watched Words", function (needs) { @@ -177,9 +173,9 @@ acceptance("Admin - Watched Words - Emoji Replacement", function (needs) { await click("button.reply-to-post"); await fillIn(".d-editor-input", "betis betis betis"); - const cooked = query(".d-editor-preview p"); - const cookedChildren = Array.from(cooked.children); - const emojis = cookedChildren.filter((child) => child.nodeName === "IMG"); + const emojis = [ + ...document.querySelector(".d-editor-preview p").children, + ].filter((child) => child.nodeName === "IMG"); assert.strictEqual(emojis.length, 3, "three emojis have been rendered"); assert.true( diff --git a/app/assets/javascripts/discourse/tests/acceptance/category-edit-security-test.js b/app/assets/javascripts/discourse/tests/acceptance/category-edit-security-test.js index 98d81a7a319..1165cbb93e0 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/category-edit-security-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/category-edit-security-test.js @@ -1,10 +1,6 @@ import { click, visit } from "@ember/test-helpers"; import { test } from "qunit"; -import { - acceptance, - query, - queryAll, -} from "discourse/tests/helpers/qunit-helpers"; +import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import selectKit from "discourse/tests/helpers/select-kit-helper"; import { i18n } from "discourse-i18n"; @@ -52,14 +48,13 @@ acceptance("Category Edit - Security", function (needs) { await availableGroups.expand(); await availableGroups.selectRowByValue("staff"); - const addedRow = [...queryAll(".row-body")].at(-1); - - assert.dom(".group-name-link", addedRow).hasText("staff"); - assert.strictEqual( - addedRow.querySelectorAll(".d-icon-square-check").length, - 3, - "new row permissions match default 'everyone' permissions" - ); + assert.dom("[data-group-name='staff'] .group-name-link").hasText("staff"); + assert + .dom("[data-group-name='staff'] .d-icon-square-check") + .exists( + { count: 3 }, + "new row permissions match default 'everyone' permissions" + ); }); test("adding a previously removed permission", async function (assert) { @@ -77,14 +72,12 @@ acceptance("Category Edit - Security", function (needs) { assert.dom(".row-body").exists("adds back the permission tp the list"); - const firstRow = query(".row-body"); - - assert.dom(".group-name-label", firstRow).hasText("everyone"); - assert.strictEqual( - firstRow.querySelectorAll(".d-icon-square-check").length, - 1, - "adds only 'See' permission for a new row" - ); + assert + .dom(".row-body[data-group-name='everyone'] .group-name-label") + .hasText("everyone"); + assert + .dom(".row-body[data-group-name='everyone'] .d-icon-square-check") + .exists({ count: 1 }, "adds only 'See' permission for a new row"); }); test("editing permissions", async function (assert) { @@ -92,71 +85,66 @@ acceptance("Category Edit - Security", function (needs) { await visit("/c/bug/edit/security"); - const everyoneRow = query(".row-body"); - - assert.strictEqual( - everyoneRow.querySelectorAll(".reply-granted, .create-granted").length, - 2, - "everyone has full permissions by default" - ); + assert + .dom( + "[data-group-name='everyone'] .reply-granted, [data-group-name='everyone'] .create-granted" + ) + .exists({ count: 2 }, "everyone has full permissions by default"); await availableGroups.expand(); await availableGroups.selectRowByValue("staff"); - const staffRow = [...queryAll(".row-body")].at(-1); + assert + .dom( + "[data-group-name='staff'] .reply-granted, [data-group-name='staff'] .create-granted" + ) + .exists({ count: 2 }, "staff group also has full permissions"); - assert.strictEqual( - staffRow.querySelectorAll(".reply-granted, .create-granted").length, - 2, - "staff group also has full permissions" - ); + await click("[data-group-name='everyone'] .reply-toggle"); - await click(everyoneRow.querySelector(".reply-toggle")); + assert + .dom( + "[data-group-name='everyone'] .reply-granted, [data-group-name='everyone'] .create-granted" + ) + .doesNotExist("everyone does not have reply or create"); - assert.strictEqual( - everyoneRow.querySelectorAll(".reply-granted, .create-granted").length, - 0, - "everyone does not have reply or create" - ); + assert + .dom( + "[data-group-name='staff'] .reply-granted, [data-group-name='staff'] .create-granted" + ) + .exists({ count: 2 }, "staff group still has full permissions"); - assert.strictEqual( - staffRow.querySelectorAll(".reply-granted, .create-granted").length, - 2, - "staff group still has full permissions" - ); + await click("[data-group-name='staff'] .reply-toggle"); - await click(staffRow.querySelector(".reply-toggle")); + assert + .dom( + "[data-group-name='everyone'] .reply-granted, [data-group-name='everyone'] .create-granted" + ) + .doesNotExist("everyone permission unchanged"); - assert.strictEqual( - everyoneRow.querySelectorAll(".reply-granted, .create-granted").length, - 0, - "everyone permission unchanged" - ); + assert + .dom("[data-group-name='staff'] .reply-granted") + .doesNotExist("staff does not have reply permission"); - assert.strictEqual( - staffRow.querySelectorAll(".reply-granted").length, - 0, - "staff does not have reply permission" - ); + assert + .dom("[data-group-name='staff'] .create-granted") + .doesNotExist("staff does not have create permission"); - assert.strictEqual( - staffRow.querySelectorAll(".create-granted").length, - 0, - "staff does not have create permission" - ); + await click("[data-group-name='everyone'] .create-toggle"); - await click(everyoneRow.querySelector(".create-toggle")); + assert + .dom( + "[data-group-name='everyone'] .reply-granted, [data-group-name='everyone'] .create-granted" + ) + .exists({ count: 2 }, "everyone has full permissions"); - assert.strictEqual( - everyoneRow.querySelectorAll(".reply-granted, .create-granted").length, - 2, - "everyone has full permissions" - ); - - assert.strictEqual( - staffRow.querySelectorAll(".reply-granted, .create-granted").length, - 2, - "staff group has full permissions (inherited from everyone)" - ); + assert + .dom( + "[data-group-name='staff'] .reply-granted, [data-group-name='staff'] .create-granted" + ) + .exists( + { count: 2 }, + "staff group has full permissions (inherited from everyone)" + ); }); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js b/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js index 362dbe8b468..e901490c02d 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js @@ -3,7 +3,7 @@ import { test } from "qunit"; import sinon from "sinon"; import DiscourseURL from "discourse/lib/url"; import pretender from "discourse/tests/helpers/create-pretender"; -import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import selectKit from "discourse/tests/helpers/select-kit-helper"; import { i18n } from "discourse-i18n"; @@ -184,8 +184,7 @@ acceptance("Category Edit", function (needs) { await fillIn(".email-in", "duplicate@example.com"); await click("#save-category"); - assert.strictEqual( - query(".dialog-body").textContent.trim(), + assert.dom(".dialog-body").hasText( i18n("generic_error_with_reason", { error: "duplicate email", }) @@ -204,8 +203,7 @@ acceptance("Category Edit", function (needs) { await click("#save-category"); - assert.strictEqual( - query(".dialog-body").textContent.trim(), + assert.dom(".dialog-body").hasText( i18n("generic_error_with_reason", { error: "subcategory nested under another subcategory", }) diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js index 9f851dbd66b..71a00dafc16 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js @@ -70,10 +70,9 @@ acceptance("Composer Actions", function (needs) { assert .dom(".action-title .topic-link") .hasAttribute("href", "/t/internationalization-localization/280"); - assert.strictEqual( - query(".d-editor-input").value, - "test replying to topic when initially replied to post" - ); + assert + .dom(".d-editor-input") + .hasValue("test replying to topic when initially replied to post"); }); test("replying to post - toggle_whisper for whisperers", async function (assert) { @@ -409,10 +408,9 @@ acceptance("Composer Actions With New Topic Draft", function (needs) { await composerActions.selectRowByValue("shared_draft"); assert.strictEqual(tags.header().value(), "monkey", "tags are not reset"); - assert.strictEqual( - query("#reply-title").value, - "This is the new text for the title using 'quotes'" - ); + assert + .dom("#reply-title") + .hasValue("This is the new text for the title using 'quotes'"); assert .dom("#reply-control .btn-primary.create .d-button-label") @@ -437,11 +435,7 @@ acceptance("Composer Actions With New Topic Draft", function (needs) { .hasText(i18n("composer.composer_actions.reply_as_new_topic.confirm")); await click(".dialog-footer .btn-primary"); - assert.true( - query(".d-editor-input").value.startsWith( - "Continuing the discussion from" - ) - ); + assert.dom(".d-editor-input").hasValue(/^Continuing the discussion from/); }); }); @@ -463,10 +457,11 @@ acceptance("Prioritize Username", function (needs) { await visit("/t/short-topic-with-two-posts/54079"); await selectText("#post_2 p"); await click(".insert-quote"); - assert.strictEqual( - query(".d-editor-input").value.trim(), - '[quote="james_john, post:2, topic:54079, full:true"]\nThis is a short topic.\n[/quote]' - ); + assert + .dom(".d-editor-input") + .hasValue( + '[quote="james_john, post:2, topic:54079, full:true"]\nThis is a short topic.\n[/quote]\n\n' + ); }); }); @@ -490,20 +485,22 @@ acceptance("Prioritize Full Name", function (needs) { await visit("/t/short-topic-with-two-posts/54079"); await selectText("#post_2 p"); await click(".insert-quote"); - assert.strictEqual( - query(".d-editor-input").value.trim(), - '[quote="james, john, the third, post:2, topic:54079, full:true, username:james_john"]\nThis is a short topic.\n[/quote]' - ); + assert + .dom(".d-editor-input") + .hasValue( + '[quote="james, john, the third, post:2, topic:54079, full:true, username:james_john"]\nThis is a short topic.\n[/quote]\n\n' + ); }); test("Quoting a nested quote returns the correct username", async function (assert) { await visit("/t/short-topic-with-two-posts/54079"); await selectText("#post_4 p"); await click(".insert-quote"); - assert.strictEqual( - query(".d-editor-input").value.trim(), - '[quote="james_john, post:2, topic:54079"]\nThis is a short topic.\n[/quote]' - ); + assert + .dom(".d-editor-input") + .hasValue( + '[quote="james_john, post:2, topic:54079"]\nThis is a short topic.\n[/quote]\n\n' + ); }); }); @@ -519,9 +516,10 @@ acceptance("Prioritizing Name fall back", function (needs) { // select a user with no name await selectText("#post_1 p"); await click(".insert-quote"); - assert.strictEqual( - query(".d-editor-input").value.trim(), - '[quote="bianca, post:1, topic:130, full:true"]\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a varius ipsum. Nunc euismod, metus non vulputate malesuada, ligula metus pharetra tortor, vel sodales arcu lacus sed mauris. Nam semper, orci vitae fringilla placerat, dui tellus convallis felis, ultricies laoreet sapien mi et metus. Mauris facilisis, mi fermentum rhoncus feugiat, dolor est vehicula leo, id porta leo ex non enim. In a ligula vel tellus commodo scelerisque non in ex. Pellentesque semper leo quam, nec varius est viverra eget. Donec vehicula sem et massa faucibus tempus.\n[/quote]' - ); + assert + .dom(".d-editor-input") + .hasValue( + '[quote="bianca, post:1, topic:130, full:true"]\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a varius ipsum. Nunc euismod, metus non vulputate malesuada, ligula metus pharetra tortor, vel sodales arcu lacus sed mauris. Nam semper, orci vitae fringilla placerat, dui tellus convallis felis, ultricies laoreet sapien mi et metus. Mauris facilisis, mi fermentum rhoncus feugiat, dolor est vehicula leo, id porta leo ex non enim. In a ligula vel tellus commodo scelerisque non in ex. Pellentesque semper leo quam, nec varius est viverra eget. Donec vehicula sem et massa faucibus tempus.\n[/quote]\n\n' + ); }); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-hyperlink-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-hyperlink-test.js index 5553d7aca4a..aff9f21b8c9 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-hyperlink-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-hyperlink-test.js @@ -1,6 +1,6 @@ import { click, fillIn, triggerKeyEvent, 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"; acceptance("Composer - Hyperlink", function (needs) { needs.user(); @@ -50,7 +50,7 @@ acceptance("Composer - Hyperlink", function (needs) { .dom(".insert-link.d-modal__body") .doesNotExist("modal dismissed after cancelling"); - const textarea = query("#reply-control .d-editor-input"); + const textarea = document.querySelector("#reply-control .d-editor-input"); textarea.selectionStart = 0; textarea.selectionEnd = 6; await click(".d-editor button.link"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-uploads-uppy-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-uploads-uppy-test.js index 82081dcb3d9..9f480b81820 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-uploads-uppy-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-uploads-uppy-test.js @@ -194,12 +194,11 @@ acceptance("Uppy Composer Attachment - Upload Placeholder", function (needs) { const done = assert.async(); appEvents.on("composer:uploads-aborted", async () => { await settled(); - assert.strictEqual( - query(".dialog-body").textContent.trim(), + assert.dom(".dialog-body").hasText( i18n("post.errors.too_many_dragged_and_dropped_files", { count: 2, }), - "it should warn about too many files added" + "warns about too many files added" ); await click(".dialog-footer .btn-primary"); @@ -219,15 +218,14 @@ acceptance("Uppy Composer Attachment - Upload Placeholder", function (needs) { appEvents.on("composer:uploads-aborted", async () => { await settled(); - assert.strictEqual( - query(".dialog-body").textContent.trim(), + assert.dom(".dialog-body").hasText( i18n("post.errors.upload_not_authorized", { authorized_extensions: authorizedExtensions( false, this.siteSettings ).join(", "), }), - "it should warn about unauthorized extensions" + "warns about unauthorized extensions" ); await click(".dialog-footer .btn-primary"); @@ -502,11 +500,12 @@ acceptance("Uppy Composer Attachment - Upload Error", function (needs) { appEvents.on("composer:upload-error", async () => { await settled(); - assert.strictEqual( - query(".dialog-body").textContent.trim(), - "There was an error uploading the file, the gif was way too cool.", - "it should show the error message from the server" - ); + assert + .dom(".dialog-body") + .hasText( + "There was an error uploading the file, the gif was way too cool.", + "shows the error message from the server" + ); await click(".dialog-footer .btn-primary"); done(); @@ -591,11 +590,12 @@ acceptance("Uppy Composer Attachment - Upload Handler", function (needs) { appEvents.on("composer:uploads-aborted", async () => { await settled(); - assert.strictEqual( - query(".dialog-body").textContent.trim(), - "This is an upload handler test for handler-test.png. The file WAS a native file object.", - "it should show the dialog triggered by the upload handler" - ); + assert + .dom(".dialog-body") + .hasText( + "This is an upload handler test for handler-test.png. The file WAS a native file object.", + "shows the dialog triggered by the upload handler" + ); await click(".dialog-footer .btn-primary"); done(); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/do-not-disturb-test.js b/app/assets/javascripts/discourse/tests/acceptance/do-not-disturb-test.js index 4813e2f6f85..ed762f7054c 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/do-not-disturb-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/do-not-disturb-test.js @@ -3,7 +3,6 @@ import { test } from "qunit"; import DoNotDisturb from "discourse/lib/do-not-disturb"; import { acceptance, - query, queryAll, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; @@ -88,11 +87,12 @@ acceptance("Do not disturb", function (needs) { await click(".header-dropdown-toggle.current-user button"); await click("#user-menu-button-profile"); - assert.strictEqual( - query(".do-not-disturb .relative-date").textContent.trim(), - "1h", - "the Do Not Disturb button shows how much time is left for DND mode" - ); + assert + .dom(".do-not-disturb .relative-date") + .hasText( + "1h", + "the Do Not Disturb button shows how much time is left for DND mode" + ); assert .dom(".do-not-disturb .d-icon-toggle-on") .exists("the Do Not Disturb button has the toggle-on icon"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/edit-notification-click-test.js b/app/assets/javascripts/discourse/tests/acceptance/edit-notification-click-test.js index 1f6898f3289..a7226acfef8 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/edit-notification-click-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/edit-notification-click-test.js @@ -55,17 +55,19 @@ acceptance( await click(".notification.edited a"); const [v1, v2] = queryAll(".history-modal .revision-content"); - assert.strictEqual( - v1.textContent.trim(), - "Hello world this is a test", - "history modal for the edited post is shown" - ); + assert + .dom(v1) + .hasText( + "Hello world this is a test", + "history modal for the edited post is shown" + ); - assert.strictEqual( - v2.textContent.trim(), - "Hello world this is a testThis is an edit!", - "history modal for the edited post is shown" - ); + assert + .dom(v2) + .hasText( + "Hello world this is a testThis is an edit!", + "history modal for the edited post is shown" + ); }); } ); diff --git a/app/assets/javascripts/discourse/tests/acceptance/group-test.js b/app/assets/javascripts/discourse/tests/acceptance/group-test.js index 52084bf4b14..2cf47729568 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/group-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/group-test.js @@ -257,12 +257,11 @@ acceptance("Group - Authenticated", function (needs) { await click(".group-details-button button.btn-danger"); - assert.strictEqual( - query(".dialog-body p:nth-of-type(2)").textContent.trim(), + assert.dom(".dialog-body p:nth-of-type(2)").hasText( i18n("admin.groups.delete_with_messages_confirm", { count: 2, }), - "should warn about orphan messages" + "warns about orphan messages" ); await click(".dialog-footer .btn-default"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/search-test.js b/app/assets/javascripts/discourse/tests/acceptance/search-test.js index e8c3f89d9c6..2e591d6a488 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/search-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/search-test.js @@ -148,38 +148,28 @@ acceptance("Search - Anonymous", function (needs) { await visit("/tag/important"); await click("#search-button"); - assert.strictEqual( - query(".search-link .label-suffix").textContent.trim(), - i18n("search.in"), - "first option includes suffix" - ); + assert + .dom(".search-link .label-suffix") + .hasText(i18n("search.in"), "first option includes suffix"); - assert.strictEqual( - query(".search-link .search-item-tag").textContent.trim(), - "important", - "first option includes tag" - ); + assert + .dom(".search-link .search-item-tag") + .hasText("important", "first option includes tag"); await fillIn("#search-term", "smth"); const secondOption = queryAll(contextSelector)[1]; - assert.strictEqual( - secondOption.querySelector(".search-item-prefix").textContent.trim(), - "smth", - "second option includes term" - ); + assert + .dom(".search-item-prefix", secondOption) + .hasText("smth", "second option includes term"); - assert.strictEqual( - secondOption.querySelector(".label-suffix").textContent.trim(), - i18n("search.in"), - "second option includes suffix" - ); + assert + .dom(".label-suffix", secondOption) + .hasText(i18n("search.in"), "second option includes suffix"); - assert.strictEqual( - secondOption.querySelector(".search-item-tag").textContent.trim(), - "important", - "second option includes tag" - ); + assert + .dom(".search-item-tag", secondOption) + .hasText("important", "second option includes tag"); }); test("initial options - category search scope", async function (assert) { @@ -189,23 +179,17 @@ acceptance("Search - Anonymous", function (needs) { await fillIn("#search-term", "smth"); const secondOption = queryAll(contextSelector)[1]; - assert.strictEqual( - secondOption.querySelector(".search-item-prefix").textContent.trim(), - "smth", - "second option includes term" - ); + assert + .dom(".search-item-prefix", secondOption) + .hasText("smth", "second option includes term"); - assert.strictEqual( - secondOption.querySelector(".label-suffix").textContent.trim(), - i18n("search.in"), - "second option includes suffix" - ); + assert + .dom(".label-suffix", secondOption) + .hasText(i18n("search.in"), "second option includes suffix"); - assert.strictEqual( - secondOption.querySelector(".badge-category__name").textContent.trim(), - "bug", - "second option includes category slug" - ); + assert + .dom(".badge-category__name", secondOption) + .hasText("bug", "second option includes category slug"); assert .dom(`${contextSelector} span.badge-category__wrapper`) @@ -219,17 +203,13 @@ acceptance("Search - Anonymous", function (needs) { await fillIn("#search-term", "smth"); const secondOption = queryAll(contextSelector)[1]; - assert.strictEqual( - secondOption.querySelector(".search-item-prefix").textContent.trim(), - "smth", - "second option includes term" - ); + assert + .dom(".search-item-prefix", secondOption) + .hasText("smth", "second option includes term"); - assert.strictEqual( - secondOption.querySelector(".label-suffix").textContent.trim(), - i18n("search.in_this_topic"), - "second option includes suffix" - ); + assert + .dom(".label-suffix", secondOption) + .hasText(i18n("search.in_this_topic"), "second option includes suffix"); }); test("initial options - topic search scope - 'in all topics' searches in all topics", async function (assert) { @@ -284,21 +264,23 @@ acceptance("Search - Anonymous", function (needs) { await fillIn("#search-term", "@admin"); assert.dom(".search-menu-assistant-item").exists({ count: 2 }); - assert.strictEqual( - query( + assert + .dom( ".search-menu-assistant-item:first-child .search-item-slug .label-suffix" - ).textContent.trim(), - i18n("search.in_topics_posts"), - "first result hints at global search" - ); + ) + .hasText( + i18n("search.in_topics_posts"), + "first result hints at global search" + ); - assert.strictEqual( - query( + assert + .dom( ".search-menu-assistant-item:nth-child(2) .search-item-slug .label-suffix" - ).textContent.trim(), - i18n("search.in_this_topic"), - "second result hints at search within current topic" - ); + ) + .hasText( + i18n("search.in_this_topic"), + "second result hints at search within current topic" + ); }); test("initial options - user search scope", async function (assert) { @@ -308,17 +290,16 @@ acceptance("Search - Anonymous", function (needs) { await fillIn("#search-term", "smth"); const secondOption = queryAll(contextSelector)[1]; - assert.strictEqual( - secondOption.querySelector(".search-item-prefix").textContent.trim(), - "smth", - "second option includes term for user-scoped search" - ); + assert + .dom(".search-item-prefix", secondOption) + .hasText("smth", "second option includes term for user-scoped search"); - assert.strictEqual( - secondOption.querySelector(".label-suffix").textContent.trim(), - i18n("search.in_posts_by", { username: "eviltrout" }), - "second option includes suffix for user-scoped search" - ); + assert + .dom(".label-suffix", secondOption) + .hasText( + i18n("search.in_posts_by", { username: "eviltrout" }), + "second option includes suffix for user-scoped search" + ); }); test("topic results", async function (assert) { @@ -349,22 +330,16 @@ acceptance("Search - Anonymous", function (needs) { .dom(".search-menu .search-result-post ul li") .exists("clicking second option scopes search to current topic"); - assert.strictEqual( - query("#post_7 span.highlighted").textContent.trim(), - "a proper", - "highlights the post correctly" - ); + assert + .dom("#post_7 span.highlighted") + .hasText("a proper", "highlights the post correctly"); assert .dom(".search-menu .search-context") .exists("search context indicator is visible"); await click(".clear-search"); - assert.strictEqual( - query("#search-term").textContent.trim(), - "", - "clear button works" - ); + assert.dom("#search-term").hasNoText("clear button works"); await click(".search-context"); assert @@ -688,21 +663,13 @@ acceptance("Search - Authenticated", function (needs) { await visit("/"); await click("#search-button"); - assert.strictEqual( - query( - ".search-menu .search-menu-recent li:nth-of-type(1) .search-link" - ).textContent.trim(), - "yellow", - "shows first recent search" - ); + assert + .dom(".search-menu .search-menu-recent li:nth-of-type(1) .search-link") + .hasText("yellow", "shows first recent search"); - assert.strictEqual( - query( - ".search-menu .search-menu-recent li:nth-of-type(2) .search-link" - ).textContent.trim(), - "blue", - "shows second recent search" - ); + assert + .dom(".search-menu .search-menu-recent li:nth-of-type(2) .search-link") + .hasText("blue", "shows second recent search"); await click( ".search-menu .search-menu-recent li:nth-of-type(1) .search-link" @@ -818,13 +785,9 @@ acceptance("Search - with tagging enabled", function (needs) { await fillIn("#search-term", "dev"); await triggerKeyEvent("#search-term", "keyup", 13); - assert.strictEqual( - query( - ".search-menu .results ul li:nth-of-type(1) .discourse-tags" - ).textContent.trim(), - "devslow", - "tags displayed in search results" - ); + assert + .dom(".search-menu .results ul li:nth-of-type(1) .discourse-tags") + .hasText("devslow", "tags displayed in search results"); }); test("initial options - topic search scope - selecting a tag defaults to searching 'in all topics'", async function (assert) { @@ -847,9 +810,7 @@ acceptance("Search - with tagging enabled", function (needs) { ".search-menu .results ul.search-menu-assistant .search-link"; assert.dom(firstItem).exists(); - - const firstTag = query(`${firstItem} .search-item-tag`).textContent.trim(); - assert.strictEqual(firstTag, "monkey"); + assert.dom(`${firstItem} .search-item-tag`).hasText("monkey"); }); test("initial options - search history - tag context", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-categories-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-categories-section-test.js index 64fded4397d..0dcf189f5c3 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-categories-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-categories-section-test.js @@ -22,31 +22,11 @@ acceptance("Sidebar - Anonymous - Categories Section", function (needs) { .sort((a, b) => b.topic_count - a.topic_count); assert.strictEqual(categorySectionLinks.length, 6); - - assert.strictEqual( - categorySectionLinks[0].textContent.trim(), - sidebarCategories[0].name - ); - - assert.strictEqual( - categorySectionLinks[1].textContent.trim(), - sidebarCategories[1].name - ); - - assert.strictEqual( - categorySectionLinks[2].textContent.trim(), - sidebarCategories[2].name - ); - - assert.strictEqual( - categorySectionLinks[3].textContent.trim(), - sidebarCategories[3].name - ); - - assert.strictEqual( - categorySectionLinks[4].textContent.trim(), - sidebarCategories[4].name - ); + assert.dom(categorySectionLinks[0]).hasText(sidebarCategories[0].name); + assert.dom(categorySectionLinks[1]).hasText(sidebarCategories[1].name); + assert.dom(categorySectionLinks[2]).hasText(sidebarCategories[2].name); + assert.dom(categorySectionLinks[3]).hasText(sidebarCategories[3].name); + assert.dom(categorySectionLinks[4]).hasText(sidebarCategories[4].name); assert .dom("a.sidebar-section-link[data-link-name='all-categories']") @@ -65,31 +45,11 @@ acceptance("Sidebar - Anonymous - Categories Section", function (needs) { const siteCategories = Site.current().categories; assert.strictEqual(categories.length, 6); - - assert.strictEqual( - categories[0].textContent.trim(), - siteCategories[0].name - ); - - assert.strictEqual( - categories[1].textContent.trim(), - siteCategories[1].name - ); - - assert.strictEqual( - categories[2].textContent.trim(), - siteCategories[3].name - ); - - assert.strictEqual( - categories[3].textContent.trim(), - siteCategories[4].name - ); - - assert.strictEqual( - categories[4].textContent.trim(), - siteCategories[5].name - ); + assert.dom(categories[0]).hasText(siteCategories[0].name); + assert.dom(categories[1]).hasText(siteCategories[1].name); + assert.dom(categories[2]).hasText(siteCategories[3].name); + assert.dom(categories[3]).hasText(siteCategories[4].name); + assert.dom(categories[4]).hasText(siteCategories[5].name); assert .dom("a.sidebar-section-link[data-link-name='all-categories']") @@ -107,9 +67,9 @@ acceptance("Sidebar - Anonymous - Categories Section", function (needs) { ); assert.strictEqual(categories.length, 4); - assert.strictEqual(categories[0].textContent.trim(), "meta"); - assert.strictEqual(categories[1].textContent.trim(), "blog"); - assert.strictEqual(categories[2].textContent.trim(), "bug"); + assert.dom(categories[0]).hasText("meta"); + assert.dom(categories[1]).hasText("blog"); + assert.dom(categories[2]).hasText("bug"); assert .dom("a.sidebar-section-link[data-link-name='all-categories']") diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js index c55c7bbcf1a..41a10506f1f 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-community-section-test.js @@ -14,15 +14,14 @@ acceptance("Sidebar - Anonymous user - Community Section", function (needs) { test("topics section link is shown by default ", async function (assert) { await visit("/"); - const sectionLinks = queryAll( - ".sidebar-section[data-section-name='community'] .sidebar-section-link" - ); - - assert.strictEqual( - sectionLinks[0].textContent.trim(), - i18n("sidebar.sections.community.links.topics.content"), - "displays the topics section link first" - ); + assert + .dom( + ".sidebar-section[data-section-name='community'] .sidebar-section-link" + ) + .hasText( + i18n("sidebar.sections.community.links.topics.content"), + "displays the topics section link first" + ); }); test("users section link is not shown when hide_user_profiles_from_public site setting is enabled", async function (assert) { @@ -48,34 +47,39 @@ acceptance("Sidebar - Anonymous user - Community Section", function (needs) { ".sidebar-more-section-links-details-content-main .sidebar-section-link" ); - assert.strictEqual( - sectionLinks[0].textContent.trim(), - i18n("sidebar.sections.community.links.users.content"), - "displays the users section link second" - ); + assert + .dom(sectionLinks[0]) + .hasText( + i18n("sidebar.sections.community.links.users.content"), + "displays the users section link second" + ); - assert.strictEqual( - sectionLinks[1].textContent.trim(), - i18n("sidebar.sections.community.links.about.content"), - "displays the about section link third" - ); + assert + .dom(sectionLinks[1]) + .hasText( + i18n("sidebar.sections.community.links.about.content"), + "displays the about section link third" + ); - assert.strictEqual( - sectionLinks[2].textContent.trim(), - i18n("sidebar.sections.community.links.faq.content"), - "displays the FAQ section link last" - ); + assert + .dom(sectionLinks[2]) + .hasText( + i18n("sidebar.sections.community.links.faq.content"), + "displays the FAQ section link last" + ); - assert.strictEqual( - sectionLinks[3].textContent.trim(), - i18n("sidebar.sections.community.links.groups.content"), - "displays the groups section link first" - ); + assert + .dom(sectionLinks[3]) + .hasText( + i18n("sidebar.sections.community.links.groups.content"), + "displays the groups section link first" + ); - assert.strictEqual( - sectionLinks[4].textContent.trim(), - i18n("sidebar.sections.community.links.badges.content"), - "displays the badges section link second" - ); + assert + .dom(sectionLinks[4]) + .hasText( + i18n("sidebar.sections.community.links.badges.content"), + "displays the badges section link second" + ); }); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js index 11558ba0e67..ce18aa67dfb 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-categories-section-test.js @@ -8,7 +8,6 @@ import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures"; import { acceptance, publishToMessageBus, - query, queryAll, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; @@ -433,13 +432,9 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) { "category1 section link is rendered with solid prefix icon color" ); - assert.strictEqual( - query( - `.sidebar-section-link-wrapper[data-category-id="${category1.id}"]` - ).textContent.trim(), - category1.name, - "displays category1's name for the link text" - ); + assert + .dom(`.sidebar-section-link-wrapper[data-category-id="${category1.id}"]`) + .hasText(category1.name, "displays category1's name for the link text"); await click( `.sidebar-section-link-wrapper[data-category-id="${category1.id}"] a` @@ -890,21 +885,23 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) { await visit("/"); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-category-id="${category1.id}"] .sidebar-section-link-content-badge` - ).textContent.trim(), - i18n("sidebar.unread_count", { count: 1 }), - `displays 1 unread count for ${category1.slug} section link` - ); + ) + .hasText( + i18n("sidebar.unread_count", { count: 1 }), + `displays 1 unread count for ${category1.slug} section link` + ); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-category-id="${category2.id}"] .sidebar-section-link-content-badge` - ).textContent.trim(), - i18n("sidebar.unread_count", { count: 2 }), - `displays 2 unread count for ${category2.slug} section link` - ); + ) + .hasText( + i18n("sidebar.unread_count", { count: 2 }), + `displays 2 unread count for ${category2.slug} section link` + ); await publishToMessageBus("/unread", { topic_id: 2, @@ -915,13 +912,14 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) { }, }); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-category-id="${category1.id}"] .sidebar-section-link-content-badge` - ).textContent.trim(), - i18n("sidebar.new_count", { count: 1 }), - `displays 1 new count for ${category1.slug} section link` - ); + ) + .hasText( + i18n("sidebar.new_count", { count: 1 }), + `displays 1 new count for ${category1.slug} section link` + ); await publishToMessageBus("/unread", { topic_id: 1, @@ -949,13 +947,14 @@ acceptance("Sidebar - Logged on user - Categories Section", function (needs) { }, }); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-category-id="${category2.id}"] .sidebar-section-link-content-badge` - ).textContent.trim(), - i18n("sidebar.unread_count", { count: 1 }), - `displays 1 unread count for ${category2.slug} section link` - ); + ) + .hasText( + i18n("sidebar.unread_count", { count: 1 }), + `displays 1 unread count for ${category2.slug} section link` + ); }); test("clean up topic tracking state state changed callbacks when Sidebar is collapsed", async function (assert) { @@ -1081,29 +1080,26 @@ acceptance( await visit("/"); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-category-id="${category1.id}"] .sidebar-section-link-content-badge` - ).textContent.trim(), - "2", - "count for category1 is 2 because it has 1 unread topic and 1 new topic" - ); + ) + .hasText( + "2", + "count for category1 is 2 because it has 1 unread topic and 1 new topic" + ); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-category-id="${category2.id}"] .sidebar-section-link-content-badge` - ).textContent.trim(), - "1", - "count for category2 is 1 because it has 1 new topic" - ); + ) + .hasText("1", "count for category2 is 1 because it has 1 new topic"); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-category-id="${category3.id}"] .sidebar-section-link-content-badge` - ).textContent.trim(), - "1", - "count for category3 is 1 because it has 1 unread topic" - ); + ) + .hasText("1", "count for category3 is 1 because it has 1 unread topic"); }); test("dot shown next to category link when sidebar_show_count_of_new_items is false", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js index eb6a5784e1f..1fc41ef9202 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js @@ -12,7 +12,6 @@ import { acceptance, loggedInUser, publishToMessageBus, - query, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; import { cloneJSON } from "discourse-common/lib/object"; @@ -278,13 +277,14 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { ) .exists("the users link is marked as active"); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='community'] .sidebar-more-section-links-details-summary .sidebar-section-link-content-text" - ).textContent.trim(), - i18n("sidebar.more"), - "displays the right count as users link is currently active" - ); + ) + .hasText( + i18n("sidebar.more"), + "displays the right count as users link is currently active" + ); await visit("/u"); @@ -382,13 +382,14 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { ) .exists("the groups link is marked as active"); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='community'] .sidebar-more-section-links-details-summary .sidebar-section-link-content-text" - ).textContent.trim(), - i18n("sidebar.more"), - "displays the right count as groups link is currently active" - ); + ) + .hasText( + i18n("sidebar.more"), + "displays the right count as groups link is currently active" + ); await visit("/g"); @@ -608,32 +609,30 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { }); await visit("/"); - assert.strictEqual( - query( - ".sidebar-section-link[data-link-name='my-posts']" - ).textContent.trim(), - i18n("sidebar.sections.community.links.my_posts.content"), - "displays the default text when no drafts are present" - ); + assert + .dom(".sidebar-section-link[data-link-name='my-posts']") + .hasText( + i18n("sidebar.sections.community.links.my_posts.content"), + "displays the default text when no drafts are present" + ); await publishToMessageBus(`/user-drafts/${loggedInUser().id}`, { draft_count: 1, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section-link[data-link-name='my-posts'] .sidebar-section-link-content-text" - ).textContent.trim(), - i18n("sidebar.sections.community.links.my_posts.content_drafts"), - "displays the text that's appropriate for when drafts are present" - ); - assert.strictEqual( - query( + ) + .hasText( + i18n("sidebar.sections.community.links.my_posts.content_drafts"), + "displays the text that's appropriate for when drafts are present" + ); + assert + .dom( ".sidebar-section-link[data-link-name='my-posts'] .sidebar-section-link-content-badge" - ).textContent.trim(), - "1", - "displays the draft count with no text" - ); + ) + .hasText("1", "displays the draft count with no text"); }); test("the invite section link is not visible to people who cannot invite to the forum", async function (assert) { @@ -847,13 +846,11 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { await visit("/"); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section-link[data-link-name='everything'] .sidebar-section-link-content-badge" - ).textContent.trim(), - "3 unread", - "displays the right unread count" - ); + ) + .hasText("3 unread", "displays the right unread count"); // simulate reading topic 2 await publishToMessageBus("/unread", { @@ -866,13 +863,11 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section-link[data-link-name='everything'] .sidebar-section-link-content-badge" - ).textContent.trim(), - "2 unread", - "updates the unread count" - ); + ) + .hasText("2 unread", "updates the unread count"); // simulate reading topic 3 await publishToMessageBus("/unread", { @@ -896,13 +891,14 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section-link[data-link-name='everything'] .sidebar-section-link-content-badge" - ).textContent.trim(), - "1 new", - "displays the new count once there are no unread topics" - ); + ) + .hasText( + "1 new", + "displays the new count once there are no unread topics" + ); await publishToMessageBus("/unread", { topic_id: 1, @@ -989,13 +985,11 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { ) .exists("review link is shown as part of the main section links"); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='community'] .sidebar-section-link[data-link-name='review'] .sidebar-section-link-content-badge" - ).textContent.trim(), - "34 pending", - "displays the pending reviewable count" - ); + ) + .hasText("34 pending", "displays the pending reviewable count"); await click( ".sidebar-section[data-section-name='community'] .sidebar-more-section-links-details-summary" @@ -1025,13 +1019,9 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { ".sidebar-section[data-section-name='community'] .sidebar-more-section-links-details-summary" ); - assert.strictEqual( - query( - ".sidebar-section-link[data-link-name='unread']" - ).textContent.trim(), - "unread topics", - "displays the right text for the link" - ); + assert + .dom(".sidebar-section-link[data-link-name='unread']") + .hasText("unread topics", "displays the right text for the link"); assert .dom(".sidebar-section-link[data-link-name='unread']") @@ -1099,13 +1089,9 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { "links to the right URL" ); - assert.strictEqual( - query( - ".sidebar-section-link[data-link-name='user-summary']" - ).textContent.trim(), - "my summary", - "displays the right text for the link" - ); + assert + .dom(".sidebar-section-link[data-link-name='user-summary']") + .hasText("my summary", "displays the right text for the link"); assert .dom(".sidebar-section-link[data-link-name='user-summary']") @@ -1179,13 +1165,14 @@ acceptance( await visit("/"); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section-link[data-link-name='everything'] .sidebar-section-link-content-badge" - ).textContent.trim(), - "2", - "count is 2 because there's 1 unread topic and 1 new topic" - ); + ) + .hasText( + "2", + "count is 2 because there's 1 unread topic and 1 new topic" + ); }); test("dot is shown next to the everything link when sidebar_show_count_of_new_items is false", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-messages-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-messages-section-test.js index 845328b83c1..9266c901eda 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-messages-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-messages-section-test.js @@ -4,7 +4,6 @@ import { NotificationLevels } from "discourse/lib/notification-levels"; import { acceptance, publishToMessageBus, - query, queryAll, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; @@ -413,25 +412,27 @@ acceptance( }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='messages'] .sidebar-section-link[data-link-name='group-messages-unread'].group1" - ).textContent.trim(), - i18n("sidebar.sections.messages.links.unread_with_count", { - count: 1, - }), - "displays 1 count for group1 unread inbox filter link" - ); + ) + .hasText( + i18n("sidebar.sections.messages.links.unread_with_count", { + count: 1, + }), + "displays 1 count for group1 unread inbox filter link" + ); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='messages'] .sidebar-section-link[data-link-name='group-messages-new'].group1" - ).textContent.trim(), - i18n("sidebar.sections.messages.links.new_with_count", { - count: 1, - }), - "displays 1 count for group1 new inbox filter link" - ); + ) + .hasText( + i18n("sidebar.sections.messages.links.new_with_count", { + count: 1, + }), + "displays 1 count for group1 new inbox filter link" + ); await publishToMessageBus(pmTopicTrackingState.groupChannel(1), { topic_id: 2, @@ -444,13 +445,14 @@ acceptance( }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='messages'] .sidebar-section-link[data-link-name='group-messages-new'].group1" - ).textContent.trim(), - i18n("sidebar.sections.messages.links.new"), - "removes count for group1 new inbox filter link" - ); + ) + .hasText( + i18n("sidebar.sections.messages.links.new"), + "removes count for group1 new inbox filter link" + ); }); test("new and unread counts for personal messages", async function (assert) { @@ -475,15 +477,16 @@ acceptance( }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='messages'] .sidebar-section-link[data-link-name='personal-messages-unread']" - ).textContent.trim(), - i18n("sidebar.sections.messages.links.unread_with_count", { - count: 1, - }), - "displays 1 count for the unread inbox filter link" - ); + ) + .hasText( + i18n("sidebar.sections.messages.links.unread_with_count", { + count: 1, + }), + "displays 1 count for the unread inbox filter link" + ); await publishToMessageBus(pmTopicTrackingState.userChannel(), { topic_id: 2, @@ -496,15 +499,16 @@ acceptance( }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='messages'] .sidebar-section-link[data-link-name='personal-messages-unread']" - ).textContent.trim(), - i18n("sidebar.sections.messages.links.unread_with_count", { - count: 2, - }), - "displays 2 count for the unread inbox filter link" - ); + ) + .hasText( + i18n("sidebar.sections.messages.links.unread_with_count", { + count: 2, + }), + "displays 2 count for the unread inbox filter link" + ); await publishToMessageBus(pmTopicTrackingState.userChannel(), { topic_id: 3, @@ -517,15 +521,16 @@ acceptance( }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='messages'] .sidebar-section-link[data-link-name='personal-messages-new']" - ).textContent.trim(), - i18n("sidebar.sections.messages.links.new_with_count", { - count: 1, - }), - "displays 1 count for the new inbox filter link" - ); + ) + .hasText( + i18n("sidebar.sections.messages.links.new_with_count", { + count: 1, + }), + "displays 1 count for the new inbox filter link" + ); await publishToMessageBus(pmTopicTrackingState.userChannel(), { topic_id: 3, @@ -538,13 +543,14 @@ acceptance( }, }); - assert.strictEqual( - query( + assert + .dom( ".sidebar-section[data-section-name='messages'] .sidebar-section-link[data-link-name='personal-messages-new']" - ).textContent.trim(), - i18n("sidebar.sections.messages.links.new"), - "removes the count from the new inbox filter link" - ); + ) + .hasText( + i18n("sidebar.sections.messages.links.new"), + "removes the count from the new inbox filter link" + ); }); } ); diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.js index bb0e0421266..96248fce709 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-tags-section-test.js @@ -5,7 +5,6 @@ import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures"; import { acceptance, publishToMessageBus, - query, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; import { cloneJSON } from "discourse-common/lib/object"; @@ -76,29 +75,17 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) { ) .exists({ count: 4 }, "4 section links under the section"); - assert.strictEqual( - query( - ".sidebar-section-link-wrapper[data-tag-name=tag1]" - ).textContent.trim(), - "tag1", - "displays the tag1 name for the link text" - ); + assert + .dom(".sidebar-section-link-wrapper[data-tag-name=tag1]") + .hasText("tag1", "displays the tag1 name for the link text"); - assert.strictEqual( - query( - ".sidebar-section-link-wrapper[data-tag-name=tag2]" - ).textContent.trim(), - "tag2", - "displays the tag2 name for the link text" - ); + assert + .dom(".sidebar-section-link-wrapper[data-tag-name=tag2]") + .hasText("tag2", "displays the tag2 name for the link text"); - assert.strictEqual( - query( - ".sidebar-section-link-wrapper[data-tag-name=tag3]" - ).textContent.trim(), - "tag3", - "displays the tag3 name for the link text" - ); + assert + .dom(".sidebar-section-link-wrapper[data-tag-name=tag3]") + .hasText("tag3", "displays the tag3 name for the link text"); await click(".sidebar-section-link-wrapper[data-tag-name=tag1] a"); @@ -462,21 +449,23 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) { await visit("/"); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-tag-name=tag1] .sidebar-section-link-content-badge` - ).textContent.trim(), - i18n("sidebar.unread_count", { count: 1 }), - `displays 1 unread count for tag1 section link` - ); + ) + .hasText( + i18n("sidebar.unread_count", { count: 1 }), + `displays 1 unread count for tag1 section link` + ); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-tag-name=tag2] .sidebar-section-link-content-badge` - ).textContent.trim(), - i18n("sidebar.unread_count", { count: 1 }), - `displays 1 unread count for tag2 section link` - ); + ) + .hasText( + i18n("sidebar.unread_count", { count: 1 }), + `displays 1 unread count for tag2 section link` + ); assert .dom( @@ -493,13 +482,14 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) { }, }); - assert.strictEqual( - query( + assert + .dom( `.sidebar-section-link-wrapper[data-tag-name=tag1] .sidebar-section-link-content-badge` - ).textContent.trim(), - i18n("sidebar.new_count", { count: 1 }), - `displays 1 new count for tag1 section link` - ); + ) + .hasText( + i18n("sidebar.new_count", { count: 1 }), + `displays 1 new count for tag1 section link` + ); await publishToMessageBus("/unread", { topic_id: 1, @@ -626,29 +616,26 @@ acceptance( await visit("/"); - assert.strictEqual( - query( + assert + .dom( '.sidebar-section-link-wrapper[data-tag-name="tag1"] .sidebar-section-link-content-badge' - ).textContent.trim(), - "2", - "count for tag1 is 2 because it has 1 unread topic and 1 new topic" - ); + ) + .hasText( + "2", + "count for tag1 is 2 because it has 1 unread topic and 1 new topic" + ); - assert.strictEqual( - query( + assert + .dom( '.sidebar-section-link-wrapper[data-tag-name="tag2"] .sidebar-section-link-content-badge' - ).textContent.trim(), - "1", - "count for tag2 is 1 because it has 1 unread topic" - ); + ) + .hasText("1", "count for tag2 is 1 because it has 1 unread topic"); - assert.strictEqual( - query( + assert + .dom( '.sidebar-section-link-wrapper[data-tag-name="tag3"] .sidebar-section-link-content-badge' - ).textContent.trim(), - "1", - "count for tag3 is 1 because it has 1 new topic" - ); + ) + .hasText("1", "count for tag3 is 1 because it has 1 new topic"); }); test("dot shown next to tag link when sidebar_show_count_of_new_items is false", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-discovery-tracked-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-discovery-tracked-test.js index a4dadae75c9..09a1ec623ea 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-discovery-tracked-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-discovery-tracked-test.js @@ -6,7 +6,6 @@ import topicFixtures from "discourse/tests/fixtures/discovery-fixtures"; import { acceptance, publishToMessageBus, - query, } from "discourse/tests/helpers/qunit-helpers"; import { cloneJSON } from "discourse-common/lib/object"; import { i18n } from "discourse-i18n"; @@ -183,31 +182,35 @@ acceptance("Topic Discovery Tracked", function (needs) { await visit("/"); - assert.strictEqual( - query("#navigation-bar li.unread").textContent.trim(), - i18n("filters.unread.title_with_count", { count: 4 }), - "displays the right content on unread link" - ); + assert + .dom("#navigation-bar li.unread") + .hasText( + i18n("filters.unread.title_with_count", { count: 4 }), + "displays the right content on unread link" + ); - assert.strictEqual( - query("#navigation-bar li.new").textContent.trim(), - i18n("filters.new.title_with_count", { count: 2 }), - "displays the right content on new link" - ); + assert + .dom("#navigation-bar li.new") + .hasText( + i18n("filters.new.title_with_count", { count: 2 }), + "displays the right content on new link" + ); await visit("/?f=tracked"); - assert.strictEqual( - query("#navigation-bar li.unread").textContent.trim(), - i18n("filters.unread.title_with_count", { count: 3 }), - "displays the right content on unread link" - ); + assert + .dom("#navigation-bar li.unread") + .hasText( + i18n("filters.unread.title_with_count", { count: 3 }), + "displays the right content on unread link" + ); - assert.strictEqual( - query("#navigation-bar li.new").textContent.trim(), - i18n("filters.new.title_with_count", { count: 1 }), - "displays the right content on new link" - ); + assert + .dom("#navigation-bar li.new") + .hasText( + i18n("filters.new.title_with_count", { count: 1 }), + "displays the right content on new link" + ); // simulate reading topic id 1 await publishToMessageBus("/unread", { @@ -229,17 +232,19 @@ acceptance("Topic Discovery Tracked", function (needs) { }, }); - assert.strictEqual( - query("#navigation-bar li.unread").textContent.trim(), - i18n("filters.unread.title_with_count", { count: 2 }), - "displays the right content on unread link" - ); + assert + .dom("#navigation-bar li.unread") + .hasText( + i18n("filters.unread.title_with_count", { count: 2 }), + "displays the right content on unread link" + ); - assert.strictEqual( - query("#navigation-bar li.new").textContent.trim(), - i18n("filters.new.title"), - "displays the right content on new link" - ); + assert + .dom("#navigation-bar li.new") + .hasText( + i18n("filters.new.title"), + "displays the right content on new link" + ); }); test("visit discovery page filtered by tag with tracked filter", async function (assert) { @@ -259,31 +264,35 @@ acceptance("Topic Discovery Tracked", function (needs) { await visit("/tag/some-other-tag"); - assert.strictEqual( - query("#navigation-bar li.unread").textContent.trim(), - i18n("filters.unread.title"), - "displays the right content on unread link" - ); + assert + .dom("#navigation-bar li.unread") + .hasText( + i18n("filters.unread.title"), + "displays the right content on unread link" + ); - assert.strictEqual( - query("#navigation-bar li.new").textContent.trim(), - i18n("filters.new.title_with_count", { count: 1 }), - "displays the right content on new link" - ); + assert + .dom("#navigation-bar li.new") + .hasText( + i18n("filters.new.title_with_count", { count: 1 }), + "displays the right content on new link" + ); await visit("/tag/some-other-tag?f=tracked"); - assert.strictEqual( - query("#navigation-bar li.unread").textContent.trim(), - i18n("filters.unread.title"), - "displays the right content on unread link" - ); + assert + .dom("#navigation-bar li.unread") + .hasText( + i18n("filters.unread.title"), + "displays the right content on unread link" + ); - assert.strictEqual( - query("#navigation-bar li.new").textContent.trim(), - i18n("filters.new.title"), - "displays the right content on new link" - ); + assert + .dom("#navigation-bar li.new") + .hasText( + i18n("filters.new.title"), + "displays the right content on new link" + ); }); test("visit discovery page filtered by category with tracked filter", async function (assert) { @@ -337,30 +346,34 @@ acceptance("Topic Discovery Tracked", function (needs) { await visit(`/c/3`); - assert.strictEqual( - query("#navigation-bar li.unread").textContent.trim(), - i18n("filters.unread.title_with_count", { count: 1 }), - "displays the right content on unread link" - ); + assert + .dom("#navigation-bar li.unread") + .hasText( + i18n("filters.unread.title_with_count", { count: 1 }), + "displays the right content on unread link" + ); - assert.strictEqual( - query("#navigation-bar li.new").textContent.trim(), - i18n("filters.new.title"), - "displays the right content on new link" - ); + assert + .dom("#navigation-bar li.new") + .hasText( + i18n("filters.new.title"), + "displays the right content on new link" + ); await visit(`/c/3?f=tracked`); - assert.strictEqual( - query("#navigation-bar li.unread").textContent.trim(), - i18n("filters.unread.title"), - "displays the right content on unread link" - ); + assert + .dom("#navigation-bar li.unread") + .hasText( + i18n("filters.unread.title"), + "displays the right content on unread link" + ); - assert.strictEqual( - query("#navigation-bar li.new").textContent.trim(), - i18n("filters.new.title"), - "displays the right content on new link" - ); + assert + .dom("#navigation-bar li.new") + .hasText( + i18n("filters.new.title"), + "displays the right content on new link" + ); }); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js index 9d68862931c..7742c21a355 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-test.js @@ -624,9 +624,9 @@ acceptance("Topic stats update automatically", function () { test("Likes count updates automatically", async function (assert) { await visit("/t/internationalization-localization/280"); - const likesCountSelectors = - "#post_1 .topic-map .topic-map__likes-trigger .number"; - const oldLikesCount = query(likesCountSelectors).textContent; + const oldLikesCount = document.querySelector( + "#post_1 .topic-map .topic-map__likes-trigger .number" + ).textContent; const likesChangedFixture = { id: 280, type: "stats", @@ -637,7 +637,9 @@ acceptance("Topic stats update automatically", function () { // simulate the topic like_count being changed await publishToMessageBus("/topic/280", likesChangedFixture); - assert.dom(likesCountSelectors).hasText(expectedLikesCount); + assert + .dom("#post_1 .topic-map .topic-map__likes-trigger .number") + .hasText(expectedLikesCount); assert.notStrictEqual( oldLikesCount, expectedLikesCount, diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-drafts-stream-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-drafts-stream-test.js index 36120181515..e8136860796 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-drafts-stream-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-drafts-stream-test.js @@ -39,10 +39,7 @@ acceptance("User Drafts", function (needs) { test("Stream - has excerpt", async function (assert) { await visit("/u/eviltrout/activity/drafts"); assert.dom(".user-stream-item").exists("has drafts"); - assert.strictEqual( - query(".user-stream-item:nth-child(3) .category").textContent, - "meta" - ); + assert.dom(".user-stream-item:nth-child(3) .category").hasText("meta"); assert .dom(".user-stream-item:nth-child(3) .excerpt") .hasHtml( diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js index eed128ca6ac..078fec6df32 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js @@ -96,14 +96,9 @@ acceptance("User menu", function (needs) { await visit("/"); await click(".d-header-icons .current-user button"); - let repliesBadgeNotification = query( - "#user-menu-button-replies .badge-notification" - ); - assert.strictEqual( - repliesBadgeNotification.textContent.trim(), - "2", - "badge shows the right count" - ); + assert + .dom("#user-menu-button-replies .badge-notification") + .hasText("2", "badge shows the right count"); await click(".user-menu ul li.replied a"); @@ -114,14 +109,9 @@ acceptance("User menu", function (needs) { ); await click(".d-header-icons .current-user button"); - repliesBadgeNotification = query( - "#user-menu-button-replies .badge-notification" - ); - assert.strictEqual( - repliesBadgeNotification.textContent.trim(), - "1", - "badge shows count reduced by one" - ); + assert + .dom("#user-menu-button-replies .badge-notification") + .hasText("1", "badge shows count reduced by one"); }); test("clicking on user menu items", async function (assert) { @@ -131,13 +121,12 @@ acceptance("User menu", function (needs) { await click(".d-header-icons .current-user button"); await click("#user-menu-button-review-queue"); - assert.strictEqual( - query( - "#user-menu-button-review-queue .badge-notification" - ).textContent.trim(), - "8", - "updates user's reviewable count based on request's response" - ); + assert + .dom("#user-menu-button-review-queue .badge-notification") + .hasText( + "8", + "updates user's reviewable count based on request's response" + ); await click("#quick-access-review-queue li.reviewable.pending a"); @@ -317,21 +306,13 @@ acceptance("User menu", function (needs) { "#user-menu-button-custom-tab-1 .badge-notification" ); - assert.strictEqual( - customTab1Bubble.textContent.trim(), - "73", - "bubble shows the right count" - ); + assert.dom(customTab1Bubble).hasText("73", "bubble shows the right count"); const customTab2Bubble = query( "#user-menu-button-custom-tab-2 .badge-notification" ); - assert.strictEqual( - customTab2Bubble.textContent.trim(), - "29", - "bubble shows the right count" - ); + assert.dom(customTab2Bubble).hasText("29", "bubble shows the right count"); await publishToMessageBus(`/notification/${loggedInUser().id}`, { unread_high_priority_notifications: 18, @@ -341,11 +322,12 @@ acceptance("User menu", function (needs) { "#user-menu-button-custom-tab-1 .badge-notification" ); - assert.strictEqual( - customTab1Bubble.textContent.trim(), - "18", - "displayed bubble count updates when the value is changed" - ); + assert + .dom(customTab1Bubble) + .hasText( + "18", + "displayed bubble count updates when the value is changed" + ); await click("#user-menu-button-custom-tab-1"); @@ -375,14 +357,12 @@ acceptance("User menu", function (needs) { const notifications = queryAll( "#quick-access-all-notifications ul li.notification" ); - assert.strictEqual( - notifications[0].textContent.replace(/\s+/g, " ").trim(), - "velesin pluginNotificationTransformer 0 edited topic 443" - ); - assert.strictEqual( - notifications[1].textContent.replace(/\s+/g, " ").trim(), - "velesin pluginNotificationTransformer 1 some title" - ); + assert + .dom(notifications[0]) + .hasText("velesin pluginNotificationTransformer 0 edited topic 443"); + assert + .dom(notifications[1]) + .hasText("velesin pluginNotificationTransformer 1 some title"); }); test("bookmarks tab applies model transformations registered by plugins", async function (assert) { @@ -400,11 +380,9 @@ acceptance("User menu", function (needs) { await click(".d-header-icons .current-user button"); await click("#user-menu-button-bookmarks"); - const bookmarks = queryAll("#quick-access-bookmarks ul li.bookmark"); - assert.strictEqual( - bookmarks[0].textContent.replace(/\s+/g, " ").trim(), - "osama pluginBookmarkTransformer Test poll topic hello world" - ); + assert + .dom("#quick-access-bookmarks ul li.bookmark") + .hasText("osama pluginBookmarkTransformer Test poll topic hello world"); }); test("messages tab applies model transformations registered by plugins", async function (assert) { @@ -427,11 +405,11 @@ acceptance("User menu", function (needs) { await click(".d-header-icons .current-user button"); await click("#user-menu-button-messages"); - const messages = queryAll("#quick-access-messages ul li.message"); - assert.strictEqual( - messages[0].textContent.replace(/\s+/g, " ").trim(), - "mixtape pluginTransformer#2 pluginTransformer#1 BUG: Can not render emoji properly" - ); + assert + .dom("#quick-access-messages ul li.message") + .hasText( + "mixtape pluginTransformer#2 pluginTransformer#1 BUG: Can not render emoji properly" + ); }); test("the profile tab", async function (assert) { @@ -448,11 +426,9 @@ acceptance("User menu", function (needs) { summaryLink.href.endsWith("/u/eviltrout/summary"), "has a link to the summary page of the user" ); - assert.strictEqual( - summaryLink.textContent.trim(), - i18n("user.summary.title"), - "summary link has the right label" - ); + assert + .dom(summaryLink) + .hasText(i18n("user.summary.title"), "summary link has the right label"); assert .dom(".d-icon-user", summaryLink) .exists("summary link has the right icon"); @@ -462,11 +438,12 @@ acceptance("User menu", function (needs) { activityLink.href.endsWith("/u/eviltrout/activity"), "has a link to the activity page of the user" ); - assert.strictEqual( - activityLink.textContent.trim(), - i18n("user.activity_stream"), - "activity link has the right label" - ); + assert + .dom(activityLink) + .hasText( + i18n("user.activity_stream"), + "activity link has the right label" + ); assert .dom(".d-icon-bars-staggered", activityLink) .exists("activity link has the right icon"); @@ -476,11 +453,9 @@ acceptance("User menu", function (needs) { invitesLink.href.endsWith("/u/eviltrout/invited"), "has a link to the invites page of the user" ); - assert.strictEqual( - invitesLink.textContent.trim(), - i18n("user.invited.title"), - "invites link has the right label" - ); + assert + .dom(invitesLink) + .hasText(i18n("user.invited.title"), "invites link has the right label"); assert .dom(".d-icon-user-plus", invitesLink) .exists("invites link has the right icon"); @@ -500,11 +475,12 @@ acceptance("User menu", function (needs) { draftsLink.href.endsWith("/u/eviltrout/activity/drafts"), "has a link to the drafts page of the user" ); - assert.strictEqual( - draftsLink.textContent.trim(), - i18n("drafts.label_with_count", { count: 13 }), - "drafts link has the right label with count of the user's drafts" - ); + assert + .dom(draftsLink) + .hasText( + i18n("drafts.label_with_count", { count: 13 }), + "drafts link has the right label with count of the user's drafts" + ); assert .dom(".d-icon-user_menu\\.drafts", draftsLink) .exists("drafts link has the right icon"); @@ -514,11 +490,12 @@ acceptance("User menu", function (needs) { preferencesLink.href.endsWith("/u/eviltrout/preferences"), "has a link to the preferences page of the user" ); - assert.strictEqual( - preferencesLink.textContent.trim(), - i18n("user.preferences.title"), - "preferences link has the right label" - ); + assert + .dom(preferencesLink) + .hasText( + i18n("user.preferences.title"), + "preferences link has the right label" + ); assert .dom(".d-icon-gear", preferencesLink) .exists("preferences link has the right icon"); @@ -526,14 +503,12 @@ acceptance("User menu", function (needs) { let doNotDisturbButton = query( "#quick-access-profile ul li.do-not-disturb .btn" ); - assert.strictEqual( - doNotDisturbButton.textContent - .replaceAll(/\s+/g, " ") - .replaceAll(/\u200B/g, "") - .trim(), - i18n("pause_notifications.label"), - "Do Not Disturb button has the right label" - ); + assert + .dom(doNotDisturbButton) + .hasText( + i18n("pause_notifications.label"), + "Do Not Disturb button has the right label" + ); assert .dom(".d-icon-toggle-off", doNotDisturbButton) .exists("Do Not Disturb button has the right icon"); @@ -548,14 +523,12 @@ acceptance("User menu", function (needs) { doNotDisturbButton = query( "#quick-access-profile ul li.do-not-disturb .btn" ); - assert.strictEqual( - doNotDisturbButton.textContent - .replaceAll(/\s+/g, " ") - .replaceAll(/\u200B/g, "") - .trim(), - `${i18n("pause_notifications.label")} 2h`, - "Do Not Disturb button has the right label when Do Not Disturb is enabled" - ); + assert + .dom(doNotDisturbButton) + .hasText( + `${i18n("pause_notifications.label")} 2h`, + "Do Not Disturb button has the right label when Do Not Disturb is enabled" + ); assert .dom(".d-icon-toggle-on", doNotDisturbButton) .exists( @@ -568,14 +541,12 @@ acceptance("User menu", function (needs) { let toggleAnonButton = query( "#quick-access-profile ul li.enable-anonymous .btn" ); - assert.strictEqual( - toggleAnonButton.textContent - .replaceAll(/\s+/g, " ") - .replaceAll(/\u200B/g, "") - .trim(), - i18n("switch_to_anon"), - "toggle anonymous button has the right label when the user isn't anonymous" - ); + assert + .dom(toggleAnonButton) + .hasText( + i18n("switch_to_anon"), + "toggle anonymous button has the right label when the user isn't anonymous" + ); assert .dom(".d-icon-user-secret", toggleAnonButton) .exists( @@ -590,14 +561,12 @@ acceptance("User menu", function (needs) { toggleAnonButton = query( "#quick-access-profile ul li.disable-anonymous .btn" ); - assert.strictEqual( - toggleAnonButton.textContent - .replaceAll(/\s+/g, " ") - .replaceAll(/\u200B/g, "") - .trim(), - i18n("switch_from_anon"), - "toggle anonymous button has the right label when the user is anonymous" - ); + assert + .dom(toggleAnonButton) + .hasText( + i18n("switch_from_anon"), + "toggle anonymous button has the right label when the user is anonymous" + ); assert .dom(".d-icon-ban", toggleAnonButton) .exists( @@ -690,14 +659,9 @@ acceptance("User menu", function (needs) { ); const logoutButton = query("#quick-access-profile ul li.logout .btn"); - assert.strictEqual( - logoutButton.textContent - .replaceAll(/\s+/g, " ") - .replaceAll(/\u200B/g, "") - .trim(), - i18n("user.log_out"), - "logout button has the right label" - ); + assert + .dom(logoutButton) + .hasText(i18n("user.log_out"), "logout button has the right label"); assert .dom(".d-icon-right-from-bracket", logoutButton) .exists("logout button has the right icon"); @@ -943,13 +907,12 @@ acceptance("User menu - Dismiss button", function (needs) { await click(".d-header-icons .current-user button"); await click(".user-menu .notifications-dismiss"); - assert.strictEqual( - query( - ".dismiss-notification-confirmation .d-modal__body" - ).textContent.trim(), - i18n("notifications.dismiss_confirmation.body.default", { count: 10 }), - "confirmation modal is shown when there are unread high pri notifications" - ); + assert + .dom(".dismiss-notification-confirmation .d-modal__body") + .hasText( + i18n("notifications.dismiss_confirmation.body.default", { count: 10 }), + "confirmation modal is shown when there are unread high pri notifications" + ); await click(".d-modal__footer .btn-default"); // click cancel on the dismiss modal assert.false(markRead, "mark-read request isn't sent"); @@ -963,11 +926,9 @@ acceptance("User menu - Dismiss button", function (needs) { await visit("/"); await click(".d-header-icons .current-user button"); - assert.strictEqual( - query("#user-menu-button-bookmarks .badge-notification").textContent, - "103", - "bookmarks tab has bubble with count" - ); + assert + .dom("#user-menu-button-bookmarks .badge-notification") + .hasText("103", "bookmarks tab has bubble with count"); await click("#user-menu-button-bookmarks"); assert @@ -979,10 +940,7 @@ acceptance("User menu - Dismiss button", function (needs) { await click(".user-menu .notifications-dismiss"); - assert.strictEqual( - query( - ".dismiss-notification-confirmation .d-modal__body" - ).textContent.trim(), + assert.dom(".dismiss-notification-confirmation .d-modal__body").hasText( i18n("notifications.dismiss_confirmation.body.bookmarks", { count: 103, }), @@ -1014,11 +972,9 @@ acceptance("User menu - Dismiss button", function (needs) { await visit("/"); await click(".d-header-icons .current-user button"); - assert.strictEqual( - query("#user-menu-button-messages .badge-notification").textContent, - "89", - "messages tab has bubble with count" - ); + assert + .dom("#user-menu-button-messages .badge-notification") + .hasText("89", "messages tab has bubble with count"); await click("#user-menu-button-messages"); assert @@ -1030,10 +986,7 @@ acceptance("User menu - Dismiss button", function (needs) { await click(".user-menu .notifications-dismiss"); - assert.strictEqual( - query( - ".dismiss-notification-confirmation .d-modal__body" - ).textContent.trim(), + assert.dom(".dismiss-notification-confirmation .d-modal__body").hasText( i18n("notifications.dismiss_confirmation.body.messages", { count: 89, }), @@ -1081,11 +1034,9 @@ acceptance("User menu - Dismiss button", function (needs) { let othersBadgeNotification = query( "#user-menu-button-other-notifications .badge-notification" ); - assert.strictEqual( - othersBadgeNotification.textContent.trim(), - "4", - "badge shows the right count" - ); + assert + .dom(othersBadgeNotification) + .hasText("4", "badge shows the right count"); await click(".user-menu .notifications-dismiss"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js index 46664b0318a..e5ec447c3bf 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-account-test.js @@ -6,7 +6,7 @@ import pretender, { fixturesByUrl, response, } from "discourse/tests/helpers/create-pretender"; -import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { cloneJSON } from "discourse-common/lib/object"; import { i18n } from "discourse-i18n"; @@ -100,11 +100,9 @@ acceptance("User Preferences - Account", function (needs) { await click(".delete-account .btn-danger"); await click(".dialog-footer .btn-danger"); - assert.strictEqual( - query(".dialog-body").textContent.trim(), - i18n("user.deleted_yourself"), - "confirmation dialog is shown" - ); + assert + .dom(".dialog-body") + .hasText(i18n("user.deleted_yourself"), "confirmation dialog is shown"); await click(".dialog-footer .btn-primary"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js index a7dc6504c57..21329f8cf70 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js @@ -11,7 +11,6 @@ import { fixturesByUrl } from "discourse/tests/helpers/create-pretender"; import { acceptance, publishToMessageBus, - query, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; import { cloneJSON } from "discourse-common/lib/object"; @@ -567,11 +566,9 @@ acceptance( await visit("/u/charlie/messages"); - assert.strictEqual( - query(".topic-post-badges").textContent.trim(), - "", - "does not display unread posts count badge" - ); + assert + .dom(".topic-post-badges") + .hasText("", "does not display unread posts count badge"); } finally { resetHighestReadCache(); } @@ -584,11 +581,9 @@ acceptance( .dom(".topic-list-item") .exists({ count: 3 }, "displays the right topic list"); - assert.strictEqual( - query(`tr[data-topic-id="1"] .topic-post-badges`).textContent.trim(), - "1", - "displays the right unread posts count badge" - ); + assert + .dom(`tr[data-topic-id="1"] .topic-post-badges`) + .hasText(/1/, "displays the right unread posts count badge"); await visit("/u/charlie/messages/group/awesome_group"); diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-test.js index 57fdfbb78a9..05de5852a3f 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-test.js @@ -11,7 +11,6 @@ import userFixtures from "discourse/tests/fixtures/user-fixtures"; import { acceptance, publishToMessageBus, - query, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; import selectKit from "discourse/tests/helpers/select-kit-helper"; @@ -131,16 +130,14 @@ acceptance( test("Periods in current user's username don't act like wildcards", async function (assert) { await visit("/u/eviltrout"); - assert.strictEqual( - query(".user-profile-names .username").textContent.trim(), + assert.dom(".user-profile-names .username").hasText( `eviltrout Robin Ward is an admin`, "eviltrout profile is shown" ); await visit("/u/e.il.rout"); - assert.strictEqual( - query(".user-profile-names .username").textContent.trim(), + assert.dom(".user-profile-names .username").hasText( `e.il.rout Robin Ward is an admin`, "e.il.rout profile is shown" diff --git a/app/assets/javascripts/discourse/tests/acceptance/users-test.js b/app/assets/javascripts/discourse/tests/acceptance/users-test.js index b319ab6465f..4e1a4db242b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/users-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/users-test.js @@ -2,11 +2,7 @@ import { click, triggerKeyEvent, visit } from "@ember/test-helpers"; import { test } from "qunit"; import directoryFixtures from "discourse/tests/fixtures/directory-fixtures"; import pretender, { response } from "discourse/tests/helpers/create-pretender"; -import { - acceptance, - query, - queryAll, -} from "discourse/tests/helpers/qunit-helpers"; +import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers"; import { cloneJSON } from "discourse-common/lib/object"; import { i18n } from "discourse-i18n"; @@ -91,11 +87,11 @@ acceptance("User Directory", function () { test("Custom user fields are present", async function (assert) { await visit("/u"); - const firstRowUserField = query( - ".directory .directory-table__body .directory-table__row:first-child .directory-table__value--user-field" - ); - - assert.strictEqual(firstRowUserField.textContent.trim(), "Blue"); + assert + .dom( + ".directory .directory-table__body .directory-table__row:first-child .directory-table__value--user-field" + ) + .hasText("Blue"); }); test("Can sort table via keyboard", async function (assert) { @@ -185,27 +181,15 @@ acceptance("User directory - Editing columns", function (needs) { let columns; columns = fetchColumns(); - assert.strictEqual( - columns[3].querySelector(".column-name").textContent.trim(), - "Replies Posted" - ); - assert.strictEqual( - columns[4].querySelector(".column-name").textContent.trim(), - "Topics Viewed" - ); + assert.dom(".column-name", columns[3]).hasText("Replies Posted"); + assert.dom(".column-name", columns[4]).hasText("Topics Viewed"); // Click on row 4 and see if they are swapped await click(columns[4].querySelector(".move-column-up")); columns = fetchColumns(); - assert.strictEqual( - columns[3].querySelector(".column-name").textContent.trim(), - "Topics Viewed" - ); - assert.strictEqual( - columns[4].querySelector(".column-name").textContent.trim(), - "Replies Posted" - ); + assert.dom(".column-name", columns[3]).hasText("Topics Viewed"); + assert.dom(".column-name", columns[4]).hasText("Replies Posted"); const moveUserFieldColumnUpBtn = columns[columns.length - 1].querySelector(".move-column-up"); @@ -215,14 +199,8 @@ acceptance("User directory - Editing columns", function (needs) { await click(moveUserFieldColumnUpBtn); columns = fetchColumns(); - assert.strictEqual( - columns[4].querySelector(".column-name").textContent.trim(), - "Favorite Color" - ); - assert.strictEqual( - columns[5].querySelector(".column-name").textContent.trim(), - "Replies Posted" - ); + assert.dom(".column-name", columns[4]).hasText("Favorite Color"); + assert.dom(".column-name", columns[5]).hasText("Replies Posted"); // Now click restore default and check order of column names await click(".reset-to-default"); diff --git a/app/assets/javascripts/discourse/tests/integration/components/admin-plugin-config-area-test.js b/app/assets/javascripts/discourse/tests/integration/components/admin-plugin-config-area-test.js index c1a0c292828..a0fe94581f8 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/admin-plugin-config-area-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/admin-plugin-config-area-test.js @@ -37,17 +37,16 @@ module("Integration | Component | admin-plugin-config-area", function (hooks) { `); - assert.strictEqual( - document.querySelectorAll(".admin-plugin-inner-sidebar-nav__item").length, - 3, - "it renders the correct number of sidebar nav items (including always adding a Settings link)" - ); + assert + .dom(".admin-plugin-inner-sidebar-nav__item") + .exists( + { count: 3 }, + "renders the correct number of sidebar nav items (including always adding a Settings link)" + ); - assert.strictEqual( - document.querySelector(".admin-plugin-config-area").textContent.trim(), - "Test content", - "it renders the yielded content" - ); + assert + .dom(".admin-plugin-config-area") + .hasText("Test content", "renders the yielded content"); }); test("it does not render the nav items in the sidebar when using top mode but it does along the top", async function (assert) { @@ -70,16 +69,12 @@ module("Integration | Component | admin-plugin-config-area", function (hooks) { `); - assert.strictEqual( - document.querySelectorAll(".admin-plugin-inner-sidebar-nav__item").length, - 0, - "it renders the correct number of sidebar nav items" - ); + assert + .dom(".admin-plugin-inner-sidebar-nav__item") + .doesNotExist("renders the correct number of sidebar nav items"); - assert.strictEqual( - document.querySelector(".admin-plugin-config-area").textContent.trim(), - "Test content", - "it renders the yielded content" - ); + assert + .dom(".admin-plugin-config-area") + .hasText("Test content", "renders the yielded content"); }); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/d-navigation-test.js b/app/assets/javascripts/discourse/tests/integration/components/d-navigation-test.js index 37b4bd63c6d..0ba274c495e 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/d-navigation-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/d-navigation-test.js @@ -2,7 +2,6 @@ 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 { query } from "discourse/tests/helpers/qunit-helpers"; module("Integration | Component | d-navigation", function (hooks) { setupRenderingTest(hooks); @@ -26,9 +25,6 @@ module("Integration | Component | d-navigation", function (hooks) { assert .dom(".category-row") .exists({ count: 1 }, "displays only categories that are not muted"); - assert.strictEqual( - query(".category-row .badge-category span").textContent.trim(), - "dev" - ); + assert.dom(".category-row .badge-category span").hasText("dev"); }); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js b/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js index 9631e70ba4b..68c8713276c 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js @@ -3,7 +3,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"; module("Integration | Component | pending-post", function (hooks) { setupRenderingTest(hooks); @@ -22,10 +21,6 @@ module("Integration | Component | pending-post", function (hooks) { await render(hbs``); - assert.strictEqual( - query("p.excerpt").textContent.trim(), - "bold text", - "renders the cooked text" - ); + assert.dom("p.excerpt").hasText("bold text", "renders the cooked text"); }); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs index 19784b976a0..074ccda4982 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs +++ b/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs @@ -46,11 +46,12 @@ module("Integration | Component | search-menu", function (hooks) { await fillIn("#search-term", "test"); - assert.strictEqual( - query(".label-suffix").textContent.trim(), - i18n("search.in_topics_posts"), - "search label reflects context of search" - ); + assert + .dom(".label-suffix") + .hasText( + i18n("search.in_topics_posts"), + "search label reflects context of search" + ); await triggerKeyEvent("#search-term", "keyup", "Enter"); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js index db582d6d069..2e02401035a 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js @@ -148,10 +148,7 @@ module( await render( hbs`` ); - assert.strictEqual( - query(".formatted-selection").textContent.trim(), - "bar" - ); + assert.dom(".formatted-selection").hasText("bar"); await this.subject.expand(); assert.deepEqual( diff --git a/app/assets/javascripts/discourse/tests/integration/components/user-menu/bookmarks-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/user-menu/bookmarks-list-test.js index 1a9b40eaf52..c4d9ff812bd 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/user-menu/bookmarks-list-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/user-menu/bookmarks-list-test.js @@ -4,7 +4,7 @@ import { module, test } from "qunit"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import pretender, { response } from "discourse/tests/helpers/create-pretender"; -import { query, queryAll } from "discourse/tests/helpers/qunit-helpers"; +import { queryAll } from "discourse/tests/helpers/qunit-helpers"; import { i18n } from "discourse-i18n"; module( @@ -71,16 +71,15 @@ module( return response({ notifications: [], bookmarks: [] }); }); await render(template); - assert.strictEqual( - query(".empty-state-title").textContent.trim(), - i18n("user.no_bookmarks_title"), - "empty state title is shown" - ); - assert.strictEqual( - query(".empty-state-body").textContent.trim(), - i18n("user.no_bookmarks_body", { icon: "" }).trim(), - "empty state body is shown" - ); + assert + .dom(".empty-state-title") + .hasText(i18n("user.no_bookmarks_title"), "empty state title is shown"); + assert + .dom(".empty-state-body") + .hasText( + i18n("user.no_bookmarks_body", { icon: "" }), + "empty state body is shown" + ); assert .dom(".empty-state-body svg.d-icon-bookmark") .exists("icon is correctly rendered in the empty state body"); diff --git a/app/assets/javascripts/discourse/tests/integration/components/user-menu/likes-list-test.js b/app/assets/javascripts/discourse/tests/integration/components/user-menu/likes-list-test.js index d87d917ba5a..6157158d6d7 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/user-menu/likes-list-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/user-menu/likes-list-test.js @@ -3,7 +3,6 @@ import { hbs } from "ember-cli-htmlbars"; import { module, test } from "qunit"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import pretender, { response } from "discourse/tests/helpers/create-pretender"; -import { query } from "discourse/tests/helpers/qunit-helpers"; import { i18n } from "discourse-i18n"; module( @@ -11,19 +10,19 @@ module( function (hooks) { setupRenderingTest(hooks); - const template = hbs``; test("empty state (aka blank page syndrome)", async function (assert) { pretender.get("/notifications", () => { return response({ notifications: [] }); }); - await render(template); + await render(hbs``); - assert.strictEqual( - query(".empty-state-title").textContent.trim(), - i18n("user.no_likes_title"), - "empty state title for the likes tab is shown" - ); + assert + .dom(".empty-state-title") + .hasText( + i18n("user.no_likes_title"), + "empty state title for the likes tab is shown" + ); assert .dom(".empty-state-body a") .hasAttribute( diff --git a/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-item-test.js b/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-item-test.js index aa50fab6965..64d677c99ec 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-item-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-item-test.js @@ -11,7 +11,6 @@ import UserMenuReviewable from "discourse/models/user-menu-reviewable"; import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types"; import PrivateMessagesFixture from "discourse/tests/fixtures/private-messages-fixtures"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; -import { query } from "discourse/tests/helpers/qunit-helpers"; import { cloneJSON, deepMerge } from "discourse-common/lib/object"; import { i18n } from "discourse-i18n"; @@ -163,20 +162,17 @@ module( getNotification(this.currentUser, this.siteSettings, this.site) ); await render(template); - const label = query("li a .item-label"); - const description = query("li a .item-description"); - assert.strictEqual( - label.textContent.trim(), - "osama", - "the label's content is the username by default" - ); + assert + .dom("li a .item-label") + .hasText("osama", "the label's content is the username by default"); - assert.strictEqual( - description.textContent.trim(), - "This is fancy title !", - "the description defaults to the fancy_title" - ); + assert + .dom("li a .item-description") + .hasText( + "This is fancy title !", + "the description defaults to the fancy_title" + ); }); test("the description falls back to topic_title from data if fancy_title is absent", async function (assert) { @@ -187,13 +183,13 @@ module( }) ); await render(template); - const description = query("li a .item-description"); - assert.strictEqual( - description.textContent.trim(), - "this is title before it becomes fancy !", - "topic_title from data is rendered safely" - ); + assert + .dom("li a .item-description") + .hasText( + "this is title before it becomes fancy !", + "topic_title from data is rendered safely" + ); }); test("fancy_title is emoji-unescaped", async function (assert) { @@ -222,13 +218,13 @@ module( }) ); await render(template); - const description = query("li a .item-description"); - assert.strictEqual( - description.textContent.trim(), - "unsafe title with unescaped emoji", - "topic_title is rendered safely" - ); + assert + .dom("li a .item-description") + .hasText( + "unsafe title with unescaped emoji", + "topic_title is rendered safely" + ); assert .dom(".item-description img.emoji") .exists("emoji is rendered correctly"); @@ -305,20 +301,22 @@ module( assert .dom("li .item-label") .hasClass("label-wrapper-1", "label wrapper has additional classes"); - assert.strictEqual( - query("li .item-label").textContent.trim(), - "notification label 666 ", - "label content is customized" - ); + assert + .dom("li .item-label") + .hasText( + "notification label 666 ", + "label content is customized" + ); assert .dom(".item-description") .hasClass("description-class-1", "description has additional classes"); - assert.strictEqual( - query(".item-description").textContent.trim(), - "notification description 123