]>
Commit | Line | Data |
---|---|---|
a7cf03c1 RBR |
1 | /** |
2 | * @jest-environment jsdom | |
3 | */ | |
4 | ||
4e6be9f4 RBR |
5 | import '@testing-library/jest-dom/extend-expect'; |
6 | ||
7 | import { addMessages } from 'svelte-i18n'; | |
8 | ||
9 | import { render } from '@testing-library/svelte'; | |
a7cf03c1 | 10 | import '$lib/i18n'; |
4e6be9f4 RBR |
11 | |
12 | import Forum from './forum.svelte'; | |
13 | ||
14 | const internals = { | |
cac85db0 | 15 | results: null |
4e6be9f4 RBR |
16 | }; |
17 | ||
18 | describe('Forum component', () => { | |
cac85db0 RBR |
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 | }); | |
4e6be9f4 | 70 | }); |