2022-11-02 21:41:30 +08:00
|
|
|
import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import I18n from "I18n";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { module, test } from "qunit";
|
|
|
|
import { render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Component | chat-retention-reminder",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
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;
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(
|
|
|
|
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-retention-reminder-text").innerText.trim(),
|
|
|
|
I18n.t("chat.retention_reminders.public", { days: 100 })
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
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;
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(
|
|
|
|
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.false(exists(".chat-retention-reminder"));
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
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;
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(
|
|
|
|
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-retention-reminder-text").innerText.trim(),
|
|
|
|
I18n.t("chat.retention_reminders.dm", { days: 100 })
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
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;
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(
|
|
|
|
hbs`<ChatRetentionReminder @chatChannel={{this.chatChannel}} />`
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.false(exists(".chat-retention-reminder"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|