DEV: Extensively use qunit-dom's hasText (#30012)

This commit is contained in:
Jarek Radosz
2024-11-30 16:44:51 +01:00
committed by GitHub
parent d93967e2fb
commit dfb74d90c3
37 changed files with 348 additions and 563 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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