2024-07-25 09:09:06 -04:00
|
|
|
import { getOwner } from "@ember/owner";
|
2023-10-10 14:38:59 -04:00
|
|
|
import { render } from "@ember/test-helpers";
|
|
|
|
import hbs from "htmlbars-inline-precompile";
|
|
|
|
import { module, test } from "qunit";
|
2022-11-28 12:38:05 -05:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2024-04-08 15:00:09 -04:00
|
|
|
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
|
2022-11-28 12:38:05 -05:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-channel-metadata", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2023-07-12 20:28:11 -04:00
|
|
|
test("displays last message created at", async function (assert) {
|
2023-03-03 07:09:25 -05:00
|
|
|
let lastMessageSentAt = moment().subtract(1, "day").format();
|
2024-04-08 15:00:09 -04:00
|
|
|
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
|
|
|
|
this.channel.lastMessage = new ChatFabricators(getOwner(this)).message({
|
2023-07-12 20:28:11 -04:00
|
|
|
channel: this.channel,
|
|
|
|
created_at: lastMessageSentAt,
|
2022-11-28 12:38:05 -05:00
|
|
|
});
|
2023-03-03 07:09:25 -05:00
|
|
|
|
2022-11-28 12:38:05 -05:00
|
|
|
await render(hbs`<ChatChannelMetadata @channel={{this.channel}} />`);
|
|
|
|
|
2024-01-25 09:30:21 -05:00
|
|
|
assert.dom(".chat-channel__metadata-date").hasText("Yesterday");
|
2022-12-05 08:47:01 -05:00
|
|
|
|
|
|
|
lastMessageSentAt = moment();
|
2023-07-12 20:28:11 -04:00
|
|
|
this.channel.lastMessage.createdAt = lastMessageSentAt;
|
2022-12-05 08:47:01 -05:00
|
|
|
await render(hbs`<ChatChannelMetadata @channel={{this.channel}} />`);
|
|
|
|
|
2022-11-28 12:38:05 -05:00
|
|
|
assert
|
2024-01-25 09:30:21 -05:00
|
|
|
.dom(".chat-channel__metadata-date")
|
2022-11-28 12:38:05 -05:00
|
|
|
.hasText(lastMessageSentAt.format("LT"));
|
|
|
|
});
|
|
|
|
});
|