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";
|
2022-11-02 21:41:30 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import I18n from "I18n";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { module, test } from "qunit";
|
2022-11-02 21:41:30 +08:00
|
|
|
import User from "discourse/models/user";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-message-info", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("chat_webhook_event", async function (assert) {
|
|
|
|
this.set("message", { chat_webhook_event: { username: "discobot" } });
|
|
|
|
|
|
|
|
await render(hbs`<ChatMessageInfo @message={{this.message}} />`);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-message-info__username").innerText.trim(),
|
|
|
|
this.message.chat_webhook_event.username
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-message-info__bot-indicator").textContent.trim(),
|
|
|
|
I18n.t("chat.bot")
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("user", async function (assert) {
|
|
|
|
this.set("message", { user: { username: "discobot" } });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatMessageInfo @message={{this.message}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-message-info__username").innerText.trim(),
|
|
|
|
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) {
|
|
|
|
this.set("message", {
|
|
|
|
user: { username: "discobot" },
|
|
|
|
created_at: moment(),
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatMessageInfo @message={{this.message}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.true(exists(".chat-message-info__date"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("bookmark (with reminder)", async function (assert) {
|
|
|
|
this.set("message", {
|
|
|
|
user: { username: "discobot" },
|
|
|
|
bookmark: Bookmark.create({
|
|
|
|
reminder_at: moment(),
|
|
|
|
name: "some name",
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<ChatMessageInfo @message={{this.message}} />`);
|
|
|
|
|
|
|
|
assert.true(
|
|
|
|
exists(".chat-message-info__bookmark .d-icon-discourse-bookmark-clock")
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("bookmark (no reminder)", async function (assert) {
|
|
|
|
this.set("message", {
|
|
|
|
user: { username: "discobot" },
|
|
|
|
bookmark: Bookmark.create({
|
|
|
|
name: "some name",
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<ChatMessageInfo @message={{this.message}} />`);
|
|
|
|
|
|
|
|
assert.true(exists(".chat-message-info__bookmark .d-icon-bookmark"));
|
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" };
|
|
|
|
this.set("message", { user: User.create({ status }) });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
await render(hbs`<ChatMessageInfo @message={{this.message}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.true(exists(".chat-message-info__status .user-status-message"));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("reviewable", async function (assert) {
|
|
|
|
this.set("message", {
|
|
|
|
user: { username: "discobot" },
|
|
|
|
user_flag_status: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<ChatMessageInfo @message={{this.message}} />`);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-message-info__flag > .svg-icon-title").title,
|
|
|
|
I18n.t("chat.you_flagged")
|
|
|
|
);
|
|
|
|
|
|
|
|
this.set("message", {
|
|
|
|
user: { username: "discobot" },
|
|
|
|
reviewable_id: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-message-info__flag a .svg-icon-title").title,
|
|
|
|
I18n.t("chat.flagged")
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
});
|