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', () => {
77 'test_forums.diversion': 'Diversion'
83 internals.results = render(Topic, { props: {
84 topic: internals.basicTopic
88 test('Should show the topic title', () => {
90 expect(internals.results.getByText('I sure am a test topic'))
93 test('Should display remaining time in readable format', () => {
95 expect(internals.results.getByText(/2 minutes remaining/))
98 test('Remaining time should be a permalink to the topic', () => {
100 expect(internals.results.getByText(/2 minutes remaining/).closest('a'))
101 .toHaveAttribute('href', '/t/b1a4f8d1-4d16-4872-b391-fda6a0e9012d');
104 test('Should show text for all posts', () => {
106 expect(internals.results.getByText('This is the first post'))
108 expect(internals.results.getByText('This response came later'))
112 test('Should send index and count to posts', () => {
114 expect(internals.results.getByTitle('Post 1 of 2 by past_user'))
116 expect(internals.results.getByTitle('Post 2 of 2 by future_user'))
120 describe('Forum link', () => {
122 test('Should show forum if the post has one', () => {
124 expect(internals.results.getByText(/^\s*⏃\s*Diversion\s*$/))
128 test('Forum text should be a permalink to the forum', () => {
130 expect(internals.results.getByText(/^\s*⏃\s*Diversion\s*$/).closest('a'))
131 .toHaveAttribute('href', '/f/diversion');
134 test('Should not show forum if the post doesn\'t have one', () => {
137 internals.results = render(Topic, { props: {
138 topic: internals.topicWithoutForum
141 expect(internals.results.queryByText(/^\s*⏃\s*Diversion\s*$/))
146 describe('Tag listing', () => {
148 test('Should show topic tags', () => {
150 expect(internals.results.getByText('fish'))
152 expect(internals.results.getByText('fish'))
153 .toHaveTextContent('fish(40)');
154 expect(internals.results.getByText('statue'))
156 expect(internals.results.getByText('statue'))
157 .toHaveTextContent('statue(5)');
160 test('Tag text should be a permalink to the tag', () => {
162 expect(internals.results.getByText('fish').closest('a'))
163 .toHaveAttribute('href', '/g/fish');
164 expect(internals.results.getByText('statue').closest('a'))
165 .toHaveAttribute('href', '/g/statue');