mirror of
https://github.com/discourse/discourse.git
synced 2024-12-04 23:04:27 +08:00
09277bc543
This commit adds a new "My threads" link in sidebar and drawer. This link will open the "/chat/threads" page which contains all threads where the current user is a member. It's ordered by activity (unread and then last message created). Moreover, the threads list of a channel page is now showing every threads of a channel, and not just the ones where you are a member.
96 lines
3.0 KiB
JavaScript
96 lines
3.0 KiB
JavaScript
import { render } from "@ember/test-helpers";
|
|
import hbs from "htmlbars-inline-precompile";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
|
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
|
|
|
module("Discourse Chat | Component | <ChannelTitle />", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("category channel", async function (assert) {
|
|
this.channel = fabricators.channel();
|
|
|
|
await render(hbs`<ChannelTitle @channel={{this.channel}} />`);
|
|
|
|
assert.strictEqual(
|
|
query(".chat-channel-title__category-badge").getAttribute("style"),
|
|
`color: #${this.channel.chatable.color}`
|
|
);
|
|
assert.strictEqual(
|
|
query(".chat-channel-title__name").innerText,
|
|
this.channel.title
|
|
);
|
|
});
|
|
|
|
test("category channel - escapes title", async function (assert) {
|
|
this.channel = fabricators.channel({
|
|
chatable_type: CHATABLE_TYPES.categoryChannel,
|
|
title: "<div class='xss'>evil</div>",
|
|
});
|
|
|
|
await render(hbs`<ChannelTitle @channel={{this.channel}} />`);
|
|
|
|
assert.false(exists(".xss"));
|
|
});
|
|
|
|
test("category channel - read restricted", async function (assert) {
|
|
this.channel = fabricators.channel({
|
|
chatable: fabricators.category({ read_restricted: true }),
|
|
});
|
|
|
|
await render(hbs`<ChannelTitle @channel={{this.channel}} />`);
|
|
|
|
assert.true(exists(".d-icon-lock"));
|
|
});
|
|
|
|
test("category channel - not read restricted", async function (assert) {
|
|
this.channel = fabricators.channel({
|
|
chatable: fabricators.category({ read_restricted: false }),
|
|
});
|
|
|
|
await render(hbs`<ChannelTitle @channel={{this.channel}} />`);
|
|
|
|
assert.false(exists(".d-icon-lock"));
|
|
});
|
|
|
|
test("direct message channel - one user", async function (assert) {
|
|
this.channel = fabricators.directMessageChannel({
|
|
chatable: fabricators.directMessage({
|
|
users: [fabricators.user()],
|
|
}),
|
|
});
|
|
|
|
await render(hbs`<ChannelTitle @channel={{this.channel}} />`);
|
|
|
|
const user = this.channel.chatable.users[0];
|
|
|
|
assert.true(exists(`.chat-user-avatar .avatar[title="${user.username}"]`));
|
|
assert.strictEqual(
|
|
query(".chat-channel-title__name").innerText.trim(),
|
|
user.username
|
|
);
|
|
});
|
|
|
|
test("direct message channel - multiple users", async function (assert) {
|
|
this.channel = fabricators.directMessageChannel({
|
|
users: [fabricators.user(), fabricators.user(), fabricators.user()],
|
|
});
|
|
this.channel.chatable.group = true;
|
|
|
|
await render(hbs`<ChannelTitle @channel={{this.channel}} />`);
|
|
|
|
const users = this.channel.chatable.users;
|
|
|
|
assert.strictEqual(
|
|
parseInt(query(".chat-channel-title__users-count").innerText.trim(), 10),
|
|
users.length
|
|
);
|
|
assert.strictEqual(
|
|
query(".chat-channel-title__name").innerText.trim(),
|
|
users.mapBy("username").join(", ")
|
|
);
|
|
});
|
|
});
|