2024-04-09 03:00:09 +08:00
|
|
|
import { getOwner } from "@ember/application";
|
2024-05-07 21:38:24 +08:00
|
|
|
import { clearRender, render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
2024-04-09 03:00:09 +08:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-message", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
const template = hbs`
|
2023-06-19 15:50:54 +08:00
|
|
|
<ChatMessage @message={{this.message}} />
|
2022-12-22 21:35:18 +08:00
|
|
|
`;
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
test("Message with edits", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
edited: true,
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
await render(template);
|
2023-05-09 00:24:41 +08:00
|
|
|
|
2023-06-16 20:04:11 +08:00
|
|
|
assert.true(exists(".chat-message-edited"), "has the correct css class");
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Deleted message", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
2023-06-16 20:04:11 +08:00
|
|
|
user: this.currentUser,
|
|
|
|
deleted_at: moment(),
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
await render(template);
|
2023-03-03 20:09:25 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.true(
|
2023-06-19 15:50:54 +08:00
|
|
|
exists(".chat-message-text.-deleted .chat-message-expand"),
|
2023-06-16 20:04:11 +08:00
|
|
|
"has the correct css class and expand button within"
|
2022-11-02 21:41:30 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Hidden message", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
hidden: true,
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
await render(template);
|
2023-05-09 00:24:41 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.true(
|
2023-06-19 15:50:54 +08:00
|
|
|
exists(".chat-message-text.-hidden .chat-message-expand"),
|
2023-06-16 20:04:11 +08:00
|
|
|
"has the correct css class and expand button within"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Message with reply", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
inReplyTo: new ChatFabricators(getOwner(this)).message(),
|
|
|
|
});
|
2023-06-16 20:04:11 +08:00
|
|
|
await render(template);
|
|
|
|
|
|
|
|
assert.true(
|
|
|
|
exists(".chat-message-container.has-reply"),
|
|
|
|
"has the correct css class"
|
2022-11-02 21:41:30 +08:00
|
|
|
);
|
|
|
|
});
|
2024-05-07 21:38:24 +08: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 21:41:30 +08:00
|
|
|
});
|