2022-11-02 09:41:30 -04:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { render } from "@ember/test-helpers";
|
|
|
|
import { module, test } from "qunit";
|
2023-05-17 11:49:52 -04:00
|
|
|
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2022-11-02 09:41:30 -04:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Component | chat-channel-preview-card",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
2023-05-17 11:49:52 -04:00
|
|
|
this.set("channel", fabricators.channel({ chatable_type: "Category" }));
|
2023-05-08 12:24:41 -04:00
|
|
|
|
|
|
|
this.channel.description = "Important stuff is announced here.";
|
|
|
|
this.channel.title = "announcements";
|
2023-05-10 07:45:13 -04:00
|
|
|
this.channel.meta = { can_join_chat_channel: true };
|
2022-11-02 09:41:30 -04:00
|
|
|
this.currentUser.set("has_chat_enabled", true);
|
|
|
|
this.siteSettings.chat_enabled = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
test("channel title", async function (assert) {
|
2022-12-22 08:35:18 -05:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.strictEqual(
|
2022-11-02 09:41:30 -04:00
|
|
|
query(".chat-channel-title__name").innerText,
|
|
|
|
this.channel.title,
|
|
|
|
"it shows the channel title"
|
|
|
|
);
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.true(
|
2022-11-02 09:41:30 -04:00
|
|
|
exists(query(".chat-channel-title__category-badge")),
|
|
|
|
"it shows the category hashtag badge"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("channel description", async function (assert) {
|
2022-12-22 08:35:18 -05:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.strictEqual(
|
2022-11-02 09:41:30 -04:00
|
|
|
query(".chat-channel-preview-card__description").innerText,
|
|
|
|
this.channel.description,
|
|
|
|
"the channel description is shown"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("no channel description", async function (assert) {
|
2023-05-08 12:24:41 -04:00
|
|
|
this.channel.description = null;
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.false(
|
2022-11-02 09:41:30 -04:00
|
|
|
exists(".chat-channel-preview-card__description"),
|
|
|
|
"no line is left for the channel description if there is none"
|
|
|
|
);
|
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.true(
|
2022-11-02 09:41:30 -04:00
|
|
|
exists(".chat-channel-preview-card.-no-description"),
|
|
|
|
"it adds a modifier class for styling"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("join", async function (assert) {
|
2022-12-22 08:35:18 -05:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.true(
|
2022-11-02 09:41:30 -04:00
|
|
|
exists(".toggle-channel-membership-button.-join"),
|
|
|
|
"it shows the join channel button"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("browse all", async function (assert) {
|
2022-12-22 08:35:18 -05:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.true(
|
2022-11-02 09:41:30 -04:00
|
|
|
exists(".chat-channel-preview-card__browse-all"),
|
|
|
|
"it shows a link to browse all channels"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("closed channel", async function (assert) {
|
2023-05-08 12:24:41 -04:00
|
|
|
this.channel.status = "closed";
|
2022-12-22 08:35:18 -05:00
|
|
|
await render(hbs`<ChatChannelPreviewCard @channel={{this.channel}} />`);
|
2022-11-02 09:41:30 -04:00
|
|
|
|
2022-12-22 08:35:18 -05:00
|
|
|
assert.false(
|
2022-11-02 09:41:30 -04:00
|
|
|
exists(".chat-channel-preview-card__join-channel-btn"),
|
|
|
|
"it does not show the join channel button"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|