mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
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:
@ -1,93 +1,80 @@
|
||||
import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
|
||||
import { set } from "@ember/object";
|
||||
import componentTest, {
|
||||
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 hbs from "htmlbars-inline-precompile";
|
||||
import I18n from "I18n";
|
||||
import { module } from "qunit";
|
||||
import { module, test } from "qunit";
|
||||
import { render } from "@ember/test-helpers";
|
||||
|
||||
module(
|
||||
"Discourse Chat | Component | chat-retention-reminder",
|
||||
function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
componentTest("Shows for public channels when user needs it", {
|
||||
template: hbs`{{chat-retention-reminder chatChannel=chatChannel}}`,
|
||||
test("Shows for public channels when user needs it", async function (assert) {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "Category" })
|
||||
);
|
||||
this.currentUser.set("needs_channel_retention_reminder", true);
|
||||
this.siteSettings.chat_channel_retention_days = 100;
|
||||
|
||||
async beforeEach() {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "Category" })
|
||||
);
|
||||
set(this.currentUser, "needs_channel_retention_reminder", true);
|
||||
this.siteSettings.chat_channel_retention_days = 100;
|
||||
},
|
||||
await render(
|
||||
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
||||
);
|
||||
|
||||
async test(assert) {
|
||||
assert.equal(
|
||||
query(".chat-retention-reminder-text").innerText.trim(),
|
||||
I18n.t("chat.retention_reminders.public", { days: 100 })
|
||||
);
|
||||
},
|
||||
assert.strictEqual(
|
||||
query(".chat-retention-reminder-text").innerText.trim(),
|
||||
I18n.t("chat.retention_reminders.public", { days: 100 })
|
||||
);
|
||||
});
|
||||
|
||||
componentTest(
|
||||
"Doesn't show for public channels when user has dismissed it",
|
||||
{
|
||||
template: hbs`{{chat-retention-reminder chatChannel=chatChannel}}`,
|
||||
test("Doesn't show for public channels when user has dismissed it", async function (assert) {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "Category" })
|
||||
);
|
||||
this.currentUser.set("needs_channel_retention_reminder", false);
|
||||
this.siteSettings.chat_channel_retention_days = 100;
|
||||
|
||||
async beforeEach() {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "Category" })
|
||||
);
|
||||
set(this.currentUser, "needs_channel_retention_reminder", false);
|
||||
this.siteSettings.chat_channel_retention_days = 100;
|
||||
},
|
||||
await render(
|
||||
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
||||
);
|
||||
|
||||
async test(assert) {
|
||||
assert.notOk(exists(".chat-retention-reminder"));
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
componentTest("Shows for direct message channels when user needs it", {
|
||||
template: hbs`{{chat-retention-reminder chatChannel=chatChannel}}`,
|
||||
|
||||
async beforeEach() {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "DirectMessage" })
|
||||
);
|
||||
set(this.currentUser, "needs_dm_retention_reminder", true);
|
||||
this.siteSettings.chat_dm_retention_days = 100;
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
assert.equal(
|
||||
query(".chat-retention-reminder-text").innerText.trim(),
|
||||
I18n.t("chat.retention_reminders.dm", { days: 100 })
|
||||
);
|
||||
},
|
||||
assert.false(exists(".chat-retention-reminder"));
|
||||
});
|
||||
|
||||
componentTest("Doesn't show for dm channels when user has dismissed it", {
|
||||
template: hbs`{{chat-retention-reminder chatChannel=chatChannel}}`,
|
||||
test("Shows for direct message channels when user needs it", async function (assert) {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "DirectMessage" })
|
||||
);
|
||||
this.currentUser.set("needs_dm_retention_reminder", true);
|
||||
this.siteSettings.chat_dm_retention_days = 100;
|
||||
|
||||
async beforeEach() {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "DirectMessage" })
|
||||
);
|
||||
set(this.currentUser, "needs_dm_retention_reminder", false);
|
||||
this.siteSettings.chat_dm_retention_days = 100;
|
||||
},
|
||||
await render(
|
||||
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
||||
);
|
||||
|
||||
async test(assert) {
|
||||
assert.notOk(exists(".chat-retention-reminder"));
|
||||
},
|
||||
assert.strictEqual(
|
||||
query(".chat-retention-reminder-text").innerText.trim(),
|
||||
I18n.t("chat.retention_reminders.dm", { days: 100 })
|
||||
);
|
||||
});
|
||||
|
||||
test("Doesn't show for dm channels when user has dismissed it", async function (assert) {
|
||||
this.set(
|
||||
"chatChannel",
|
||||
ChatChannel.create({ chatable_type: "DirectMessage" })
|
||||
);
|
||||
this.currentUser.set("needs_dm_retention_reminder", false);
|
||||
this.siteSettings.chat_dm_retention_days = 100;
|
||||
|
||||
await render(
|
||||
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
||||
);
|
||||
|
||||
assert.false(exists(".chat-retention-reminder"));
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user