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";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2022-11-02 21:41:30 +08:00
|
|
|
import Bookmark from "discourse/models/bookmark";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2024-12-01 21:00:48 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2024-04-09 03:00:09 +08:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2023-10-11 02:38:59 +08:00
|
|
|
import ChatMessage from "discourse/plugins/chat/discourse/models/chat-message";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
const template = hbs`
|
|
|
|
<Chat::Message::Info @message={{this.message}} @show={{true}} />
|
|
|
|
`;
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("chat_webhook_event", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
chat_webhook_event: { username: "discobot" },
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2024-10-15 23:11:20 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-message-info__username")
|
|
|
|
.hasText(this.message.chatWebhookEvent.username);
|
2024-12-01 21:00:48 +08:00
|
|
|
assert.dom(".chat-message-info__bot-indicator").hasText(i18n("chat.bot"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("user", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
user: { username: "discobot" },
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-10-15 23:11:20 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-message-info__username")
|
|
|
|
.hasText(this.message.user.username);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("date", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
user: { username: "discobot" },
|
|
|
|
created_at: moment(),
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert.dom(".chat-message-info__date").exists();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("bookmark (with reminder)", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
user: { username: "discobot" },
|
|
|
|
bookmark: Bookmark.create({
|
|
|
|
reminder_at: moment(),
|
|
|
|
name: "some name",
|
|
|
|
}),
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-message-info__bookmark .d-icon-discourse-bookmark-clock")
|
|
|
|
.exists();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("bookmark (no reminder)", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = ChatMessage.create(
|
|
|
|
new ChatFabricators(getOwner(this)).channel(),
|
|
|
|
{
|
|
|
|
user: { username: "discobot" },
|
|
|
|
bookmark: Bookmark.create({
|
|
|
|
name: "some name",
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert.dom(".chat-message-info__bookmark .d-icon-bookmark").exists();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("user status", async function (assert) {
|
|
|
|
const status = { description: "off to dentist", emoji: "tooth" };
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
user: { status },
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-09 03:27:32 +08:00
|
|
|
assert.dom(".chat-message-info__status .user-status-message").exists();
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
test("flag status", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
user: { username: "discobot" },
|
|
|
|
user_flag_status: 0,
|
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-message-info__flag > .svg-icon-title")
|
2024-11-20 04:45:18 +08:00
|
|
|
.hasAttribute("title", i18n("chat.you_flagged"));
|
2023-06-19 15:50:54 +08:00
|
|
|
});
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
test("reviewable", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
user: { username: "discobot" },
|
2023-06-19 15:50:54 +08:00
|
|
|
user_flag_status: 0,
|
2023-03-03 20:09:25 +08:00
|
|
|
});
|
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2022-12-22 21:35:18 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
assert
|
|
|
|
.dom(".chat-message-info__flag > .svg-icon-title")
|
2024-11-20 04:45:18 +08:00
|
|
|
.hasAttribute("title", i18n("chat.you_flagged"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
2023-02-17 00:17:16 +08:00
|
|
|
|
|
|
|
test("with username classes", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
user: {
|
|
|
|
username: "discobot",
|
|
|
|
admin: true,
|
|
|
|
moderator: true,
|
|
|
|
new_user: true,
|
|
|
|
primary_group_name: "foo",
|
|
|
|
},
|
|
|
|
});
|
2023-02-17 00:17:16 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2023-02-17 00:17:16 +08:00
|
|
|
|
|
|
|
assert.dom(".chat-message-info__username.is-staff").exists();
|
|
|
|
assert.dom(".chat-message-info__username.is-admin").exists();
|
|
|
|
assert.dom(".chat-message-info__username.is-moderator").exists();
|
|
|
|
assert.dom(".chat-message-info__username.is-new-user").exists();
|
|
|
|
assert.dom(".chat-message-info__username.group--foo").exists();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("without username classes", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-03-03 20:09:25 +08:00
|
|
|
user: { username: "discobot" },
|
|
|
|
});
|
2023-02-17 00:17:16 +08:00
|
|
|
|
2023-06-19 15:50:54 +08:00
|
|
|
await render(template);
|
2023-02-17 00:17:16 +08:00
|
|
|
|
|
|
|
assert.dom(".chat-message-info__username.is-staff").doesNotExist();
|
|
|
|
assert.dom(".chat-message-info__username.is-admin").doesNotExist();
|
|
|
|
assert.dom(".chat-message-info__username.is-moderator").doesNotExist();
|
|
|
|
assert.dom(".chat-message-info__username.is-new-user").doesNotExist();
|
|
|
|
assert.dom(".chat-message-info__username.group--foo").doesNotExist();
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|