From b81055a6d45419557a705dad1076e6eb09ef55da Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Sun, 3 Nov 2024 21:04:38 +0100 Subject: [PATCH] DEV: Convert more `equal` assertions (#29554) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …to either qunit-dom or `strictEqual` --- .../acceptance/admin-site-settings-test.js | 2 +- .../tests/acceptance/admin-users-list-test.js | 5 +-- .../composer-editor-mentions-test.js | 10 ++--- .../tests/acceptance/flag-post-test.js | 17 +++---- .../group-manage-membership-test.js | 5 ++- .../acceptance/post-inline-mentions-test.js | 8 ++-- .../sidebar-user-community-section-test.js | 2 +- .../discourse/tests/acceptance/themes-test.js | 8 ++-- .../user-preferences-account-test.js | 5 +-- .../form-template-field/wrapper-test.js | 19 ++++---- .../components/number-field-test.js | 10 ++--- .../select-kit/category-selector-test.js | 6 +-- .../email-group-user-chooser-test.js | 18 +++----- .../select-kit/mini-tag-chooser-test.js | 2 +- .../select-kit/multi-select-test.js | 2 +- .../controllers/admin-user-badges-test.js | 8 ++-- .../tests/unit/lib/case-converter-test.js | 27 +++++++----- .../tests/unit/lib/download-calendar-test.js | 4 +- .../tests/unit/lib/formatter-test.js | 6 +-- .../discourse/tests/unit/lib/text-test.js | 2 +- .../tests/unit/models/category-test.js | 4 +- .../tests/unit/models/composer-test.js | 6 +-- .../unit/models/topic-tracking-state-test.js | 2 +- .../da-email-group-user-field-test.js | 4 +- .../acceptance/chat-composer-test.js | 2 +- .../components/chat-channel-test.js | 22 +++++----- ...date-test.js => format-chat-date-test.gjs} | 33 +++++++------- .../unit/helpers/tonable-emoji-title-test.gjs | 41 +++++++++++++++++ .../unit/helpers/tonable-emoji-title-test.js | 44 ------------------- .../unit/lib/chat-composer-buttons-test.js | 4 +- .../unit/lib/slugify-channel-test.js | 10 ++--- .../unit/utility/plugin-api-test.js | 5 ++- .../unit/discourse-local-dates-test.js | 20 ++------- 33 files changed, 165 insertions(+), 198 deletions(-) rename plugins/chat/test/javascripts/unit/helpers/{format-chat-date-test.js => format-chat-date-test.gjs} (52%) create mode 100644 plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.gjs delete mode 100644 plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.js diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js index d34f8e11ac1..41d97e1f4bc 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/admin-site-settings-test.js @@ -198,7 +198,7 @@ acceptance("Admin - Site Settings", function (needs) { const navItems = queryAll(".admin-nav .nav-stacked li a"); navItems.each((_, item) => { - assert.equal( + assert.strictEqual( item.title, item.innerText, "menu item has title, and the title is equal to menu item's label" diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-users-list-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-users-list-test.js index b068ccd111e..db21edca809 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/admin-users-list-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/admin-users-list-test.js @@ -22,10 +22,7 @@ acceptance("Admin - Users List", function (needs) { await fillIn(".controls.username input", "doesntexist"); - assert.equal( - query(".users-list-container").innerText, - I18n.t("search.no_results") - ); + assert.dom(".users-list-container").hasText(I18n.t("search.no_results")); }); test("sorts users", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js index 40e9a5ac8b6..08e8b860fb5 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-editor-mentions-test.js @@ -119,13 +119,9 @@ acceptance("Composer - editor mentions", function (needs) { .dom(`.autocomplete .emoji[alt='${status.emoji}']`) .exists("status emoji is shown"); - assert.equal( - query( - ".autocomplete .user-status-message-description" - ).textContent.trim(), - status.description, - "status description is shown" - ); + assert + .dom(".autocomplete .user-status-message-description") + .hasText(status.description, "status description is shown"); }); test("metadata matches are moved to the end", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.js b/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.js index 592f6af5b50..e0d577619e8 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/flag-post-test.js @@ -125,11 +125,7 @@ acceptance("flagging", function (needs) { await selectKit(".reviewable-action-dropdown").expand(); await click("[data-value='agree_and_silence']"); assert.ok(exists(".silence-user-modal"), "it shows the silence modal"); - assert.equal( - query(".suspend-message").value, - "", - "penalty message is empty" - ); + assert.dom(".suspend-message").hasValue("", "penalty message is empty"); const silenceUntilCombobox = selectKit(".silence-until .combobox"); await silenceUntilCombobox.expand(); await silenceUntilCombobox.selectRowByValue("tomorrow"); @@ -148,11 +144,12 @@ acceptance("flagging", function (needs) { await selectKit(".reviewable-action-dropdown").expand(); await click("[data-value='agree_and_silence']"); assert.ok(exists(".silence-user-modal"), "it shows the silence modal"); - assert.equal( - query(".suspend-message").value, - "-------------------\n

Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?

\n-------------------", - "penalty message is prefilled with post text" - ); + assert + .dom(".suspend-message") + .hasValue( + "-------------------\n

Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?

\n-------------------", + "penalty message is prefilled with post text" + ); }); test("Can delete spammer from spam", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/group-manage-membership-test.js b/app/assets/javascripts/discourse/tests/acceptance/group-manage-membership-test.js index bc8f3963835..fb2c4faed45 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/group-manage-membership-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/group-manage-membership-test.js @@ -121,7 +121,10 @@ acceptance("Managing Group Membership", function (needs) { await associatedGroups.selectRowByName("google_oauth2:test-group"); await associatedGroups.keyboard("enter"); - assert.equal(associatedGroups.header().name(), "google_oauth2:test-group"); + assert.strictEqual( + associatedGroups.header().name(), + "google_oauth2:test-group" + ); }); test("As an admin on a site that can't associate groups", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/post-inline-mentions-test.js b/app/assets/javascripts/discourse/tests/acceptance/post-inline-mentions-test.js index 67550e8c2c8..09135e0c507 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/post-inline-mentions-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/post-inline-mentions-test.js @@ -177,11 +177,9 @@ acceptance("Post inline mentions – user status tooltip", function (needs) { statusTooltip.querySelector("img").src.includes(status.emoji), "emoji is correct" ); - assert.equal( - statusTooltip.querySelector(".user-status-tooltip-description").innerText, - status.description, - "status description is correct" - ); + assert + .dom(".user-status-tooltip-description", statusTooltip) + .hasText(status.description, "status description is correct"); }); }); 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 0e297efa520..74bbfc53ccd 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 @@ -801,7 +801,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { "shows suffix indicator for new topics on categories link" ); - assert.equal( + assert.strictEqual( Object.keys(topicTrackingState.stateChangeCallbacks).length, initialCallbackCount, "it does not add a new topic tracking state callback when the topic is read" diff --git a/app/assets/javascripts/discourse/tests/acceptance/themes-test.js b/app/assets/javascripts/discourse/tests/acceptance/themes-test.js index 11455bc1495..da17793fbb5 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/themes-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/themes-test.js @@ -222,11 +222,9 @@ acceptance("Theme", function (needs) { await click(".control-unit .btn-primary.finish-install"); - assert.equal( - query(".show-current-style .title span").innerText, - "discourse-complete-theme", - "it updates theme title" - ); + assert + .dom(".show-current-style .title span") + .hasText("discourse-complete-theme", "it updates theme title"); assert.notOk( query(".metadata.control-unit").innerText.includes( 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 16af126495e..a4ea4aa695e 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 @@ -308,10 +308,7 @@ acceptance("User Preferences — Account - Download Archive", function (needs) { await click(".btn-request-archive"); await click("#dialog-holder .btn-primary"); - assert.equal( - query(".dialog-body").innerText.trim(), - I18n.t("user.download_archive.success") - ); + assert.dom(".dialog-body").hasText(I18n.t("user.download_archive.success")); await click("#dialog-holder .btn-primary"); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/form-template-field/wrapper-test.js b/app/assets/javascripts/discourse/tests/integration/components/form-template-field/wrapper-test.js index 661ef75e61a..230b50ddfa6 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/form-template-field/wrapper-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/form-template-field/wrapper-test.js @@ -3,7 +3,7 @@ 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 { exists, query } from "discourse/tests/helpers/qunit-helpers"; +import { exists } from "discourse/tests/helpers/qunit-helpers"; module( "Integration | Component | form-template-field | wrapper", @@ -60,26 +60,23 @@ module( - type: multi-select\n id: multi\n choices:\n - "Option 1"\n - "Option 2"\n - "Option 3"`; this.set("content", content); - const initialValues = { + this.set("initialValues", { checkbox: "on", name: "Test Name", notes: "Test Notes", dropdown: "Option 1", multi: ["Option 1"], - }; - this.set("initialValues", initialValues); + }); await render( hbs`` ); - Object.keys(initialValues).forEach((componentId) => { - assert.equal( - query(`[name='${componentId}']`).value, - initialValues[componentId], - `${componentId} component has initial value` - ); - }); + assert.dom("[name='checkbox']").hasValue("on"); + assert.dom("[name='name']").hasValue("Test Name"); + assert.dom("[name='notes']").hasValue("Test Notes"); + assert.dom("[name='dropdown']").hasValue("Option 1"); + assert.dom("[name='multi']").hasValue("Option 1"); }); test("renders a component based on the component type found in the content YAML when passed ids", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js b/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js index 2141eb4f9fb..d132e370e68 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/number-field-test.js @@ -18,7 +18,7 @@ module("Integration | Component | number-field", function (hooks) { await fillIn(".number-field-test", "33"); - assert.equal( + assert.strictEqual( this.get("value"), 33, "value is changed when the input is a valid number" @@ -27,7 +27,7 @@ module("Integration | Component | number-field", function (hooks) { await fillIn(".number-field-test", ""); await triggerKeyEvent(".number-field-test", "keydown", 66); // b - assert.equal( + assert.strictEqual( this.get("value"), "", "value is cleared when the input is NaN" @@ -46,7 +46,7 @@ module("Integration | Component | number-field", function (hooks) { await triggerKeyEvent(".number-field-test", "keydown", 189); // - await triggerKeyEvent(".number-field-test", "keydown", 49); // 1 - assert.equal( + assert.strictEqual( this.get("value"), "", "value is cleared when the input is less than the min" @@ -60,9 +60,9 @@ module("Integration | Component | number-field", function (hooks) { await fillIn(".number-field-test", "-1"); - assert.equal( + assert.strictEqual( this.get("value"), - "-1", + -1, "negative input allowed when min is negative" ); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-selector-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-selector-test.js index 2ec3084867c..98a67e88475 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-selector-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-selector-test.js @@ -43,12 +43,12 @@ module( await this.subject.expand(); await this.subject.fillInFilter("Parent Category"); - assert.equal(this.subject.rows().length, 2); - assert.equal( + assert.strictEqual(this.subject.rows().length, 2); + assert.strictEqual( this.subject.rowByIndex(0).el().innerText.replace("\n", " "), "Parent Category × 95" ); - assert.equal( + assert.strictEqual( this.subject.rowByIndex(1).el().innerText.replaceAll("\n", " "), "Parent Category × 95 +2 subcategories" ); diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/email-group-user-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/email-group-user-chooser-test.js index bf192214cf5..7ba5a345e0b 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/email-group-user-chooser-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/email-group-user-chooser-test.js @@ -133,18 +133,12 @@ module( await fillIn(".filter-input", "test-user"); assert.ok(exists(".user-status-message"), "user status is rendered"); - assert.equal( - query(".user-status-message .emoji").alt, - status.emoji, - "status emoji is correct" - ); - assert.equal( - query( - ".user-status-message .user-status-message-description" - ).innerText.trim(), - status.description, - "status description is correct" - ); + assert + .dom(".user-status-message .emoji") + .hasAttribute("alt", status.emoji, "status emoji is correct"); + assert + .dom(".user-status-message .user-status-message-description") + .hasText(status.description, "status description is correct"); }); } ); 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 beaeac77581..2f3bea79758 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 @@ -130,7 +130,7 @@ module( await this.subject.fillInFilter("test"); - assert.equal(this.subject.filter().value(), "#test"); + assert.strictEqual(this.subject.filter().value(), "#test"); assert.ok( exists(".select-kit-row[data-value='test']"), "it filters out the invalid char from the suggested tag" diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js index 7c58fc07ec0..19a6e470007 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/multi-select-test.js @@ -116,7 +116,7 @@ module("Integration | Component | select-kit/multi-select", function (hooks) { await this.subject.expand(); await paste(query(".filter-input"), "foo|bar"); - assert.equal(this.subject.header().value(), "1,2"); + assert.strictEqual(this.subject.header().value(), "1,2"); }); test("no value property with no content", async function (assert) { diff --git a/app/assets/javascripts/discourse/tests/unit/controllers/admin-user-badges-test.js b/app/assets/javascripts/discourse/tests/unit/controllers/admin-user-badges-test.js index f43e95d2bc0..c53fd52c0b5 100644 --- a/app/assets/javascripts/discourse/tests/unit/controllers/admin-user-badges-test.js +++ b/app/assets/javascripts/discourse/tests/unit/controllers/admin-user-badges-test.js @@ -107,9 +107,9 @@ module("Unit | Controller | admin-user-badges", function (hooks) { GrantBadgeStub.calledWith(badgeToGrant.id, user.username, badgeReason) ); - assert.equal(controller.badgeReason, ""); - assert.equal(controller.userBadges.length, 1); - assert.equal(controller.userBadges[0].id, newUserBadge.id); - assert.equal(controller.selectedBadgeId, otherBadge.id); + assert.strictEqual(controller.badgeReason, ""); + assert.strictEqual(controller.userBadges.length, 1); + assert.strictEqual(controller.userBadges[0].id, newUserBadge.id); + assert.strictEqual(controller.selectedBadgeId, otherBadge.id); }); }); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/case-converter-test.js b/app/assets/javascripts/discourse/tests/unit/lib/case-converter-test.js index a398749fa91..662ba44ccdf 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/case-converter-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/case-converter-test.js @@ -10,23 +10,26 @@ module("Unit | discourse-common | case-converter", function (hooks) { setupTest(hooks); test("camelCaseToSnakeCase", function (assert) { - assert.equal(camelCaseToSnakeCase("camelCase"), "camel_case"); - assert.equal(camelCaseToSnakeCase("camelCase99"), "camel_case99"); - assert.equal(camelCaseToSnakeCase("camelCaseId"), "camel_case_id"); - assert.equal(camelCaseToSnakeCase("camelCaseUrl"), "camel_case_url"); + assert.strictEqual(camelCaseToSnakeCase("camelCase"), "camel_case"); + assert.strictEqual(camelCaseToSnakeCase("camelCase99"), "camel_case99"); + assert.strictEqual(camelCaseToSnakeCase("camelCaseId"), "camel_case_id"); + assert.strictEqual(camelCaseToSnakeCase("camelCaseUrl"), "camel_case_url"); }); test("camelCaseToDash", function (assert) { - assert.equal(camelCaseToDash("camelCase"), "camel-case"); - assert.equal(camelCaseToDash("camelCaseToDash99"), "camel-case-to-dash99"); - assert.equal(camelCaseToDash("camelCaseId"), "camel-case-id"); - assert.equal(camelCaseToDash("camelCaseUrl"), "camel-case-url"); + assert.strictEqual(camelCaseToDash("camelCase"), "camel-case"); + assert.strictEqual( + camelCaseToDash("camelCaseToDash99"), + "camel-case-to-dash99" + ); + assert.strictEqual(camelCaseToDash("camelCaseId"), "camel-case-id"); + assert.strictEqual(camelCaseToDash("camelCaseUrl"), "camel-case-url"); }); test("snakeCaseToCamelCase", function (assert) { - assert.equal(snakeCaseToCamelCase("snake_case"), "snakeCase"); - assert.equal(snakeCaseToCamelCase("snake_case99"), "snakeCase99"); - assert.equal(snakeCaseToCamelCase("some_id"), "someId"); - assert.equal(snakeCaseToCamelCase("some_url"), "someUrl"); + assert.strictEqual(snakeCaseToCamelCase("snake_case"), "snakeCase"); + assert.strictEqual(snakeCaseToCamelCase("snake_case99"), "snakeCase99"); + assert.strictEqual(snakeCaseToCamelCase("some_id"), "someId"); + assert.strictEqual(snakeCaseToCamelCase("some_url"), "someUrl"); }); }); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js b/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js index c2171f6fe61..28ad1797d14 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js @@ -39,7 +39,7 @@ module("Unit | Utility | download-calendar", function (hooks) { } ); - assert.equal( + assert.strictEqual( data, `BEGIN:VCALENDAR VERSION:2.0 @@ -76,7 +76,7 @@ END:VCALENDAR` ], { recurrenceRule: "FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR" } ); - assert.equal( + assert.strictEqual( data, `BEGIN:VCALENDAR VERSION:2.0 diff --git a/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js b/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js index 9751d9d9b58..fb3c2bbb373 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/formatter-test.js @@ -492,14 +492,14 @@ module("Unit | Utility | formatter | until", function (hooks) { const timezone = "UTC"; this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone); const result = until("2100-01-01 13:00:00.000Z", timezone, "en"); - assert.equal(result, "Until: 1:00 PM"); + assert.strictEqual(result, "Until: 1:00 PM"); }); test("shows date if until moment is tomorrow", function (assert) { const timezone = "UTC"; this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone); const result = until("2100-01-02 12:00:00.000Z", timezone, "en"); - assert.equal(result, "Until: Jan 2"); + assert.strictEqual(result, "Until: Jan 2"); }); test("shows until moment in user's timezone", function (assert) { @@ -510,6 +510,6 @@ module("Unit | Utility | formatter | until", function (hooks) { this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone); const result = until(`2100-01-01 ${untilUTC}:00.000Z`, timezone, "en"); - assert.equal(result, `Until: ${untilTbilisi}`); + assert.strictEqual(result, `Until: ${untilTbilisi}`); }); }); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/text-test.js index 007aef339ae..c311a032486 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/text-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/text-test.js @@ -70,6 +70,6 @@ module("Unit | Utility | text | parseMentions", function (hooks) { \`\`\` `; const mentions = await parseMentions(markdown); - assert.equal(mentions.length, 0); + assert.strictEqual(mentions.length, 0); }); }); diff --git a/app/assets/javascripts/discourse/tests/unit/models/category-test.js b/app/assets/javascripts/discourse/tests/unit/models/category-test.js index 55527398239..d9755da7954 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/category-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/category-test.js @@ -28,8 +28,8 @@ module("Unit | Model | category", function (hooks) { }); assert.deepEqual(foo.subcategories, [bar, baz]); - assert.equal(bar.parentCategory, foo); - assert.equal(baz.parentCategory, foo); + assert.strictEqual(bar.parentCategory, foo); + assert.strictEqual(baz.parentCategory, foo); }); test("slugFor", function (assert) { diff --git a/app/assets/javascripts/discourse/tests/unit/models/composer-test.js b/app/assets/javascripts/discourse/tests/unit/models/composer-test.js index 603d6d0c2a6..2e093e374e5 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/composer-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/composer-test.js @@ -454,7 +454,7 @@ module("Unit | Model | composer", function (hooks) { pretender.post("/posts", function (request) { const data = parsePostData(request.requestBody); - assert.equal(data.meta_data.some_custom_field, "some_value"); + assert.strictEqual(data.meta_data.some_custom_field, "some_value"); saved = true; return response(200, { @@ -478,11 +478,11 @@ module("Unit | Model | composer", function (hooks) { draftSequence: 1, }); - assert.equal(composer.loading, false); + assert.false(composer.loading); composer.metaData = { some_custom_field: "some_value" }; await composer.save({}); - assert.equal(saved, true); + assert.true(saved); }); }); diff --git a/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js b/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js index de3be8c9740..539c1c63e20 100644 --- a/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js +++ b/app/assets/javascripts/discourse/tests/unit/models/topic-tracking-state-test.js @@ -373,7 +373,7 @@ module("Unit | Model | topic-tracking-state", function (hooks) { "expect state for topic 111 to be deleted" ); - assert.equal( + assert.strictEqual( stateChangeCallbackCalledTimes, 1, "callback is only called once" diff --git a/plugins/automation/test/javascripts/integration/components/da-email-group-user-field-test.js b/plugins/automation/test/javascripts/integration/components/da-email-group-user-field-test.js index c152684649b..f69f57856f4 100644 --- a/plugins/automation/test/javascripts/integration/components/da-email-group-user-field-test.js +++ b/plugins/automation/test/javascripts/integration/components/da-email-group-user-field-test.js @@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers"; import { hbs } from "ember-cli-htmlbars"; import { module, test } from "qunit"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; -import { exists, query } from "discourse/tests/helpers/qunit-helpers"; +import { exists } from "discourse/tests/helpers/qunit-helpers"; module("Integration | Component | email-group-user-field", function (hooks) { setupRenderingTest(hooks); @@ -12,7 +12,7 @@ module("Integration | Component | email-group-user-field", function (hooks) { await render(template); - assert.equal(query(".control-label").innerText, "a label"); + assert.dom(".control-label").hasText("a label"); assert.ok( exists( ".controls details.select-kit.multi-select.user-chooser.email-group-user-chooser" diff --git a/plugins/chat/test/javascripts/acceptance/chat-composer-test.js b/plugins/chat/test/javascripts/acceptance/chat-composer-test.js index e902ff6bae3..fc4cfe31f71 100644 --- a/plugins/chat/test/javascripts/acceptance/chat-composer-test.js +++ b/plugins/chat/test/javascripts/acceptance/chat-composer-test.js @@ -62,7 +62,7 @@ acceptance("Discourse Chat - Composer", function (needs) { await settled(); - assert.equal(document.querySelector(".chat-composer__input").value, "Foo"); + assert.dom(".chat-composer__input").hasValue("Foo"); }); }); diff --git a/plugins/chat/test/javascripts/components/chat-channel-test.js b/plugins/chat/test/javascripts/components/chat-channel-test.js index df6b23d487f..02e5c21caaf 100644 --- a/plugins/chat/test/javascripts/components/chat-channel-test.js +++ b/plugins/chat/test/javascripts/components/chat-channel-test.js @@ -161,20 +161,18 @@ module( await render(hbs``); await triggerEvent(statusSelector(mentionedUser.username), "mousemove"); - assert.equal( - document - .querySelector(".user-status-tooltip-description") - .textContent.trim(), - mentionedUser.status.description, - "status description is correct" - ); + assert + .dom(".user-status-tooltip-description") + .hasText( + mentionedUser.status.description, + "status description is correct" + ); - assert.ok( - document.querySelector( + assert + .dom( `.user-status-message-tooltip img[alt='${mentionedUser.status.emoji}']` - ), - "status emoji is correct" - ); + ) + .exists("status emoji is correct"); }); function assertStatusIsRendered(assert, selector, status) { diff --git a/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.js b/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.gjs similarity index 52% rename from plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.js rename to plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.gjs index 991da1823ce..3609b70a458 100644 --- a/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.js +++ b/plugins/chat/test/javascripts/unit/helpers/format-chat-date-test.gjs @@ -1,9 +1,9 @@ +import { hash } from "@ember/helper"; import { getOwner } from "@ember/owner"; import { render } from "@ember/test-helpers"; -import hbs from "htmlbars-inline-precompile"; import { module, test } from "qunit"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; -import { query } from "discourse/tests/helpers/qunit-helpers"; +import formatChatDate from "discourse/plugins/chat/discourse/helpers/format-chat-date"; import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators"; module("Discourse Chat | Unit | Helpers | format-chat-date", function (hooks) { @@ -11,31 +11,32 @@ module("Discourse Chat | Unit | Helpers | format-chat-date", function (hooks) { test("link to chat message", async function (assert) { const channel = new ChatFabricators(getOwner(this)).channel(); - this.message = new ChatFabricators(getOwner(this)).message({ channel }); + const message = new ChatFabricators(getOwner(this)).message({ channel }); - await render(hbs`{{format-chat-date this.message}}`); + await render(); - assert.equal( - query(".chat-time").getAttribute("href"), - `/chat/c/-/${channel.id}/${this.message.id}` - ); + assert + .dom(".chat-time") + .hasAttribute("href", `/chat/c/-/${channel.id}/${message.id}`); }); test("link to chat message thread", async function (assert) { const channel = new ChatFabricators(getOwner(this)).channel(); const thread = new ChatFabricators(getOwner(this)).thread(); - this.message = new ChatFabricators(getOwner(this)).message({ + const message = new ChatFabricators(getOwner(this)).message({ channel, thread, }); - await render( - hbs`{{format-chat-date this.message (hash threadContext=true)}}` - ); + await render(); - assert.equal( - query(".chat-time").getAttribute("href"), - `/chat/c/-/${channel.id}/t/${thread.id}/${this.message.id}` - ); + assert + .dom(".chat-time") + .hasAttribute( + "href", + `/chat/c/-/${channel.id}/t/${thread.id}/${message.id}` + ); }); }); diff --git a/plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.gjs b/plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.gjs new file mode 100644 index 00000000000..1d6c964b338 --- /dev/null +++ b/plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.gjs @@ -0,0 +1,41 @@ +import { render } from "@ember/test-helpers"; +import { module, test } from "qunit"; +import { setupRenderingTest } from "discourse/tests/helpers/component-test"; +import tonableEmojiTitle from "discourse/plugins/chat/discourse/helpers/tonable-emoji-title"; + +module( + "Discourse Chat | Unit | Helpers | tonable-emoji-title", + function (hooks) { + setupRenderingTest(hooks); + + test("When emoji is not tonable", async function (assert) { + const emoji = { name: "foo", tonable: false }; + const diversity = 1; + await render(); + + assert.dom("span").hasText(":foo:"); + }); + + test("When emoji is tonable and diversity is 1", async function (assert) { + const emoji = { name: "foo", tonable: true }; + const diversity = 1; + await render(); + + assert.dom("span").hasText(":foo:"); + }); + + test("When emoji is tonable and diversity is greater than 1", async function (assert) { + const emoji = { name: "foo", tonable: true }; + const diversity = 2; + await render(); + + assert.dom("span").hasText(":foo:t2:"); + }); + } +); diff --git a/plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.js b/plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.js deleted file mode 100644 index c7ff219f57b..00000000000 --- a/plugins/chat/test/javascripts/unit/helpers/tonable-emoji-title-test.js +++ /dev/null @@ -1,44 +0,0 @@ -import { render } from "@ember/test-helpers"; -import hbs from "htmlbars-inline-precompile"; -import { module, test } from "qunit"; -import { setupRenderingTest } from "discourse/tests/helpers/component-test"; - -module( - "Discourse Chat | Unit | Helpers | tonable-emoji-title", - function (hooks) { - setupRenderingTest(hooks); - - test("When emoji is not tonable", async function (assert) { - this.set("emoji", { name: "foo", tonable: false }); - this.set("diversity", 1); - await render(hbs`{{tonable-emoji-title this.emoji this.diversity}}`); - - assert.equal( - document.querySelector("#ember-testing").innerText.trim(), - ":foo:" - ); - }); - - test("When emoji is tonable and diversity is 1", async function (assert) { - this.set("emoji", { name: "foo", tonable: true }); - this.set("diversity", 1); - await render(hbs`{{tonable-emoji-title this.emoji this.diversity}}`); - - assert.equal( - document.querySelector("#ember-testing").innerText.trim(), - ":foo:" - ); - }); - - test("When emoji is tonable and diversity is greater than 1", async function (assert) { - this.set("emoji", { name: "foo", tonable: true }); - this.set("diversity", 2); - await render(hbs`{{tonable-emoji-title this.emoji this.diversity}}`); - - assert.equal( - document.querySelector("#ember-testing").innerText.trim(), - ":foo:t2:" - ); - }); - } -); diff --git a/plugins/chat/test/javascripts/unit/lib/chat-composer-buttons-test.js b/plugins/chat/test/javascripts/unit/lib/chat-composer-buttons-test.js index bf62526c383..8b008cc4b17 100644 --- a/plugins/chat/test/javascripts/unit/lib/chat-composer-buttons-test.js +++ b/plugins/chat/test/javascripts/unit/lib/chat-composer-buttons-test.js @@ -28,8 +28,8 @@ module("Discourse Chat | Unit | chat-composer-buttons", function (hooks) { test("chatComposerButtons", function (assert) { const button = chatComposerButtons({ baz: "fooz" }, "inline")[1]; - assert.equal(button.id, "bar"); - assert.equal(button.label, "fooz"); + assert.strictEqual(button.id, "bar"); + assert.strictEqual(button.label, "fooz"); }); test("chatComposerButtonsDependentKeys", function (assert) { diff --git a/plugins/chat/test/javascripts/unit/lib/slugify-channel-test.js b/plugins/chat/test/javascripts/unit/lib/slugify-channel-test.js index 9ce84b57ae3..8fdc4847404 100644 --- a/plugins/chat/test/javascripts/unit/lib/slugify-channel-test.js +++ b/plugins/chat/test/javascripts/unit/lib/slugify-channel-test.js @@ -3,14 +3,14 @@ import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel module("Discourse Chat | Unit | slugify-channel", function () { test("defaults for title", function (assert) { - assert.equal(slugifyChannel({ title: "Foo bar" }), "foo-bar"); + assert.strictEqual(slugifyChannel({ title: "Foo bar" }), "foo-bar"); }); test("a very long name for the title", function (assert) { const string = "xAq8l5ca2CtEToeMLe2pEr2VUGQBx3HPlxbkDExKrJHp4f7jCVw9id1EQv1N1lYMRdAIiZNnn94Kr0uU0iiEeVO4XkBVmpW8Mknmd"; - assert.equal( + assert.strictEqual( slugifyChannel({ title: string }), string.toLowerCase().slice(0, -1) ); @@ -19,18 +19,18 @@ module("Discourse Chat | Unit | slugify-channel", function () { test("a cyrillic name for the title", function (assert) { const string = "Русская литература и фольклор"; - assert.equal( + assert.strictEqual( slugifyChannel({ title: string }), "русская-литература-и-фольклор" ); }); test("channel has escapedTitle", function (assert) { - assert.equal(slugifyChannel({ escapedTitle: "Foo bar" }), "foo-bar"); + assert.strictEqual(slugifyChannel({ escapedTitle: "Foo bar" }), "foo-bar"); }); test("channel has slug and title", function (assert) { - assert.equal( + assert.strictEqual( slugifyChannel({ title: "Foo bar", slug: "some-other-thing" }), "some-other-thing", "slug takes priority" diff --git a/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js b/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js index a186af7e395..55eb9d298de 100644 --- a/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js +++ b/plugins/chat/test/javascripts/unit/utility/plugin-api-test.js @@ -31,7 +31,10 @@ module("Chat | Unit | Utility | plugin-api", function (hooks) { test("#removeChatComposerSecondaryActions", async function (assert) { withPluginApi("1.1.0", async (api) => { // assert that the api method is defined - assert.equal(typeof api.removeChatComposerSecondaryActions, "function"); + assert.strictEqual( + typeof api.removeChatComposerSecondaryActions, + "function" + ); logIn(); const currentUser = User.current(); diff --git a/plugins/discourse-local-dates/test/javascripts/unit/discourse-local-dates-test.js b/plugins/discourse-local-dates/test/javascripts/unit/discourse-local-dates-test.js index ee4ee32ca27..8ac75b81686 100644 --- a/plugins/discourse-local-dates/test/javascripts/unit/discourse-local-dates-test.js +++ b/plugins/discourse-local-dates/test/javascripts/unit/discourse-local-dates-test.js @@ -48,14 +48,8 @@ module("Unit | discourse-local-dates", function (hooks) { discourse_local_dates_enabled: true, }); - assert.equal( - from.querySelector(".relative-time").textContent, - "Yesterday 5:21 PM" - ); - assert.equal( - to.querySelector(".relative-time").textContent, - "10:22 PM (Singapore)" - ); + assert.dom(".relative-time", from).hasText("Yesterday 5:21 PM"); + assert.dom(".relative-time", to).hasText("10:22 PM (Singapore)"); } ); }); @@ -73,14 +67,8 @@ module("Unit | discourse-local-dates", function (hooks) { discourse_local_dates_enabled: true, }); - assert.equal( - from.querySelector(".relative-time").textContent, - "Yesterday 5:21 PM" - ); - assert.equal( - to.querySelector(".relative-time").textContent, - "Yesterday" - ); + assert.dom(".relative-time", from).hasText("Yesterday 5:21 PM"); + assert.dom(".relative-time", to).hasText("Yesterday"); } ); });