]>
git.r.bdr.sh - rbdr/forum/blob - src/components/topic/topic.test.js
83eeba3cbc611e4f04267a26d549c1cf6abeca79
1 import '@testing-library/jest-dom/extend-expect';
3 import { addMessages
} from 'svelte-i18n';
5 import { cleanup
, render
} from '@testing-library/svelte';
6 import '$/config/i18n';
8 import Topic
from './topic.svelte';
13 id: 'b1a4f8d1-4d16-4872-b391-fda6a0e9012d',
14 title: 'I sure am a test topic',
16 updated_at: Date
.now(),
20 label: 'test_forums.diversion'
34 id: '413a74db-9473-4bac-8698-da9452c05854',
35 text: 'This is the first post',
36 created_at: Date
.UTC(1999, 7, 1, 8, 8, 2, 111).valueOf(),
39 id: 'c76d3e51-76ac-4e84-a1b2-2eee9abd68b3'
43 id: '821ff177-5250-406f-9431-1a8097b35430',
44 text: 'This response came later',
45 created_at: Date
.UTC(2038, 1, 2, 3, 4, 6, 789).valueOf(),
47 handle: 'future_user',
48 id: 'cb9307cb-77e9-4c55-bbe7-dbbf88737358'
54 id: '9715e9ee-0d63-4b50-b613-826ef2791728',
55 title: 'This topic, no forums',
57 updated_at: Date
.now(),
68 describe('Topic component', () => {
73 'test_forums.diversion': 'Diversion'
79 internals
.results
= render(Topic
, { props: {
80 topic: internals
.basicTopic
84 test('Should show the topic title', () => {
86 expect(internals
.results
.getByText('I sure am a test topic'))
89 test('Should display remaining time in readable format', () => {
91 expect(internals
.results
.getByText(/2 minutes remaining
/))
94 test('Remaining time should be a permalink to the topic', () => {
96 expect(internals
.results
.getByText(/2 minutes remaining
/).closest('a'))
97 .toHaveAttribute('href', '/t/b1a4f8d1-4d16-4872-b391-fda6a0e9012d');
100 test('Should show text for all posts', () => {
102 expect(internals
.results
.getByText('This is the first post'))
104 expect(internals
.results
.getByText('This response came later'))
108 describe('Forum link', () => {
110 test('Should show forum if the post has one', () => {
112 expect(internals
.results
.getByText(/^\s*⏃\s*Diversion\s*$/))
116 test('Forum text should be a permalink to the forum', () => {
118 expect(internals
.results
.getByText(/^\s*⏃\s*Diversion\s*$/).closest('a'))
119 .toHaveAttribute('href', '/f/diversion');
122 test('Should not show forum if the post doesn\'t have one', () => {
125 internals
.results
= render(Topic
, { props: {
126 topic: internals
.topicWithoutForum
129 expect(internals
.results
.queryByText(/^\s*⏃\s*Diversion\s*$/))
134 describe('Tag listing', () => {
136 test('Should show topic tags', () => {
138 expect(internals
.results
.getByText('fish'))
140 expect(internals
.results
.getByText('fish'))
141 .toHaveTextContent('fish(40)');
142 expect(internals
.results
.getByText('statue'))
144 expect(internals
.results
.getByText('statue'))
145 .toHaveTextContent('statue(5)');
148 test('Tag text should be a permalink to the tag', () => {
150 expect(internals
.results
.getByText('fish').closest('a'))
151 .toHaveAttribute('href', '/g/fish');
152 expect(internals
.results
.getByText('statue').closest('a'))
153 .toHaveAttribute('href', '/g/statue');