This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/test/javascripts/components/chat-retention-reminder-test.js
Gerhard Schlager 7974fcba46 DEV: Lint locale files for correct usage of %{count}
Strings need to be pluralized when they contain the `%{count}` interpolation key. This also fixes all strings in core.
2022-12-07 01:22:37 +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", { count: 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"));
},
});
}
);