]>
git.r.bdr.sh - rbdr/forum/blob - src/components/topic/topic.test.js
ca1abfbaa4958e8a3a518f1c9bed1cb7c3e2119f
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 test('Should send index and countt to posts', () => {
110 expect(internals
.results
.getByTitle('Post 1 of 2 by past_user'))
112 expect(internals
.results
.getByTitle('Post 2 of 2 by future_user'))
116 describe('Forum link', () => {
118 test('Should show forum if the post has one', () => {
120 expect(internals
.results
.getByText(/^\s*⏃\s*Diversion\s*$/))
124 test('Forum text should be a permalink to the forum', () => {
126 expect(internals
.results
.getByText(/^\s*⏃\s*Diversion\s*$/).closest('a'))
127 .toHaveAttribute('href', '/f/diversion');
130 test('Should not show forum if the post doesn\'t have one', () => {
133 internals
.results
= render(Topic
, { props: {
134 topic: internals
.topicWithoutForum
137 expect(internals
.results
.queryByText(/^\s*⏃\s*Diversion\s*$/))
142 describe('Tag listing', () => {
144 test('Should show topic tags', () => {
146 expect(internals
.results
.getByText('fish'))
148 expect(internals
.results
.getByText('fish'))
149 .toHaveTextContent('fish(40)');
150 expect(internals
.results
.getByText('statue'))
152 expect(internals
.results
.getByText('statue'))
153 .toHaveTextContent('statue(5)');
156 test('Tag text should be a permalink to the tag', () => {
158 expect(internals
.results
.getByText('fish').closest('a'))
159 .toHaveAttribute('href', '/g/fish');
160 expect(internals
.results
.getByText('statue').closest('a'))
161 .toHaveAttribute('href', '/g/statue');