DEV: Convert more equal assertions (#29554)

…to either qunit-dom or `strictEqual`
This commit is contained in:
Jarek Radosz 2024-11-03 21:04:38 +01:00 committed by GitHub
parent d2056c7fc6
commit b81055a6d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 165 additions and 198 deletions

View File

@ -198,7 +198,7 @@ acceptance("Admin - Site Settings", function (needs) {
const navItems = queryAll(".admin-nav .nav-stacked li a"); const navItems = queryAll(".admin-nav .nav-stacked li a");
navItems.each((_, item) => { navItems.each((_, item) => {
assert.equal( assert.strictEqual(
item.title, item.title,
item.innerText, item.innerText,
"menu item has title, and the title is equal to menu item's label" "menu item has title, and the title is equal to menu item's label"

View File

@ -22,10 +22,7 @@ acceptance("Admin - Users List", function (needs) {
await fillIn(".controls.username input", "doesntexist"); await fillIn(".controls.username input", "doesntexist");
assert.equal( assert.dom(".users-list-container").hasText(I18n.t("search.no_results"));
query(".users-list-container").innerText,
I18n.t("search.no_results")
);
}); });
test("sorts users", async function (assert) { test("sorts users", async function (assert) {

View File

@ -119,13 +119,9 @@ acceptance("Composer - editor mentions", function (needs) {
.dom(`.autocomplete .emoji[alt='${status.emoji}']`) .dom(`.autocomplete .emoji[alt='${status.emoji}']`)
.exists("status emoji is shown"); .exists("status emoji is shown");
assert.equal( assert
query( .dom(".autocomplete .user-status-message-description")
".autocomplete .user-status-message-description" .hasText(status.description, "status description is shown");
).textContent.trim(),
status.description,
"status description is shown"
);
}); });
test("metadata matches are moved to the end", async function (assert) { test("metadata matches are moved to the end", async function (assert) {

View File

@ -125,11 +125,7 @@ acceptance("flagging", function (needs) {
await selectKit(".reviewable-action-dropdown").expand(); await selectKit(".reviewable-action-dropdown").expand();
await click("[data-value='agree_and_silence']"); await click("[data-value='agree_and_silence']");
assert.ok(exists(".silence-user-modal"), "it shows the silence modal"); assert.ok(exists(".silence-user-modal"), "it shows the silence modal");
assert.equal( assert.dom(".suspend-message").hasValue("", "penalty message is empty");
query(".suspend-message").value,
"",
"penalty message is empty"
);
const silenceUntilCombobox = selectKit(".silence-until .combobox"); const silenceUntilCombobox = selectKit(".silence-until .combobox");
await silenceUntilCombobox.expand(); await silenceUntilCombobox.expand();
await silenceUntilCombobox.selectRowByValue("tomorrow"); await silenceUntilCombobox.selectRowByValue("tomorrow");
@ -148,11 +144,12 @@ acceptance("flagging", function (needs) {
await selectKit(".reviewable-action-dropdown").expand(); await selectKit(".reviewable-action-dropdown").expand();
await click("[data-value='agree_and_silence']"); await click("[data-value='agree_and_silence']");
assert.ok(exists(".silence-user-modal"), "it shows the silence modal"); assert.ok(exists(".silence-user-modal"), "it shows the silence modal");
assert.equal( assert
query(".suspend-message").value, .dom(".suspend-message")
"-------------------\n<p>Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?</p>\n-------------------", .hasValue(
"penalty message is prefilled with post text" "-------------------\n<p>Any plans to support localization of UI elements, so that I (for example) could set up a completely German speaking forum?</p>\n-------------------",
); "penalty message is prefilled with post text"
);
}); });
test("Can delete spammer from spam", async function (assert) { test("Can delete spammer from spam", async function (assert) {

View File

@ -121,7 +121,10 @@ acceptance("Managing Group Membership", function (needs) {
await associatedGroups.selectRowByName("google_oauth2:test-group"); await associatedGroups.selectRowByName("google_oauth2:test-group");
await associatedGroups.keyboard("enter"); 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) { test("As an admin on a site that can't associate groups", async function (assert) {

View File

@ -177,11 +177,9 @@ acceptance("Post inline mentions user status tooltip", function (needs) {
statusTooltip.querySelector("img").src.includes(status.emoji), statusTooltip.querySelector("img").src.includes(status.emoji),
"emoji is correct" "emoji is correct"
); );
assert.equal( assert
statusTooltip.querySelector(".user-status-tooltip-description").innerText, .dom(".user-status-tooltip-description", statusTooltip)
status.description, .hasText(status.description, "status description is correct");
"status description is correct"
);
}); });
}); });

View File

@ -801,7 +801,7 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
"shows suffix indicator for new topics on categories link" "shows suffix indicator for new topics on categories link"
); );
assert.equal( assert.strictEqual(
Object.keys(topicTrackingState.stateChangeCallbacks).length, Object.keys(topicTrackingState.stateChangeCallbacks).length,
initialCallbackCount, initialCallbackCount,
"it does not add a new topic tracking state callback when the topic is read" "it does not add a new topic tracking state callback when the topic is read"

View File

@ -222,11 +222,9 @@ acceptance("Theme", function (needs) {
await click(".control-unit .btn-primary.finish-install"); await click(".control-unit .btn-primary.finish-install");
assert.equal( assert
query(".show-current-style .title span").innerText, .dom(".show-current-style .title span")
"discourse-complete-theme", .hasText("discourse-complete-theme", "it updates theme title");
"it updates theme title"
);
assert.notOk( assert.notOk(
query(".metadata.control-unit").innerText.includes( query(".metadata.control-unit").innerText.includes(

View File

@ -308,10 +308,7 @@ acceptance("User Preferences — Account - Download Archive", function (needs) {
await click(".btn-request-archive"); await click(".btn-request-archive");
await click("#dialog-holder .btn-primary"); await click("#dialog-holder .btn-primary");
assert.equal( assert.dom(".dialog-body").hasText(I18n.t("user.download_archive.success"));
query(".dialog-body").innerText.trim(),
I18n.t("user.download_archive.success")
);
await click("#dialog-holder .btn-primary"); await click("#dialog-holder .btn-primary");
}); });

View File

@ -3,7 +3,7 @@ import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender"; 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( module(
"Integration | Component | form-template-field | wrapper", "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"`; - type: multi-select\n id: multi\n choices:\n - "Option 1"\n - "Option 2"\n - "Option 3"`;
this.set("content", content); this.set("content", content);
const initialValues = { this.set("initialValues", {
checkbox: "on", checkbox: "on",
name: "Test Name", name: "Test Name",
notes: "Test Notes", notes: "Test Notes",
dropdown: "Option 1", dropdown: "Option 1",
multi: ["Option 1"], multi: ["Option 1"],
}; });
this.set("initialValues", initialValues);
await render( await render(
hbs`<FormTemplateField::Wrapper @content={{this.content}} @initialValues={{this.initialValues}} />` hbs`<FormTemplateField::Wrapper @content={{this.content}} @initialValues={{this.initialValues}} />`
); );
Object.keys(initialValues).forEach((componentId) => { assert.dom("[name='checkbox']").hasValue("on");
assert.equal( assert.dom("[name='name']").hasValue("Test Name");
query(`[name='${componentId}']`).value, assert.dom("[name='notes']").hasValue("Test Notes");
initialValues[componentId], assert.dom("[name='dropdown']").hasValue("Option 1");
`${componentId} component has initial value` 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) { test("renders a component based on the component type found in the content YAML when passed ids", async function (assert) {

View File

@ -18,7 +18,7 @@ module("Integration | Component | number-field", function (hooks) {
await fillIn(".number-field-test", "33"); await fillIn(".number-field-test", "33");
assert.equal( assert.strictEqual(
this.get("value"), this.get("value"),
33, 33,
"value is changed when the input is a valid number" "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 fillIn(".number-field-test", "");
await triggerKeyEvent(".number-field-test", "keydown", 66); // b await triggerKeyEvent(".number-field-test", "keydown", 66); // b
assert.equal( assert.strictEqual(
this.get("value"), this.get("value"),
"", "",
"value is cleared when the input is NaN" "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", 189); // -
await triggerKeyEvent(".number-field-test", "keydown", 49); // 1 await triggerKeyEvent(".number-field-test", "keydown", 49); // 1
assert.equal( assert.strictEqual(
this.get("value"), this.get("value"),
"", "",
"value is cleared when the input is less than the min" "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"); await fillIn(".number-field-test", "-1");
assert.equal( assert.strictEqual(
this.get("value"), this.get("value"),
"-1", -1,
"negative input allowed when min is negative" "negative input allowed when min is negative"
); );
}); });

View File

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

View File

@ -133,18 +133,12 @@ module(
await fillIn(".filter-input", "test-user"); await fillIn(".filter-input", "test-user");
assert.ok(exists(".user-status-message"), "user status is rendered"); assert.ok(exists(".user-status-message"), "user status is rendered");
assert.equal( assert
query(".user-status-message .emoji").alt, .dom(".user-status-message .emoji")
status.emoji, .hasAttribute("alt", status.emoji, "status emoji is correct");
"status emoji is correct" assert
); .dom(".user-status-message .user-status-message-description")
assert.equal( .hasText(status.description, "status description is correct");
query(
".user-status-message .user-status-message-description"
).innerText.trim(),
status.description,
"status description is correct"
);
}); });
} }
); );

View File

@ -130,7 +130,7 @@ module(
await this.subject.fillInFilter("test"); await this.subject.fillInFilter("test");
assert.equal(this.subject.filter().value(), "#test"); assert.strictEqual(this.subject.filter().value(), "#test");
assert.ok( assert.ok(
exists(".select-kit-row[data-value='test']"), exists(".select-kit-row[data-value='test']"),
"it filters out the invalid char from the suggested tag" "it filters out the invalid char from the suggested tag"

View File

@ -116,7 +116,7 @@ module("Integration | Component | select-kit/multi-select", function (hooks) {
await this.subject.expand(); await this.subject.expand();
await paste(query(".filter-input"), "foo|bar"); 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) { test("no value property with no content", async function (assert) {

View File

@ -107,9 +107,9 @@ module("Unit | Controller | admin-user-badges", function (hooks) {
GrantBadgeStub.calledWith(badgeToGrant.id, user.username, badgeReason) GrantBadgeStub.calledWith(badgeToGrant.id, user.username, badgeReason)
); );
assert.equal(controller.badgeReason, ""); assert.strictEqual(controller.badgeReason, "");
assert.equal(controller.userBadges.length, 1); assert.strictEqual(controller.userBadges.length, 1);
assert.equal(controller.userBadges[0].id, newUserBadge.id); assert.strictEqual(controller.userBadges[0].id, newUserBadge.id);
assert.equal(controller.selectedBadgeId, otherBadge.id); assert.strictEqual(controller.selectedBadgeId, otherBadge.id);
}); });
}); });

View File

@ -10,23 +10,26 @@ module("Unit | discourse-common | case-converter", function (hooks) {
setupTest(hooks); setupTest(hooks);
test("camelCaseToSnakeCase", function (assert) { test("camelCaseToSnakeCase", function (assert) {
assert.equal(camelCaseToSnakeCase("camelCase"), "camel_case"); assert.strictEqual(camelCaseToSnakeCase("camelCase"), "camel_case");
assert.equal(camelCaseToSnakeCase("camelCase99"), "camel_case99"); assert.strictEqual(camelCaseToSnakeCase("camelCase99"), "camel_case99");
assert.equal(camelCaseToSnakeCase("camelCaseId"), "camel_case_id"); assert.strictEqual(camelCaseToSnakeCase("camelCaseId"), "camel_case_id");
assert.equal(camelCaseToSnakeCase("camelCaseUrl"), "camel_case_url"); assert.strictEqual(camelCaseToSnakeCase("camelCaseUrl"), "camel_case_url");
}); });
test("camelCaseToDash", function (assert) { test("camelCaseToDash", function (assert) {
assert.equal(camelCaseToDash("camelCase"), "camel-case"); assert.strictEqual(camelCaseToDash("camelCase"), "camel-case");
assert.equal(camelCaseToDash("camelCaseToDash99"), "camel-case-to-dash99"); assert.strictEqual(
assert.equal(camelCaseToDash("camelCaseId"), "camel-case-id"); camelCaseToDash("camelCaseToDash99"),
assert.equal(camelCaseToDash("camelCaseUrl"), "camel-case-url"); "camel-case-to-dash99"
);
assert.strictEqual(camelCaseToDash("camelCaseId"), "camel-case-id");
assert.strictEqual(camelCaseToDash("camelCaseUrl"), "camel-case-url");
}); });
test("snakeCaseToCamelCase", function (assert) { test("snakeCaseToCamelCase", function (assert) {
assert.equal(snakeCaseToCamelCase("snake_case"), "snakeCase"); assert.strictEqual(snakeCaseToCamelCase("snake_case"), "snakeCase");
assert.equal(snakeCaseToCamelCase("snake_case99"), "snakeCase99"); assert.strictEqual(snakeCaseToCamelCase("snake_case99"), "snakeCase99");
assert.equal(snakeCaseToCamelCase("some_id"), "someId"); assert.strictEqual(snakeCaseToCamelCase("some_id"), "someId");
assert.equal(snakeCaseToCamelCase("some_url"), "someUrl"); assert.strictEqual(snakeCaseToCamelCase("some_url"), "someUrl");
}); });
}); });

View File

@ -39,7 +39,7 @@ module("Unit | Utility | download-calendar", function (hooks) {
} }
); );
assert.equal( assert.strictEqual(
data, data,
`BEGIN:VCALENDAR `BEGIN:VCALENDAR
VERSION:2.0 VERSION:2.0
@ -76,7 +76,7 @@ END:VCALENDAR`
], ],
{ recurrenceRule: "FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR" } { recurrenceRule: "FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR" }
); );
assert.equal( assert.strictEqual(
data, data,
`BEGIN:VCALENDAR `BEGIN:VCALENDAR
VERSION:2.0 VERSION:2.0

View File

@ -492,14 +492,14 @@ module("Unit | Utility | formatter | until", function (hooks) {
const timezone = "UTC"; const timezone = "UTC";
this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone); this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone);
const result = until("2100-01-01 13:00:00.000Z", timezone, "en"); 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) { test("shows date if until moment is tomorrow", function (assert) {
const timezone = "UTC"; const timezone = "UTC";
this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone); this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone);
const result = until("2100-01-02 12:00:00.000Z", timezone, "en"); 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) { 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); this.clock = fakeTime("2100-01-01 12:00:00.000Z", timezone);
const result = until(`2100-01-01 ${untilUTC}:00.000Z`, timezone, "en"); const result = until(`2100-01-01 ${untilUTC}:00.000Z`, timezone, "en");
assert.equal(result, `Until: ${untilTbilisi}`); assert.strictEqual(result, `Until: ${untilTbilisi}`);
}); });
}); });

View File

@ -70,6 +70,6 @@ module("Unit | Utility | text | parseMentions", function (hooks) {
\`\`\` \`\`\`
`; `;
const mentions = await parseMentions(markdown); const mentions = await parseMentions(markdown);
assert.equal(mentions.length, 0); assert.strictEqual(mentions.length, 0);
}); });
}); });

View File

@ -28,8 +28,8 @@ module("Unit | Model | category", function (hooks) {
}); });
assert.deepEqual(foo.subcategories, [bar, baz]); assert.deepEqual(foo.subcategories, [bar, baz]);
assert.equal(bar.parentCategory, foo); assert.strictEqual(bar.parentCategory, foo);
assert.equal(baz.parentCategory, foo); assert.strictEqual(baz.parentCategory, foo);
}); });
test("slugFor", function (assert) { test("slugFor", function (assert) {

View File

@ -454,7 +454,7 @@ module("Unit | Model | composer", function (hooks) {
pretender.post("/posts", function (request) { pretender.post("/posts", function (request) {
const data = parsePostData(request.requestBody); 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; saved = true;
return response(200, { return response(200, {
@ -478,11 +478,11 @@ module("Unit | Model | composer", function (hooks) {
draftSequence: 1, draftSequence: 1,
}); });
assert.equal(composer.loading, false); assert.false(composer.loading);
composer.metaData = { some_custom_field: "some_value" }; composer.metaData = { some_custom_field: "some_value" };
await composer.save({}); await composer.save({});
assert.equal(saved, true); assert.true(saved);
}); });
}); });

View File

@ -373,7 +373,7 @@ module("Unit | Model | topic-tracking-state", function (hooks) {
"expect state for topic 111 to be deleted" "expect state for topic 111 to be deleted"
); );
assert.equal( assert.strictEqual(
stateChangeCallbackCalledTimes, stateChangeCallbackCalledTimes,
1, 1,
"callback is only called once" "callback is only called once"

View File

@ -2,7 +2,7 @@ import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars"; import { hbs } from "ember-cli-htmlbars";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { 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) { module("Integration | Component | email-group-user-field", function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);
@ -12,7 +12,7 @@ module("Integration | Component | email-group-user-field", function (hooks) {
await render(template); await render(template);
assert.equal(query(".control-label").innerText, "a label"); assert.dom(".control-label").hasText("a label");
assert.ok( assert.ok(
exists( exists(
".controls details.select-kit.multi-select.user-chooser.email-group-user-chooser" ".controls details.select-kit.multi-select.user-chooser.email-group-user-chooser"

View File

@ -62,7 +62,7 @@ acceptance("Discourse Chat - Composer", function (needs) {
await settled(); await settled();
assert.equal(document.querySelector(".chat-composer__input").value, "Foo"); assert.dom(".chat-composer__input").hasValue("Foo");
}); });
}); });

View File

@ -161,20 +161,18 @@ module(
await render(hbs`<ChatChannel @channel={{this.channel}} /><DTooltips />`); await render(hbs`<ChatChannel @channel={{this.channel}} /><DTooltips />`);
await triggerEvent(statusSelector(mentionedUser.username), "mousemove"); await triggerEvent(statusSelector(mentionedUser.username), "mousemove");
assert.equal( assert
document .dom(".user-status-tooltip-description")
.querySelector(".user-status-tooltip-description") .hasText(
.textContent.trim(), mentionedUser.status.description,
mentionedUser.status.description, "status description is correct"
"status description is correct" );
);
assert.ok( assert
document.querySelector( .dom(
`.user-status-message-tooltip img[alt='${mentionedUser.status.emoji}']` `.user-status-message-tooltip img[alt='${mentionedUser.status.emoji}']`
), )
"status emoji is correct" .exists("status emoji is correct");
);
}); });
function assertStatusIsRendered(assert, selector, status) { function assertStatusIsRendered(assert, selector, status) {

View File

@ -1,9 +1,9 @@
import { hash } from "@ember/helper";
import { getOwner } from "@ember/owner"; import { getOwner } from "@ember/owner";
import { render } from "@ember/test-helpers"; import { render } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit"; import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test"; import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { query } from "discourse/tests/helpers/qunit-helpers"; import formatChatDate from "discourse/plugins/chat/discourse/helpers/format-chat-date";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators"; import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Unit | Helpers | format-chat-date", function (hooks) { 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) { test("link to chat message", async function (assert) {
const channel = new ChatFabricators(getOwner(this)).channel(); 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(<template>{{formatChatDate message}}</template>);
assert.equal( assert
query(".chat-time").getAttribute("href"), .dom(".chat-time")
`/chat/c/-/${channel.id}/${this.message.id}` .hasAttribute("href", `/chat/c/-/${channel.id}/${message.id}`);
);
}); });
test("link to chat message thread", async function (assert) { test("link to chat message thread", async function (assert) {
const channel = new ChatFabricators(getOwner(this)).channel(); const channel = new ChatFabricators(getOwner(this)).channel();
const thread = new ChatFabricators(getOwner(this)).thread(); const thread = new ChatFabricators(getOwner(this)).thread();
this.message = new ChatFabricators(getOwner(this)).message({ const message = new ChatFabricators(getOwner(this)).message({
channel, channel,
thread, thread,
}); });
await render( await render(<template>
hbs`{{format-chat-date this.message (hash threadContext=true)}}` {{formatChatDate message (hash threadContext=true)}}
); </template>);
assert.equal( assert
query(".chat-time").getAttribute("href"), .dom(".chat-time")
`/chat/c/-/${channel.id}/t/${thread.id}/${this.message.id}` .hasAttribute(
); "href",
`/chat/c/-/${channel.id}/t/${thread.id}/${message.id}`
);
}); });
}); });

View File

@ -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(<template>
<span>{{tonableEmojiTitle emoji diversity}}</span>
</template>);
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(<template>
<span>{{tonableEmojiTitle emoji diversity}}</span>
</template>);
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(<template>
<span>{{tonableEmojiTitle emoji diversity}}</span>
</template>);
assert.dom("span").hasText(":foo:t2:");
});
}
);

View File

@ -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:"
);
});
}
);

View File

@ -28,8 +28,8 @@ module("Discourse Chat | Unit | chat-composer-buttons", function (hooks) {
test("chatComposerButtons", function (assert) { test("chatComposerButtons", function (assert) {
const button = chatComposerButtons({ baz: "fooz" }, "inline")[1]; const button = chatComposerButtons({ baz: "fooz" }, "inline")[1];
assert.equal(button.id, "bar"); assert.strictEqual(button.id, "bar");
assert.equal(button.label, "fooz"); assert.strictEqual(button.label, "fooz");
}); });
test("chatComposerButtonsDependentKeys", function (assert) { test("chatComposerButtonsDependentKeys", function (assert) {

View File

@ -3,14 +3,14 @@ import slugifyChannel from "discourse/plugins/chat/discourse/lib/slugify-channel
module("Discourse Chat | Unit | slugify-channel", function () { module("Discourse Chat | Unit | slugify-channel", function () {
test("defaults for title", function (assert) { 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) { test("a very long name for the title", function (assert) {
const string = const string =
"xAq8l5ca2CtEToeMLe2pEr2VUGQBx3HPlxbkDExKrJHp4f7jCVw9id1EQv1N1lYMRdAIiZNnn94Kr0uU0iiEeVO4XkBVmpW8Mknmd"; "xAq8l5ca2CtEToeMLe2pEr2VUGQBx3HPlxbkDExKrJHp4f7jCVw9id1EQv1N1lYMRdAIiZNnn94Kr0uU0iiEeVO4XkBVmpW8Mknmd";
assert.equal( assert.strictEqual(
slugifyChannel({ title: string }), slugifyChannel({ title: string }),
string.toLowerCase().slice(0, -1) 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) { test("a cyrillic name for the title", function (assert) {
const string = "Русская литература и фольклор"; const string = "Русская литература и фольклор";
assert.equal( assert.strictEqual(
slugifyChannel({ title: string }), slugifyChannel({ title: string }),
"русская-литература-и-фольклор" "русская-литература-и-фольклор"
); );
}); });
test("channel has escapedTitle", function (assert) { 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) { test("channel has slug and title", function (assert) {
assert.equal( assert.strictEqual(
slugifyChannel({ title: "Foo bar", slug: "some-other-thing" }), slugifyChannel({ title: "Foo bar", slug: "some-other-thing" }),
"some-other-thing", "some-other-thing",
"slug takes priority" "slug takes priority"

View File

@ -31,7 +31,10 @@ module("Chat | Unit | Utility | plugin-api", function (hooks) {
test("#removeChatComposerSecondaryActions", async function (assert) { test("#removeChatComposerSecondaryActions", async function (assert) {
withPluginApi("1.1.0", async (api) => { withPluginApi("1.1.0", async (api) => {
// assert that the api method is defined // assert that the api method is defined
assert.equal(typeof api.removeChatComposerSecondaryActions, "function"); assert.strictEqual(
typeof api.removeChatComposerSecondaryActions,
"function"
);
logIn(); logIn();
const currentUser = User.current(); const currentUser = User.current();

View File

@ -48,14 +48,8 @@ module("Unit | discourse-local-dates", function (hooks) {
discourse_local_dates_enabled: true, discourse_local_dates_enabled: true,
}); });
assert.equal( assert.dom(".relative-time", from).hasText("Yesterday 5:21 PM");
from.querySelector(".relative-time").textContent, assert.dom(".relative-time", to).hasText("10:22 PM (Singapore)");
"Yesterday 5:21 PM"
);
assert.equal(
to.querySelector(".relative-time").textContent,
"10:22 PM (Singapore)"
);
} }
); );
}); });
@ -73,14 +67,8 @@ module("Unit | discourse-local-dates", function (hooks) {
discourse_local_dates_enabled: true, discourse_local_dates_enabled: true,
}); });
assert.equal( assert.dom(".relative-time", from).hasText("Yesterday 5:21 PM");
from.querySelector(".relative-time").textContent, assert.dom(".relative-time", to).hasText("Yesterday");
"Yesterday 5:21 PM"
);
assert.equal(
to.querySelector(".relative-time").textContent,
"Yesterday"
);
} }
); );
}); });