DEV: Modernize chat's component tests (#19577)

1. `test()` and `render()` instead of `componentTest()`
2. Angle brackets
3. `strictEqual()`/`true()`/`false()` assertions

This removes all remaining uses of `componentTest` from core
This commit is contained in:
Jarek Radosz
2022-12-22 14:35:18 +01:00
committed by GitHub
parent 8546c2084a
commit dc3473fe06
34 changed files with 1397 additions and 1762 deletions

View File

@ -20,39 +20,39 @@ module("Discourse Chat | Component | chat-channel-card", function (hooks) {
test("escapes channel title", async function (assert) {
this.channel.set("title", "<div class='xss'>evil</div>");
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.notOk(exists(".xss"));
assert.false(exists(".xss"));
});
test("escapes channel description", async function (assert) {
this.channel.set("description", "<div class='xss'>evil</div>");
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.notOk(exists(".xss"));
assert.false(exists(".xss"));
});
test("Closed channel", async function (assert) {
this.channel.set("status", "closed");
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.ok(exists(".chat-channel-card.-closed"));
assert.true(exists(".chat-channel-card.-closed"));
});
test("Archived channel", async function (assert) {
this.channel.set("status", "archived");
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.ok(exists(".chat-channel-card.-archived"));
assert.true(exists(".chat-channel-card.-archived"));
});
test("Muted channel", async function (assert) {
this.channel.currentUserMembership.muted = true;
this.channel.currentUserMembership.following = true;
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.equal(
assert.strictEqual(
query(".chat-channel-card__tag.-muted").textContent.trim(),
I18n.t("chat.muted")
);
@ -60,27 +60,27 @@ module("Discourse Chat | Component | chat-channel-card", function (hooks) {
test("Joined channel", async function (assert) {
this.channel.currentUserMembership.set("following", true);
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.equal(
assert.strictEqual(
query(".chat-channel-card__tag.-joined").textContent.trim(),
I18n.t("chat.joined")
);
assert.ok(exists(".toggle-channel-membership-button.-leave"));
assert.true(exists(".toggle-channel-membership-button.-leave"));
});
test("Joinable channel", async function (assert) {
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.ok(exists(".chat-channel-card__join-btn"));
assert.true(exists(".chat-channel-card__join-btn"));
});
test("Memberships count", async function (assert) {
this.channel.set("membershipsCount", 4);
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.equal(
assert.strictEqual(
query(".chat-channel-card__members").textContent.trim(),
I18n.t("chat.channel.memberships_count", { count: 4 })
);
@ -88,41 +88,41 @@ module("Discourse Chat | Component | chat-channel-card", function (hooks) {
test("No description", async function (assert) {
this.channel.set("description", null);
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.notOk(exists(".chat-channel-card__description"));
assert.false(exists(".chat-channel-card__description"));
});
test("Description", async function (assert) {
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.equal(
assert.strictEqual(
query(".chat-channel-card__description").textContent.trim(),
this.channel.description
);
});
test("Name", async function (assert) {
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.equal(
assert.strictEqual(
query(".chat-channel-card__name").innerText.trim(),
this.channel.title
);
});
test("Settings button", async function (assert) {
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.ok(exists(".chat-channel-card__setting"));
assert.true(exists(".chat-channel-card__setting"));
});
test("Read restricted chatable", async function (assert) {
this.channel.set("chatable.read_restricted", true);
await render(hbs`{{chat-channel-card channel=channel}}`);
await render(hbs`<ChatChannelCard @channel={{this.channel}} />`);
assert.ok(exists(".d-icon-lock"));
assert.equal(
assert.true(exists(".d-icon-lock"));
assert.strictEqual(
query(".chat-channel-card").style.borderLeftColor,
"rgb(213, 99, 83)"
);