2023-03-03 20:09:25 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2023-06-16 20:04:11 +08:00
|
|
|
import fabricators 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) {
|
2023-06-16 20:04:11 +08:00
|
|
|
this.message = fabricators.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) {
|
2023-06-16 20:04:11 +08:00
|
|
|
this.message = fabricators.message({
|
|
|
|
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) {
|
2023-06-16 20:04:11 +08:00
|
|
|
this.message = fabricators.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) {
|
|
|
|
this.message = fabricators.message({ inReplyTo: fabricators.message() });
|
|
|
|
await render(template);
|
|
|
|
|
|
|
|
assert.true(
|
|
|
|
exists(".chat-message-container.has-reply"),
|
|
|
|
"has the correct css class"
|
2022-11-02 21:41:30 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|