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.
98 lines
2.9 KiB
Text
Vendored
98 lines
2.9 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 ChatChannelPreviewCard from "discourse/plugins/chat/discourse/components/chat-channel-preview-card";
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
|
|
|
module("Component | ChatChannelPreviewCard", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.set(
|
|
"channel",
|
|
new ChatFabricators(getOwner(this)).channel({
|
|
chatable_type: "Category",
|
|
})
|
|
);
|
|
|
|
this.channel.description = "Important stuff is announced here.";
|
|
this.channel.title = "announcements";
|
|
this.channel.meta = { can_join_chat_channel: true };
|
|
this.currentUser.set("has_chat_enabled", true);
|
|
this.siteSettings.chat_enabled = true;
|
|
});
|
|
|
|
test("channel title", async function (assert) {
|
|
await render(
|
|
<template><ChatChannelPreviewCard @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-name__label")
|
|
.hasText(this.channel.title, "shows the channel title");
|
|
|
|
assert
|
|
.dom(".chat-channel-icon.--icon")
|
|
.exists("shows the category hashtag badge");
|
|
});
|
|
|
|
test("channel description", async function (assert) {
|
|
await render(
|
|
<template><ChatChannelPreviewCard @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-preview-card__description")
|
|
.hasText(this.channel.description, "the channel description is shown");
|
|
});
|
|
|
|
test("no channel description", async function (assert) {
|
|
this.channel.description = null;
|
|
|
|
await render(
|
|
<template><ChatChannelPreviewCard @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-preview-card__description")
|
|
.doesNotExist(
|
|
"no line is left for the channel description if there is none"
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-preview-card.-no-description")
|
|
.exists("adds a modifier class for styling");
|
|
});
|
|
|
|
test("join", async function (assert) {
|
|
await render(
|
|
<template><ChatChannelPreviewCard @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".toggle-channel-membership-button.-join")
|
|
.exists("shows the join channel button");
|
|
});
|
|
|
|
test("browse all", async function (assert) {
|
|
await render(
|
|
<template><ChatChannelPreviewCard @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-preview-card__browse-all")
|
|
.exists("shows a link to browse all channels");
|
|
});
|
|
|
|
test("closed channel", async function (assert) {
|
|
this.channel.status = "closed";
|
|
await render(
|
|
<template><ChatChannelPreviewCard @channel={{this.channel}} /></template>
|
|
);
|
|
|
|
assert
|
|
.dom(".chat-channel-preview-card__join-channel-btn")
|
|
.doesNotExist("it does not show the join channel button");
|
|
});
|
|
});
|