2024-07-25 21:09:06 +08:00
|
|
|
import { getOwner } from "@ember/owner";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { module, test } from "qunit";
|
2024-04-09 03:00:09 +08:00
|
|
|
import CoreFabricators from "discourse/lib/fabricators";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-07-10 15:36:20 +08:00
|
|
|
function containerSelector(user, options = {}) {
|
|
|
|
let onlineSelector = ":not(.is-online)";
|
|
|
|
if (options.online) {
|
|
|
|
onlineSelector = ".is-online";
|
|
|
|
}
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-07-10 15:36:20 +08:00
|
|
|
return `.chat-user-avatar${onlineSelector} .chat-user-avatar__container[data-user-card=${user.username}] .avatar[title=${user.username}]`;
|
|
|
|
}
|
|
|
|
|
2023-10-10 03:12:50 +08:00
|
|
|
module("Discourse Chat | Component | <ChatUserAvatar />", function (hooks) {
|
2022-11-02 21:41:30 +08:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2023-10-10 03:12:50 +08:00
|
|
|
test("when user is not online", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.user = new CoreFabricators(getOwner(this)).user();
|
2023-07-10 15:36:20 +08:00
|
|
|
this.chat = { presenceChannel: { users: [] } };
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
await render(
|
2023-10-10 03:12:50 +08:00
|
|
|
hbs`<ChatUserAvatar @chat={{this.chat}} @user={{this.user}} />`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
|
|
|
|
2023-07-10 15:36:20 +08:00
|
|
|
assert.dom(containerSelector(this.user, { online: false })).exists();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("user is online", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.user = new CoreFabricators(getOwner(this)).user();
|
2023-07-10 15:36:20 +08:00
|
|
|
this.chat = {
|
|
|
|
presenceChannel: { users: [{ id: this.user.id }] },
|
|
|
|
};
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
await render(
|
2023-10-10 03:12:50 +08:00
|
|
|
hbs`<ChatUserAvatar @chat={{this.chat}} @user={{this.user}} />`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
|
|
|
|
2023-07-10 15:36:20 +08:00
|
|
|
assert.dom(containerSelector(this.user, { online: true })).exists();
|
|
|
|
});
|
|
|
|
|
2023-10-10 03:12:50 +08:00
|
|
|
test("@showPresence=false", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.user = new CoreFabricators(getOwner(this)).user();
|
2023-07-10 15:36:20 +08:00
|
|
|
this.chat = {
|
|
|
|
presenceChannel: { users: [{ id: this.user.id }] },
|
|
|
|
};
|
|
|
|
|
|
|
|
await render(
|
2023-10-10 03:12:50 +08:00
|
|
|
hbs`<ChatUserAvatar @showPresence={{false}} @chat={{this.chat}} @user={{this.user}} />`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
2023-07-10 15:36:20 +08:00
|
|
|
|
|
|
|
assert.dom(containerSelector(this.user, { online: false })).exists();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
2023-10-10 03:12:50 +08:00
|
|
|
|
|
|
|
test("@interactive=true", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.user = new CoreFabricators(getOwner(this)).user();
|
2023-10-10 03:12:50 +08:00
|
|
|
|
|
|
|
await render(
|
|
|
|
hbs`<ChatUserAvatar @interactive={{false}} @user={{this.user}} />`
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.dom(".clickable").doesNotExist();
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|