mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 19:41:19 +08:00
FIX: makes chat user avatar show presence by default (#22490)
It's way more common to have presence enabled than disabled, so we should have been making it the default from start. This commit also changes the namespace of `<ChatUserAvatar />` into `<Chat::UserAvatar />` and refactors tests.
This commit is contained in:
@ -1,50 +1,55 @@
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import { module, test } from "qunit";
|
||||
import { render } from "@ember/test-helpers";
|
||||
import fabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
||||
|
||||
const user = {
|
||||
id: 1,
|
||||
username: "markvanlan",
|
||||
name: null,
|
||||
avatar_template: "/letter_avatar_proxy/v4/letter/m/48db29/{size}.png",
|
||||
};
|
||||
function containerSelector(user, options = {}) {
|
||||
let onlineSelector = ":not(.is-online)";
|
||||
if (options.online) {
|
||||
onlineSelector = ".is-online";
|
||||
}
|
||||
|
||||
module("Discourse Chat | Component | chat-user-avatar", function (hooks) {
|
||||
return `.chat-user-avatar${onlineSelector} .chat-user-avatar__container[data-user-card=${user.username}] .avatar[title=${user.username}]`;
|
||||
}
|
||||
|
||||
module("Discourse Chat | Component | <Chat::UserAvatar />", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("user is not online", async function (assert) {
|
||||
this.set("user", user);
|
||||
this.set("chat", { presenceChannel: { users: [] } });
|
||||
this.user = fabricators.user();
|
||||
this.chat = { presenceChannel: { users: [] } };
|
||||
|
||||
await render(
|
||||
hbs`<ChatUserAvatar @chat={{this.chat}} @user={{this.user}} />`
|
||||
hbs`<Chat::UserAvatar @chat={{this.chat}} @user={{this.user}} />`
|
||||
);
|
||||
|
||||
assert.true(
|
||||
exists(
|
||||
`.chat-user-avatar .chat-user-avatar-container[data-user-card=${user.username}] .avatar[title=${user.username}]`
|
||||
)
|
||||
);
|
||||
assert.false(exists(".chat-user-avatar.is-online"));
|
||||
assert.dom(containerSelector(this.user, { online: false })).exists();
|
||||
});
|
||||
|
||||
test("user is online", async function (assert) {
|
||||
this.set("user", user);
|
||||
this.set("chat", {
|
||||
presenceChannel: { users: [{ id: user.id }] },
|
||||
});
|
||||
this.user = fabricators.user();
|
||||
this.chat = {
|
||||
presenceChannel: { users: [{ id: this.user.id }] },
|
||||
};
|
||||
|
||||
await render(
|
||||
hbs`<ChatUserAvatar @showPresence={{true}} @chat={{this.chat}} @user={{this.user}} />`
|
||||
hbs`<Chat::UserAvatar @chat={{this.chat}} @user={{this.user}} />`
|
||||
);
|
||||
|
||||
assert.true(
|
||||
exists(
|
||||
`.chat-user-avatar .chat-user-avatar-container[data-user-card=${user.username}] .avatar[title=${user.username}]`
|
||||
)
|
||||
assert.dom(containerSelector(this.user, { online: true })).exists();
|
||||
});
|
||||
|
||||
test("showPresence=false", async function (assert) {
|
||||
this.user = fabricators.user();
|
||||
this.chat = {
|
||||
presenceChannel: { users: [{ id: this.user.id }] },
|
||||
};
|
||||
|
||||
await render(
|
||||
hbs`<Chat::UserAvatar @showPresence={{false}} @chat={{this.chat}} @user={{this.user}} />`
|
||||
);
|
||||
assert.true(exists(".chat-user-avatar.is-online"));
|
||||
|
||||
assert.dom(containerSelector(this.user, { online: false })).exists();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user