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