discourse/plugins/chat/test/javascripts/components/chat-channel-metadata-test.gjs
Jarek Radosz 893fcf714b
DEV: Remove plugin names from test titles (#39418)
Those are now automatically included in testem's output.
2026-04-21 19:19:52 +02:00

50 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("Component | chat-channel-metadata", function (hooks) {
setupRenderingTest(hooks);
test("displays created at placeholder for empty chat", async function (assert) {
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={{this.channel}} /></template>
);
assert.dom(".chat-channel__metadata-date").hasText("");
});
test("displays last message created at", async function (assert) {
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={{this.channel}} /></template>
);
assert.dom(".chat-channel__metadata-date").hasText("Yesterday");
lastMessageSentAt = moment();
this.channel.lastMessage.createdAt = lastMessageSentAt;
await render(
<template><ChatChannelMetadata @channel={{this.channel}} /></template>
);
assert
.dom(".chat-channel__metadata-date")
.hasText(lastMessageSentAt.format("LT"));
});
});