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