A platform for community discussion. Free, open, simple.
import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { withPluginApi } from "discourse/lib/plugin-api";
import Topic from "discourse/models/topic";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import HighContextTopicCard from "../../discourse/components/card/high-context-topic-card.gjs";
function topicFor(attrs = {}) {
return Topic.create({
id: 1,
title: "How do cards work?",
fancy_title: "How do cards work?",
created_at: "2024-06-01T08:00:00Z",
bumped_at: "2024-06-01T18:00:00Z",
last_posted_at: "2024-06-01T12:00:00Z",
last_poster_username: "alice",
posts_count: 3,
like_count: 0,
tags: [],
posters: [
{
extras: "latest single",
user: {
id: 1,
username: "alice",
name: "Alice",
avatar_template: "/letter_avatar_proxy/v4/letter/a/{size}.png",
},
},
],
...attrs,
});
}
module(
"Horizon | Integration | Component | Card | HighContextTopicCard",
function (hooks) {
setupRenderingTest(hooks);
test("renders before-link content with its topic outside the heading", async function (assert) {
withPluginApi((api) => {
api.renderInOutlet(
"topic-list-before-link",
<template>
<span
class="before-link-content"
data-topic-id={{@outletArgs.topic.id}}
>{{@outletArgs.topic.title}}</span>
</template>
);
});
const topic = topicFor();
await render(
<template>
<HighContextTopicCard @hideCategory={{true}} @topic={{topic}} />
</template>
);
assert
.dom(".hc-topic-card__header .before-link-content")
.hasText(topic.title)
.hasAttribute("data-topic-id", String(topic.id));
assert.dom(".hc-topic-card__title .before-link-content").doesNotExist();
assert.dom(".hc-topic-card__title.raw-topic-link").hasText(topic.title);
});
test("shows the last reply line with the actual reply time when a reply is recent", async function (assert) {
const lastPostedAt = "2024-06-01T12:00:00Z";
const topic = topicFor({
bumped_at: "2024-06-01T18:00:00Z",
last_posted_at: lastPostedAt,
});
await render(
<template>
<HighContextTopicCard @hideCategory={{true}} @topic={{topic}} />
</template>
);
assert.dom(".hc-topic-card__last-reply").exists();
assert.dom(".hc-topic-card__last-reply-name").hasText("alice");
assert
.dom(".hc-topic-card__time .relative-date")
.hasAttribute("data-time", String(new Date(lastPostedAt).getTime()));
});
test("hides the last reply line when the topic was bumped more than a day after the last post", async function (assert) {
const topic = topicFor({
bumped_at: "2024-06-10T12:00:00Z",
last_posted_at: "2024-06-01T12:00:00Z",
});
await render(
<template>
<HighContextTopicCard @hideCategory={{true}} @topic={{topic}} />
</template>
);
assert.dom(".hc-topic-card__last-reply").doesNotExist();
assert.dom(".hc-topic-card__context").doesNotExist();
});
}
);