2024-07-25 21:09:06 +08:00
|
|
|
import { getOwner } from "@ember/owner";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
2023-10-11 02:38:59 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { module, test } from "qunit";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2024-04-09 03:00:09 +08:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Component | chat-channel-preview-card",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.set(
|
|
|
|
"channel",
|
|
|
|
new ChatFabricators(getOwner(this)).channel({
|
|
|
|
chatable_type: "Category",
|
|
|
|
})
|
|
|
|
);
|
2023-05-09 00:24:41 +08:00
|
|
|
|
|
|
|
this.channel.description = "Important stuff is announced here.";
|
|
|
|
this.channel.title = "announcements";
|
2023-05-10 19:45:13 +08:00
|
|
|
this.channel.meta = { can_join_chat_channel: true };
|
2022-11-02 21:41:30 +08:00
|
|
|
this.currentUser.set("has_chat_enabled", true);
|
|
|
|
this.siteSettings.chat_enabled = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
test("channel title", async function (assert) {
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-30 23:44:51 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-channel-name__label")
|
|
|
|
.hasText(this.channel.title, "shows the channel title");
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-channel-icon.--category-badge")
|
|
|
|
.exists("shows the category hashtag badge");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("channel description", async function (assert) {
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-30 23:44:51 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-channel-preview-card__description")
|
|
|
|
.hasText(this.channel.description, "the channel description is shown");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("no channel description", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel.description = null;
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-10 08:30:33 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-channel-preview-card__description")
|
|
|
|
.doesNotExist(
|
|
|
|
"no line is left for the channel description if there is none"
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-channel-preview-card.-no-description")
|
|
|
|
.exists("adds a modifier class for styling");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("join", async function (assert) {
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert
|
|
|
|
.dom(".toggle-channel-membership-button.-join")
|
|
|
|
.exists("shows the join channel button");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("browse all", async function (assert) {
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-channel-preview-card__browse-all")
|
|
|
|
.exists("shows a link to browse all channels");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("closed channel", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel.status = "closed";
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-10 08:30:33 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-channel-preview-card__join-channel-btn")
|
|
|
|
.doesNotExist("it does not show the join channel button");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|