mirror of
https://github.com/discourse/discourse.git
synced 2024-12-22 15:03:50 +08:00
e991574389
This change increases the visibility of unread channels to make them stand out more in drawer mode (desktop). When a channel is unread: - it floats to the top; - when multiple channels are unread, they are sorted alphabetically (equal to how it’s done on mobile) - the unread indicator blue dot moves to directly right of the channel name
89 lines
3.1 KiB
Plaintext
89 lines
3.1 KiB
Plaintext
import { getOwner } from "@ember/owner";
|
|
import { render } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import CoreFabricators from "discourse/lib/fabricators";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
import ChannelName from "discourse/plugins/chat/discourse/components/channel-name";
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
|
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
|
|
|
const CHANNEL_NAME_LABEL = ".chat-channel-name__label";
|
|
|
|
module("Discourse Chat | Component | <ChannelName />", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("category channel - label", async function (assert) {
|
|
const channel = new ChatFabricators(getOwner(this)).channel();
|
|
|
|
await render(<template><ChannelName @channel={{channel}} /></template>);
|
|
|
|
assert.strictEqual(query(CHANNEL_NAME_LABEL).innerText, channel.title);
|
|
});
|
|
|
|
test("category channel - escapes label", async function (assert) {
|
|
const channel = new ChatFabricators(getOwner(this)).channel({
|
|
chatable_type: CHATABLE_TYPES.categoryChannel,
|
|
title: "<div class='xss'>evil</div>",
|
|
});
|
|
|
|
await render(<template><ChannelName @channel={{channel}} /></template>);
|
|
|
|
assert.false(exists(".xss"));
|
|
});
|
|
|
|
test("dm channel - one user", async function (assert) {
|
|
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
|
chatable: new ChatFabricators(getOwner(this)).directMessage({
|
|
users: [new CoreFabricators(getOwner(this)).user()],
|
|
}),
|
|
});
|
|
const user = channel.chatable.users[0];
|
|
|
|
await render(<template><ChannelName @channel={{channel}} /></template>);
|
|
|
|
assert.strictEqual(
|
|
query(CHANNEL_NAME_LABEL).innerText.trim(),
|
|
user.username
|
|
);
|
|
});
|
|
|
|
test("dm channel - multiple users", async function (assert) {
|
|
const channel = new ChatFabricators(getOwner(this)).directMessageChannel({
|
|
users: [
|
|
new CoreFabricators(getOwner(this)).user(),
|
|
new CoreFabricators(getOwner(this)).user(),
|
|
new CoreFabricators(getOwner(this)).user(),
|
|
],
|
|
});
|
|
channel.chatable.group = true;
|
|
const users = channel.chatable.users;
|
|
|
|
await render(<template><ChannelName @channel={{channel}} /></template>);
|
|
|
|
assert.strictEqual(
|
|
query(CHANNEL_NAME_LABEL).innerText.trim(),
|
|
users.mapBy("username").join(", ")
|
|
);
|
|
});
|
|
|
|
test("unreadIndicator", async function (assert) {
|
|
const channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
|
channel.tracking.unreadCount = 1;
|
|
|
|
let unreadIndicator = true;
|
|
await render(
|
|
<template><ChannelName @channel={{channel}} @unreadIndicator={{unreadIndicator}}/></template>
|
|
);
|
|
|
|
assert.true(exists(".chat-channel-unread-indicator"));
|
|
|
|
unreadIndicator = false;
|
|
await render(
|
|
<template><ChannelName @channel={{channel}} @unreadIndicator={{unreadIndicator}}/></template>
|
|
);
|
|
|
|
assert.false(exists(".chat-channel-unread-indicator"));
|
|
});
|
|
});
|