mirror of
https://github.com/discourse/discourse.git
synced 2026-08-14 13:58:53 +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.
119 lines
3.8 KiB
Text
Vendored
119 lines
3.8 KiB
Text
Vendored
import { getOwner } from "@ember/owner";
|
|
import { click, render } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
|
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
|
import { i18n } from "discourse-i18n";
|
|
import ChatNotices from "discourse/plugins/chat/discourse/components/chat-notices";
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
|
|
|
module("Component | ChatNotice", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("displays all notices for a channel", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
this.manager = this.container.lookup(
|
|
"service:chat-channel-notices-manager"
|
|
);
|
|
this.manager.handleNotice({
|
|
channel_id: this.channel.id,
|
|
text_content: "hello",
|
|
});
|
|
this.manager.handleNotice({
|
|
channel_id: this.channel.id,
|
|
text_content: "goodbye",
|
|
});
|
|
this.manager.handleNotice({
|
|
channel_id: this.channel.id + 1,
|
|
text_content: "N/A",
|
|
});
|
|
|
|
await render(
|
|
<template><ChatNotices @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
const notices = queryAll(".chat-notices .chat-notices__notice");
|
|
|
|
assert.strictEqual(notices.length, 2, "Two notices are rendered");
|
|
|
|
assert.dom(notices[0]).includesText("hello");
|
|
assert.dom(notices[1]).includesText("goodbye");
|
|
});
|
|
|
|
test("Notices can be cleared", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
this.manager = this.container.lookup(
|
|
"service:chat-channel-notices-manager"
|
|
);
|
|
this.manager.handleNotice({
|
|
channel_id: this.channel.id,
|
|
text_content: "hello",
|
|
});
|
|
|
|
await render(
|
|
<template><ChatNotices @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert.strictEqual(
|
|
queryAll(".chat-notices .chat-notices__notice").length,
|
|
1,
|
|
"Notice is present"
|
|
);
|
|
|
|
await click(".chat-notices__notice__clear");
|
|
|
|
assert.strictEqual(
|
|
queryAll(".chat-notices .chat-notices__notice").length,
|
|
0,
|
|
"Notice was cleared"
|
|
);
|
|
});
|
|
test("MentionWithoutMembership notice renders", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
this.manager = this.container.lookup(
|
|
"service:chat-channel-notices-manager"
|
|
);
|
|
const text = "Joffrey can't chat, hermano";
|
|
this.manager.handleNotice({
|
|
channel_id: this.channel.id,
|
|
notice_type: "mention_without_membership",
|
|
data: { user_ids: [1], message_id: 1, text },
|
|
});
|
|
|
|
await render(
|
|
<template><ChatNotices @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert.strictEqual(
|
|
queryAll(
|
|
".chat-notices .chat-notices__notice .mention-without-membership-notice"
|
|
).length,
|
|
1,
|
|
"Notice is present"
|
|
);
|
|
|
|
assert.dom(".mention-without-membership-notice__body__text").hasText(text);
|
|
assert
|
|
.dom(".mention-without-membership-notice__body__link")
|
|
.hasText(i18n("chat.mention_warning.invite"));
|
|
|
|
pretender.post(`/chat/api/channels/${this.channel.id}/invites`, () => {
|
|
return [200, { "Content-Type": "application/json" }, {}];
|
|
});
|
|
|
|
await click(".mention-without-membership-notice__body__link");
|
|
|
|
// I would love to test that the invitation sent text is present here but
|
|
// dismiss is called right away instead of waiting 3 seconds.. Not much we can
|
|
// do about this - at least we are testing that nothing broke all the way through
|
|
// clearing the notice
|
|
assert.strictEqual(
|
|
queryAll(
|
|
".chat-notices .chat-notices__notice .mention-without-membership-notice"
|
|
).length,
|
|
0,
|
|
"Notice has been cleared"
|
|
);
|
|
});
|
|
});
|