]>
Commit | Line | Data |
---|---|---|
a7cf03c1 RBR |
1 | /** |
2 | * @jest-environment jsdom | |
3 | */ | |
4 | ||
47b0bfe4 RBR |
5 | import '@testing-library/jest-dom/extend-expect'; |
6 | ||
7 | import { render } from '@testing-library/svelte'; | |
a7cf03c1 | 8 | import '$lib/i18n'; |
47b0bfe4 RBR |
9 | |
10 | import Tag from './tag.svelte'; | |
11 | ||
12 | const internals = { | |
13 | results: null | |
14 | }; | |
15 | ||
16 | describe('Tag component', () => { | |
17 | ||
18 | beforeEach(() => { | |
19 | ||
20 | internals.results = render(Tag, { props: { | |
21 | tag: { | |
22 | id: 'avocado', | |
23 | topics: [ | |
24 | { | |
25 | id: 'eb751e7a-5777-46c3-b81b-cc66546d5157', | |
26 | title: 'A single topic', | |
27 | ttl: 160 * 1000, | |
28 | updated_at: Date.now() | |
29 | }, | |
30 | { | |
31 | id: 'b4a5613c-237b-4147-a867-9c105d51e365', | |
32 | title: 'And its companion', | |
33 | ttl: 160 * 1000, | |
34 | updated_at: Date.now() | |
35 | } | |
36 | ] | |
37 | } | |
38 | } }); | |
39 | }); | |
40 | ||
41 | test('It should display the tag title', () => { | |
42 | ||
43 | expect(internals.results.getByText('Tag: avocado')) | |
44 | .toBeVisible(); | |
45 | }); | |
46 | ||
47 | test('It should display the topics', () => { | |
48 | ||
49 | expect(internals.results.getByText('A single topic')) | |
50 | .toBeVisible(); | |
51 | expect(internals.results.getByText('And its companion')) | |
52 | .toBeVisible(); | |
53 | }); | |
4e6be9f4 RBR |
54 | |
55 | test('It should link to the topics', () => { | |
56 | ||
57 | expect(internals.results.getByText('A single topic').closest('a')) | |
58 | .toHaveAttribute('href', '/t/eb751e7a-5777-46c3-b81b-cc66546d5157'); | |
59 | expect(internals.results.getByText('And its companion').closest('a')) | |
60 | .toHaveAttribute('href', '/t/b4a5613c-237b-4147-a867-9c105d51e365'); | |
61 | }); | |
47b0bfe4 | 62 | }); |