]> git.r.bdr.sh - rbdr/forum/blob - src/lib/components/forum/forum.test.ts
Don't remember what this WIP was about
[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 beforeAll(() => {
20 addMessages('en', {
21 'test_forums.oleo': 'Oleo'
22 });
23 });
24
25 beforeEach(() => {
26 internals.results = render(Forum, {
27 props: {
28 forum: {
29 id: 'oleo',
30 glyph: '☽',
31 label: 'test_forums.oleo',
32 topics: [
33 {
34 id: '0575d375-5bea-44df-a597-bee3adda624d',
35 title: 'Very forumy topic',
36 ttl: 160 * 1000,
37 updated_at: Date.now()
38 },
39 {
40 id: 'aeeb56e4-751d-4400-8aa7-d0f3a20d4e25',
41 title: 'Only mildly forum-like',
42 ttl: 160 * 1000,
43 updated_at: Date.now()
44 }
45 ]
46 }
47 }
48 });
49 });
50
51 test('It should display the forum glyph and label', () => {
52 expect(internals.results.getByText(/^\s*☽\s*Oleo\s*$/)).toBeVisible();
53 });
54
55 test('It should display the topics', () => {
56 expect(internals.results.getByText('Very forumy topic')).toBeVisible();
57 expect(internals.results.getByText('Only mildly forum-like')).toBeVisible();
58 });
59
60 test('It should link to the topics', () => {
61 expect(internals.results.getByText('Very forumy topic').closest('a')).toHaveAttribute(
62 'href',
63 '/t/0575d375-5bea-44df-a597-bee3adda624d'
64 );
65 expect(internals.results.getByText('Only mildly forum-like').closest('a')).toHaveAttribute(
66 'href',
67 '/t/aeeb56e4-751d-4400-8aa7-d0f3a20d4e25'
68 );
69 });
70 });