2024-07-25 15:09:06 +02:00
|
|
|
import { getOwner } from "@ember/owner";
|
2024-05-07 15:38:24 +02:00
|
|
|
import { clearRender, render } from "@ember/test-helpers";
|
2022-11-02 10:41:30 -03:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2023-10-10 19:38:59 +01:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2024-09-17 20:52:34 +02:00
|
|
|
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
2024-04-08 21:00:09 +02:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2022-11-02 10:41:30 -03:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-message", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 14:35:18 +01:00
|
|
|
const template = hbs`
|
2023-06-19 09:50:54 +02:00
|
|
|
<ChatMessage @message={{this.message}} />
|
2022-12-22 14:35:18 +01:00
|
|
|
`;
|
2022-11-02 10:41:30 -03:00
|
|
|
|
|
|
|
test("Message with edits", async function (assert) {
|
2024-04-08 21:00:09 +02:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
edited: true,
|
|
|
|
});
|
2022-11-02 10:41:30 -03:00
|
|
|
await render(template);
|
2023-05-08 18:24:41 +02:00
|
|
|
|
2023-06-16 14:04:11 +02:00
|
|
|
assert.true(exists(".chat-message-edited"), "has the correct css class");
|
2022-11-02 10:41:30 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Deleted message", async function (assert) {
|
2024-04-08 21:00:09 +02:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-06-16 14:04:11 +02:00
|
|
|
user: this.currentUser,
|
|
|
|
deleted_at: moment(),
|
|
|
|
});
|
2022-11-02 10:41:30 -03:00
|
|
|
await render(template);
|
2023-03-03 13:09:25 +01:00
|
|
|
|
2022-12-22 14:35:18 +01:00
|
|
|
assert.true(
|
2023-06-19 09:50:54 +02:00
|
|
|
exists(".chat-message-text.-deleted .chat-message-expand"),
|
2023-06-16 14:04:11 +02:00
|
|
|
"has the correct css class and expand button within"
|
2022-11-02 10:41:30 -03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Hidden message", async function (assert) {
|
2024-04-08 21:00:09 +02:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
hidden: true,
|
|
|
|
});
|
2022-11-02 10:41:30 -03:00
|
|
|
await render(template);
|
2023-05-08 18:24:41 +02:00
|
|
|
|
2022-12-22 14:35:18 +01:00
|
|
|
assert.true(
|
2023-06-19 09:50:54 +02:00
|
|
|
exists(".chat-message-text.-hidden .chat-message-expand"),
|
2023-06-16 14:04:11 +02:00
|
|
|
"has the correct css class and expand button within"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-09-17 20:52:34 +02:00
|
|
|
test("message with mark html tag", async function (assert) {
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
message: "what <mark>test</mark>",
|
|
|
|
});
|
|
|
|
await this.message.cook();
|
|
|
|
await render(template);
|
|
|
|
|
|
|
|
assert.true(
|
|
|
|
query(".chat-message-text")
|
|
|
|
.innerHTML.trim()
|
|
|
|
.includes("<p>what <mark>test</mark></p>")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-06-16 14:04:11 +02:00
|
|
|
test("Message with reply", async function (assert) {
|
2024-04-08 21:00:09 +02:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
inReplyTo: new ChatFabricators(getOwner(this)).message(),
|
|
|
|
});
|
2023-06-16 14:04:11 +02:00
|
|
|
await render(template);
|
|
|
|
|
|
|
|
assert.true(
|
|
|
|
exists(".chat-message-container.has-reply"),
|
|
|
|
"has the correct css class"
|
2022-11-02 10:41:30 -03:00
|
|
|
);
|
|
|
|
});
|
2024-05-07 15:38:24 +02:00
|
|
|
|
|
|
|
test("Message with streaming", async function (assert) {
|
|
|
|
// admin
|
|
|
|
this.currentUser.admin = true;
|
|
|
|
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
inReplyTo: new ChatFabricators(getOwner(this)).message(),
|
|
|
|
streaming: true,
|
|
|
|
});
|
|
|
|
await this.message.cook();
|
|
|
|
await render(template);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".stop-streaming-btn")
|
|
|
|
.exists("when admin, it has the stop streaming button");
|
|
|
|
|
|
|
|
await clearRender();
|
|
|
|
|
|
|
|
// not admin - not replying to current user
|
|
|
|
this.currentUser.admin = false;
|
|
|
|
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
inReplyTo: new ChatFabricators(getOwner(this)).message(),
|
|
|
|
streaming: true,
|
|
|
|
});
|
|
|
|
await this.message.cook();
|
|
|
|
await render(template);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".stop-streaming-btn")
|
|
|
|
.doesNotExist("when admin, it doesn't have the stop streaming button");
|
|
|
|
|
|
|
|
await clearRender();
|
|
|
|
|
|
|
|
// not admin - replying to current user
|
|
|
|
this.currentUser.admin = false;
|
|
|
|
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
inReplyTo: new ChatFabricators(getOwner(this)).message({
|
|
|
|
user: this.currentUser,
|
|
|
|
}),
|
|
|
|
streaming: true,
|
|
|
|
});
|
|
|
|
await this.message.cook();
|
|
|
|
await render(template);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".stop-streaming-btn")
|
|
|
|
.exists(
|
|
|
|
"when replying to current user, it has the stop streaming button"
|
|
|
|
);
|
|
|
|
});
|
2022-11-02 10:41:30 -03:00
|
|
|
});
|