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";
|
2023-05-17 23:49:52 +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";
|
2024-04-09 03:00:09 +08:00
|
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2023-05-17 23:49:52 +08:00
|
|
|
|
|
|
|
|
|
module(
|
|
|
|
|
"Discourse Chat | Component | chat-composer-message-details",
|
|
|
|
|
function (hooks) {
|
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
|
|
test("data-id attribute", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message();
|
2023-05-17 23:49:52 +08:00
|
|
|
|
|
|
|
|
|
await render(
|
|
|
|
|
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert
|
|
|
|
|
.dom(".chat-composer-message-details")
|
|
|
|
|
.hasAttribute("data-id", this.message.id.toString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("editing a message has the pencil icon", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
|
editing: true,
|
|
|
|
|
});
|
2023-05-17 23:49:52 +08:00
|
|
|
|
|
|
|
|
|
await render(
|
|
|
|
|
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
|
|
|
|
);
|
|
|
|
|
|
2024-09-13 23:50:52 +08:00
|
|
|
|
assert.dom(".chat-composer-message-details .d-icon-pencil").exists();
|
2023-05-17 23:49:52 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("replying to a message has the reply icon", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
|
const firstMessage = new ChatFabricators(getOwner(this)).message();
|
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message({
|
|
|
|
|
inReplyTo: firstMessage,
|
|
|
|
|
});
|
2023-05-17 23:49:52 +08:00
|
|
|
|
|
|
|
|
|
await render(
|
|
|
|
|
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.dom(".chat-composer-message-details .d-icon-reply").exists();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("displays user avatar", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message();
|
2023-05-17 23:49:52 +08:00
|
|
|
|
|
|
|
|
|
await render(
|
|
|
|
|
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert
|
|
|
|
|
.dom(".chat-composer-message-details .chat-user-avatar .avatar")
|
|
|
|
|
.hasAttribute("title", this.message.user.username);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("displays message excerpt", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message();
|
2023-05-17 23:49:52 +08:00
|
|
|
|
|
|
|
|
|
await render(
|
|
|
|
|
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.dom(".chat-reply__excerpt").hasText(this.message.excerpt);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("displays user’s username", async function (assert) {
|
2024-04-09 03:00:09 +08:00
|
|
|
|
this.message = new ChatFabricators(getOwner(this)).message();
|
2023-05-17 23:49:52 +08:00
|
|
|
|
|
|
|
|
|
await render(
|
|
|
|
|
hbs`<ChatComposerMessageDetails @message={{this.message}} />`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.dom(".chat-reply__username").hasText(this.message.user.username);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|