2024-07-25 21:09:06 +08:00
|
|
|
import { getOwner } from "@ember/owner";
|
2024-01-25 22:30:21 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
|
|
|
import { module, test } from "qunit";
|
2024-04-09 03:00:09 +08:00
|
|
|
import CoreFabricators from "discourse/lib/fabricators";
|
2024-01-25 22:30:21 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import ChannelIcon from "discourse/plugins/chat/discourse/components/channel-icon";
|
2024-04-09 03:00:09 +08:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2024-01-25 22:30:21 +08:00
|
|
|
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
|
|
|
|
|
|
|
module("Discourse Chat | Component | <ChannelIcon />", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
test("category channel - badge", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).channel();
|
2024-01-25 22:30:21 +08:00
|
|
|
|
|
|
|
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-channel-icon.--category-badge").getAttribute("style"),
|
|
|
|
`color: #${channel.chatable.color}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("category channel - escapes label", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).channel({
|
2024-01-25 22:30:21 +08:00
|
|
|
chatable_type: CHATABLE_TYPES.categoryChannel,
|
|
|
|
title: "<div class='xss'>evil</div>",
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
|
|
|
|
|
|
|
assert.false(exists(".xss"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("category channel - read restricted", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).channel({
|
|
|
|
chatable: new CoreFabricators(getOwner(this)).category({
|
|
|
|
read_restricted: true,
|
|
|
|
}),
|
2024-01-25 22:30:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
|
|
|
|
|
|
|
assert.true(exists(".d-icon-lock"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("category channel - not read restricted", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).channel({
|
|
|
|
chatable: new CoreFabricators(getOwner(this)).category({
|
|
|
|
read_restricted: false,
|
|
|
|
}),
|
2024-01-25 22:30:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
|
|
|
|
|
|
|
assert.false(exists(".d-icon-lock"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("dm channel - one user", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
|
|
|
chatable: new ChatFabricators(getOwner(this)).directMessage({
|
|
|
|
users: [new CoreFabricators(getOwner(this)).user()],
|
2024-01-25 22:30:21 +08:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
const user = channel.chatable.users[0];
|
|
|
|
|
|
|
|
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
|
|
|
|
|
|
|
assert.true(exists(`.chat-user-avatar .avatar[title="${user.username}"]`));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("dm channel - multiple users", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
|
|
|
users: [
|
|
|
|
new CoreFabricators(getOwner(this)).user(),
|
|
|
|
new CoreFabricators(getOwner(this)).user(),
|
|
|
|
new CoreFabricators(getOwner(this)).user(),
|
|
|
|
],
|
2024-01-25 22:30:21 +08:00
|
|
|
});
|
|
|
|
channel.chatable.group = true;
|
|
|
|
const users = channel.chatable.users;
|
|
|
|
|
|
|
|
await render(<template><ChannelIcon @channel={{channel}} /></template>);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
parseInt(query(".chat-channel-icon.--users-count").innerText.trim(), 10),
|
|
|
|
users.length
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|