discourse/plugins/chat/test/javascripts/components/chat-retention-reminder-test.js
Loïc Guitaut abcaa1a961 DEV: Rename direct message related models
This is a followup of the previous refactor where we created two new
models to handle all the dedicated logic that was present in the
`ChatChannel` model.

For the sake of consistency, `DMChannel` has been renamed to
`DirectMessageChannel` and the previous `DirectMessageChannel` model is
now named `DirectMessage`. This should help reasoning about direct
messages.
2022-11-03 14:39:23 +01:00

94 lines
2.9 KiB
JavaScript

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 { exists, query } from "discourse/tests/helpers/qunit-helpers";
import hbs from "htmlbars-inline-precompile";
import I18n from "I18n";
import { module } from "qunit";
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}}`,
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;
},
async test(assert) {
assert.equal(
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}}`,
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;
},
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 })
);
},
});
componentTest("Doesn't show for dm channels when user has dismissed 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", false);
this.siteSettings.chat_dm_retention_days = 100;
},
async test(assert) {
assert.notOk(exists(".chat-retention-reminder"));
},
});
}
);