discourse/plugins/chat/test/javascripts/components/chat-channel-metadata-test.gjs
Yuriy Kurant c1946425fa
FIX: chat: shows placeholder instead of timer for empty chats (#33105)
For empty chats, a dummy message is created with `id=null` (an
unsaved Ember model). 

The timer or placeholder's display is determined by the message ID's presence now (not the `createdAt` prop).
2025-06-09 15:59:04 +08:00

53 lines
1.8 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getOwner } from "@ember/owner";
import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import ChatChannelMetadata from "discourse/plugins/chat/discourse/components/chat-channel-metadata";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Component | chat-channel-metadata", function (hooks) {
setupRenderingTest(hooks);
test("displays created at placeholder for empty chat", async function (assert) {
const self = this;
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
this.channel.lastMessage = new ChatFabricators(getOwner(this)).message({
channel: this.channel,
created_at: Date.now(),
id: null,
});
await render(
<template><ChatChannelMetadata @channel={{self.channel}} /></template>
);
assert.dom(".chat-channel__metadata-date").hasText("");
});
test("displays last message created at", async function (assert) {
const self = this;
let lastMessageSentAt = moment().subtract(1, "day").format();
this.channel = new ChatFabricators(getOwner(this)).directMessageChannel();
this.channel.lastMessage = new ChatFabricators(getOwner(this)).message({
channel: this.channel,
created_at: lastMessageSentAt,
});
await render(
<template><ChatChannelMetadata @channel={{self.channel}} /></template>
);
assert.dom(".chat-channel__metadata-date").hasText("Yesterday");
lastMessageSentAt = moment();
this.channel.lastMessage.createdAt = lastMessageSentAt;
await render(
<template><ChatChannelMetadata @channel={{self.channel}} /></template>
);
assert
.dom(".chat-channel__metadata-date")
.hasText(lastMessageSentAt.format("LT"));
});
});