]> git.r.bdr.sh - rbdr/forum/blob - src/lib/components/tag/tag.test.ts
76304e6f32a5ca3c3c14a473391bbf7895c243cb
[rbdr/forum] / src / lib / components / tag / tag.test.ts
1 /**
2 * @jest-environment jsdom
3 */
4
5 import '@testing-library/jest-dom/extend-expect';
6
7 import { render } from '@testing-library/svelte';
8 import '$lib/i18n';
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 });
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 });
62 });