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";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2022-11-29 01:38:05 +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";
|
2022-11-29 01:38:05 +08:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-channel-metadata", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2023-07-13 08:28:11 +08:00
|
|
|
test("displays last message created at", async function (assert) {
|
2023-03-03 20:09:25 +08:00
|
|
|
let lastMessageSentAt = moment().subtract(1, "day").format();
|
2024-04-09 03:00:09 +08:00
|
|
|
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
|
|
|
this.channel.lastMessage = new ChatFabricators(getOwner(this)).message({
|
2023-07-13 08:28:11 +08:00
|
|
|
channel: this.channel,
|
|
|
|
created_at: lastMessageSentAt,
|
2022-11-29 01:38:05 +08:00
|
|
|
});
|
2023-03-03 20:09:25 +08:00
|
|
|
|
2022-11-29 01:38:05 +08:00
|
|
|
await render(hbs`<ChatChannelMetadata @channel={{this.channel}} />`);
|
|
|
|
|
2024-01-25 22:30:21 +08:00
|
|
|
assert.dom(".chat-channel__metadata-date").hasText("Yesterday");
|
2022-12-05 21:47:01 +08:00
|
|
|
|
|
|
|
lastMessageSentAt = moment();
|
2023-07-13 08:28:11 +08:00
|
|
|
this.channel.lastMessage.createdAt = lastMessageSentAt;
|
2022-12-05 21:47:01 +08:00
|
|
|
await render(hbs`<ChatChannelMetadata @channel={{this.channel}} />`);
|
|
|
|
|
2022-11-29 01:38:05 +08:00
|
|
|
assert
|
2024-01-25 22:30:21 +08:00
|
|
|
.dom(".chat-channel__metadata-date")
|
2022-11-29 01:38:05 +08:00
|
|
|
.hasText(lastMessageSentAt.format("LT"));
|
|
|
|
});
|
|
|
|
});
|