2022-12-22 21:35:18 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import fabricators from "../helpers/fabricators";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { module, test } from "qunit";
|
2023-05-09 00:24:41 +08:00
|
|
|
import { render, settled } from "@ember/test-helpers";
|
|
|
|
import { joinChannel } from "discourse/tests/helpers/presence-pretender";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Component | chat-replying-indicator",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("not displayed when no one is replying", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel = fabricators.chatChannel();
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await render(hbs`<ChatReplyingIndicator @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.false(exists(".chat-replying-indicator__text"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("displays indicator when user is replying", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel = fabricators.chatChannel();
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await render(hbs`<ChatReplyingIndicator @channel={{this.channel}} />`);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 1,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "sam",
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-replying-indicator__text").innerText,
|
2023-05-09 00:24:41 +08:00
|
|
|
`sam is typing`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("displays indicator when 2 or 3 users are replying", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel = fabricators.chatChannel();
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await render(hbs`<ChatReplyingIndicator @channel={{this.channel}} />`);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 1,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "sam",
|
|
|
|
});
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 2,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "mark",
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-replying-indicator__text").innerText,
|
2023-05-09 00:24:41 +08:00
|
|
|
`sam and mark are typing`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("displays indicator when 3 users are replying", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel = fabricators.chatChannel();
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await render(hbs`<ChatReplyingIndicator @channel={{this.channel}} />`);
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 1,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "sam",
|
|
|
|
});
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 2,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "mark",
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 3,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "joffrey",
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-replying-indicator__text").innerText,
|
2023-05-09 00:24:41 +08:00
|
|
|
`sam, mark and joffrey are typing`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("displays indicator when more than 3 users are replying", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel = fabricators.chatChannel();
|
|
|
|
|
|
|
|
await render(hbs`<ChatReplyingIndicator @channel={{this.channel}} />`);
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 1,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "sam",
|
|
|
|
});
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 2,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "mark",
|
|
|
|
});
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 3,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "joffrey",
|
|
|
|
});
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 4,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "taylor",
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-replying-indicator__text").innerText,
|
2023-05-09 00:24:41 +08:00
|
|
|
`sam, mark and 2 others are typing`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("filters current user from list of repliers", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel = fabricators.chatChannel();
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await render(hbs`<ChatReplyingIndicator @channel={{this.channel}} />`);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await joinChannel("/chat-reply/1", {
|
|
|
|
id: 1,
|
|
|
|
avatar_template: "/images/avatar.png",
|
|
|
|
username: "sam",
|
|
|
|
});
|
|
|
|
|
|
|
|
await joinChannel("/chat-reply/1", this.currentUser);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-replying-indicator__text").innerText,
|
2023-05-09 00:24:41 +08:00
|
|
|
`sam is typing`
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("resets presence when channel is draft", async function (assert) {
|
2023-05-09 00:24:41 +08:00
|
|
|
this.channel = fabricators.chatChannel();
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await render(hbs`<ChatReplyingIndicator @channel={{this.channel}} />`);
|
|
|
|
|
|
|
|
assert.dom(".chat-replying-indicator.is-subscribed").exists();
|
|
|
|
|
|
|
|
this.channel.isDraft = true;
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
await settled();
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-05-09 00:24:41 +08:00
|
|
|
assert.dom(".chat-replying-indicator.is-subscribed").doesNotExist();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|