mirror of
https://github.com/discourse/discourse.git
synced 2026-08-12 05:37:26 +08:00
Currently, most of the JS test modules follow this
convention:
```
module("Integration | Component | topic-dismiss-buttons"
```
Which is a legacy from when ember components etc were
rendered in templates like this:
```
{{d-button title="foo"}}
```
Instead, this commit updates all of them to follow this
PascalCase convention:
```
module("Integration | Component | TopicDismissButtons", function (hooks) {
```
No linting is added to enforce this, we suspect that it's
mostly a result of cargo culting, and people will add new
tests following PascalCase convention.
Also adds an initial AI skill for writing JS tests.
116 lines
3.5 KiB
Text
Vendored
116 lines
3.5 KiB
Text
Vendored
import { getOwner } from "@ember/owner";
|
|
import { render } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import { i18n } from "discourse-i18n";
|
|
import ChatRetentionReminderText from "discourse/plugins/chat/discourse/components/chat-retention-reminder-text";
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
|
|
|
module("Component | ChatRetentionReminderText", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("when setting is set on 0", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
this.siteSettings.chat_channel_retention_days = 0;
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-retention-reminder-text")
|
|
.includesText("retain channel messages indefinitely");
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} @type="short" />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-retention-reminder-text")
|
|
.includesText(i18n("chat.retention_reminders.indefinitely_short"));
|
|
});
|
|
|
|
test("when channel is a public channel", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
this.siteSettings.chat_channel_retention_days = 10;
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-retention-reminder-text")
|
|
.includesText("retain channel messages for 10 days");
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} @type="short" />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-retention-reminder-text")
|
|
.includesText(i18n("chat.retention_reminders.short", { count: 10 }));
|
|
});
|
|
|
|
test("when channel is a DM channel", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
|
this.siteSettings.chat_dm_retention_days = 10;
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-retention-reminder-text")
|
|
.includesText("retain channel messages for 10 days");
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} @type="short" />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-retention-reminder-text")
|
|
.includesText(i18n("chat.retention_reminders.short", { count: 10 }));
|
|
});
|
|
|
|
test("links to chat settings for admins", async function (assert) {
|
|
this.currentUser.admin = true;
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
this.siteSettings.chat_channel_retention_days = 0;
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} />
|
|
</template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-retention-reminder-text a")
|
|
.hasAttribute("href", "/admin/site_settings/category/chat");
|
|
});
|
|
|
|
test("does not link to chat settings for non-admins", async function (assert) {
|
|
this.currentUser.admin = false;
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
this.siteSettings.chat_channel_retention_days = 0;
|
|
|
|
await render(
|
|
<template>
|
|
<ChatRetentionReminderText @channel={{this.channel}} />
|
|
</template>
|
|
);
|
|
|
|
assert.dom(".chat-retention-reminder-text a").doesNotExist();
|
|
});
|
|
});
|