mirror of
https://github.com/discourse/discourse.git
synced 2026-08-15 14:06:35 +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.
71 lines
2.3 KiB
Text
Vendored
71 lines
2.3 KiB
Text
Vendored
import { getOwner } from "@ember/owner";
|
|
import { click, render } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { forceMobile } from "discourse/lib/mobile";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
|
import { i18n } from "discourse-i18n";
|
|
import ChatChannelLeaveBtn from "discourse/plugins/chat/discourse/components/chat-channel-leave-btn";
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
|
|
|
module("Component | ChatChannelLeaveBtn", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("accepts an optional onLeaveChannel callback", async function (assert) {
|
|
this.foo = 1;
|
|
this.onLeaveChannel = () => (this.foo = 2);
|
|
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
|
|
|
await render(
|
|
<template>
|
|
<ChatChannelLeaveBtn
|
|
@channel={{this.channel}}
|
|
@onLeaveChannel={{this.onLeaveChannel}}
|
|
/>
|
|
</template>
|
|
);
|
|
|
|
pretender.post("/chat/chat_channels/:chatChannelId/unfollow", () => {
|
|
return [200, { current_user_membership: { following: false } }, {}];
|
|
});
|
|
assert.strictEqual(this.foo, 1);
|
|
|
|
await click(".chat-channel-leave-btn");
|
|
assert.strictEqual(this.foo, 2);
|
|
});
|
|
|
|
test("has a specific title for direct message channel", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
|
|
|
await render(
|
|
<template><ChatChannelLeaveBtn @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-leave-btn")
|
|
.hasAttribute("title", i18n("chat.direct_messages.leave"));
|
|
});
|
|
|
|
test("has a specific title for message channel", async function (assert) {
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
|
|
await render(
|
|
<template><ChatChannelLeaveBtn @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-leave-btn")
|
|
.hasAttribute("title", i18n("chat.leave"));
|
|
});
|
|
|
|
test("is not visible on mobile", async function (assert) {
|
|
forceMobile();
|
|
this.channel = new ChatFabricators(getOwner(this)).channel();
|
|
|
|
await render(
|
|
<template><ChatChannelLeaveBtn @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert.dom(".chat-channel-leave-btn").doesNotExist();
|
|
});
|
|
});
|