]> git.r.bdr.sh - rbdr/forum/blob - src/components/forum/forum.test.js
832fd6cf79cfccdda234f15645217dec2daf0e37
[rbdr/forum] / src / components / forum / forum.test.js
1 import '@testing-library/jest-dom/extend-expect';
2
3 import { addMessages } from 'svelte-i18n';
4
5 import { render } from '@testing-library/svelte';
6 import '$/config/i18n';
7
8 import Forum from './forum.svelte';
9
10 const internals = {
11 results: null
12 };
13
14 describe('Forum component', () => {
15
16 beforeAll(() => {
17
18 addMessages('en', {
19 'test_forums.oleo': 'Oleo'
20 });
21 });
22
23 beforeEach(() => {
24
25 internals.results = render(Forum, { props: {
26 forum: {
27 id: 'oleo',
28 glyph: '☽',
29 label: 'test_forums.oleo',
30 topics: [
31 {
32 id: '0575d375-5bea-44df-a597-bee3adda624d',
33 title: 'Very forumy topic',
34 ttl: 160 * 1000,
35 updated_at: Date.now()
36 },
37 {
38 id: 'aeeb56e4-751d-4400-8aa7-d0f3a20d4e25',
39 title: 'Only mildly forum-like',
40 ttl: 160 * 1000,
41 updated_at: Date.now()
42 }
43 ]
44 }
45 } });
46 });
47
48 test('It should display the forum glyph and label', () => {
49
50 expect(internals.results.getByText(/^\s*☽\s*Oleo\s*$/))
51 .toBeVisible();
52 });
53
54 test('It should display the topics', () => {
55
56 expect(internals.results.getByText('Very forumy topic'))
57 .toBeVisible();
58 expect(internals.results.getByText('Only mildly forum-like'))
59 .toBeVisible();
60 });
61
62 test('It should link to the topics', () => {
63
64 expect(internals.results.getByText('Very forumy topic').closest('a'))
65 .toHaveAttribute('href', '/t/0575d375-5bea-44df-a597-bee3adda624d');
66 expect(internals.results.getByText('Only mildly forum-like').closest('a'))
67 .toHaveAttribute('href', '/t/aeeb56e4-751d-4400-8aa7-d0f3a20d4e25');
68 });
69 });