2 * @jest-environment jsdom
5 import '@testing-library/jest-dom/extend-expect';
7 import { addMessages } from 'svelte-i18n';
9 import { cleanup, render } from '@testing-library/svelte';
12 import Topic from './topic.svelte';
17 id: 'b1a4f8d1-4d16-4872-b391-fda6a0e9012d',
18 title: 'I sure am a test topic',
20 updated_at: Date.now(),
24 label: 'test_forums.diversion'
38 id: '413a74db-9473-4bac-8698-da9452c05854',
39 text: 'This is the first post',
40 created_at: Date.UTC(1999, 7, 1, 8, 8, 2, 111).valueOf(),
43 id: 'c76d3e51-76ac-4e84-a1b2-2eee9abd68b3'
47 id: '821ff177-5250-406f-9431-1a8097b35430',
48 text: 'This response came later',
49 created_at: Date.UTC(2038, 1, 2, 3, 4, 6, 789).valueOf(),
51 handle: 'future_user',
52 id: 'cb9307cb-77e9-4c55-bbe7-dbbf88737358'
58 id: '9715e9ee-0d63-4b50-b613-826ef2791728',
59 title: 'This topic, no forums',
61 updated_at: Date.now(),
72 describe('Topic component', () => {
75 'test_forums.diversion': 'Diversion'
80 internals.results = render(Topic, {
82 topic: internals.basicTopic
87 test('Should show the topic title', () => {
88 expect(internals.results.getByText('I sure am a test topic')).toBeVisible();
90 test('Should display remaining time in readable format', () => {
91 expect(internals.results.getByText(/2 minutes remaining/)).toBeVisible();
93 test('Remaining time should be a permalink to the topic', () => {
94 expect(internals.results.getByText(/2 minutes remaining/).closest('a')).toHaveAttribute(
96 '/t/b1a4f8d1-4d16-4872-b391-fda6a0e9012d'
100 test('Should show text for all posts', () => {
101 expect(internals.results.getByText('This is the first post')).toBeVisible();
102 expect(internals.results.getByText('This response came later')).toBeVisible();
105 test('Should send index and count to posts', () => {
106 expect(internals.results.getByTitle('Post 1 of 2 by past_user')).toBeVisible();
107 expect(internals.results.getByTitle('Post 2 of 2 by future_user')).toBeVisible();
110 describe('Forum link', () => {
111 test('Should show forum if the post has one', () => {
112 expect(internals.results.getByText(/^\s*⏃\s*Diversion\s*$/)).toBeVisible();
115 test('Forum text should be a permalink to the forum', () => {
116 expect(internals.results.getByText(/^\s*⏃\s*Diversion\s*$/).closest('a')).toHaveAttribute(
122 test("Should not show forum if the post doesn't have one", () => {
124 internals.results = render(Topic, {
126 topic: internals.topicWithoutForum
130 expect(internals.results.queryByText(/^\s*⏃\s*Diversion\s*$/)).toBe(null);
134 describe('Tag listing', () => {
135 test('Should show topic tags', () => {
136 expect(internals.results.getByText('fish')).toBeVisible();
137 expect(internals.results.getByText('fish')).toHaveTextContent('fish(40)');
138 expect(internals.results.getByText('statue')).toBeVisible();
139 expect(internals.results.getByText('statue')).toHaveTextContent('statue(5)');
142 test('Tag text should be a permalink to the tag', () => {
143 expect(internals.results.getByText('fish').closest('a')).toHaveAttribute('href', '/g/fish');
144 expect(internals.results.getByText('statue').closest('a')).toHaveAttribute(