]>
Commit | Line | Data |
---|---|---|
a7cf03c1 RBR |
1 | /** |
2 | * @jest-environment jsdom | |
3 | */ | |
4 | ||
879fa389 RBR |
5 | import '@testing-library/jest-dom/extend-expect'; |
6 | ||
7 | import { render } from '@testing-library/svelte'; | |
a7cf03c1 | 8 | import '$lib/i18n'; |
879fa389 RBR |
9 | |
10 | import { addMessages } from 'svelte-i18n'; | |
11 | ||
12 | import ForumList from './forum_list.svelte'; | |
13 | ||
14 | const internals = { | |
cac85db0 | 15 | results: null |
879fa389 RBR |
16 | }; |
17 | ||
47b0bfe4 | 18 | describe('Forum List component', () => { |
cac85db0 RBR |
19 | beforeAll(() => { |
20 | addMessages('en', { | |
21 | 'test_forums.yes': 'Absolutely yes', | |
22 | 'test_forums.no': 'No, not at all', | |
23 | 'test_forums.maybe': 'OK, maybe...' | |
24 | }); | |
25 | }); | |
26 | ||
27 | beforeEach(() => { | |
28 | internals.results = render(ForumList, { | |
29 | props: { | |
30 | forums: [ | |
31 | { | |
32 | id: 'yes', | |
33 | glyph: '☆', | |
34 | label: 'test_forums.yes', | |
35 | position: 2 | |
36 | }, | |
37 | { | |
38 | id: 'no', | |
39 | glyph: '◯', | |
40 | label: 'test_forums.no', | |
41 | position: 0 | |
42 | }, | |
43 | { | |
44 | id: 'maybe', | |
45 | glyph: '⏀', | |
46 | label: 'test_forums.maybe', | |
47 | position: 1 | |
48 | } | |
49 | ] | |
50 | } | |
51 | }); | |
52 | }); | |
53 | ||
54 | test('It should display each forum according to their position', () => { | |
55 | expect(internals.results.container).toHaveTextContent(/^◯.+⏀.+☆.+$/); | |
56 | }); | |
57 | ||
58 | test('It should translate forum labels', () => { | |
59 | expect(internals.results.getByText('Absolutely yes')).toBeVisible(); | |
60 | expect(internals.results.getByText('No, not at all')).toBeVisible(); | |
61 | expect(internals.results.getByText('OK, maybe...')).toBeVisible(); | |
62 | }); | |
63 | ||
64 | test('It should display forum glyphs', () => { | |
65 | expect(internals.results.getByText('☆')).toBeVisible(); | |
66 | expect(internals.results.getByText('◯')).toBeVisible(); | |
67 | expect(internals.results.getByText('⏀')).toBeVisible(); | |
68 | }); | |
69 | ||
70 | test('Label should be a permalink to the forum', () => { | |
71 | expect(internals.results.getByText('Absolutely yes').closest('a')).toHaveAttribute( | |
72 | 'href', | |
73 | '/f/yes' | |
74 | ); | |
75 | expect(internals.results.getByText('No, not at all').closest('a')).toHaveAttribute( | |
76 | 'href', | |
77 | '/f/no' | |
78 | ); | |
79 | expect(internals.results.getByText('OK, maybe...').closest('a')).toHaveAttribute( | |
80 | 'href', | |
81 | '/f/maybe' | |
82 | ); | |
83 | }); | |
84 | ||
85 | test('Glyph should be a permalink to the forum', () => { | |
86 | expect(internals.results.getByText('☆').closest('a')).toHaveAttribute('href', '/f/yes'); | |
87 | expect(internals.results.getByText('◯').closest('a')).toHaveAttribute('href', '/f/no'); | |
88 | expect(internals.results.getByText('⏀').closest('a')).toHaveAttribute('href', '/f/maybe'); | |
89 | }); | |
879fa389 | 90 | }); |