]>
Commit | Line | Data |
---|---|---|
879fa389 RBR |
1 | import '@testing-library/jest-dom/extend-expect'; |
2 | ||
3 | import { render } from '@testing-library/svelte'; | |
4 | import '$/config/i18n'; | |
5 | ||
6 | import Post from './post.svelte'; | |
7 | ||
8 | const internals = { | |
9 | basicPost: { | |
10 | id: 'e5a19d53-4c9a-4be8-afa5-00942ea3afa4', | |
11 | text: 'This is an example post qwerty', | |
12 | created_at: Date.UTC(2021, 3, 19, 6, 6, 6, 666).valueOf(), | |
13 | author: { | |
14 | handle: 'very_cool_user', | |
15 | id: 'b01bdb48-4b5e-46a4-97f3-6db789bcd33b' | |
16 | }, | |
17 | topic: { | |
18 | id: '35d3c3eb-e486-42ef-994c-d8ab1f1e167a', | |
19 | title: 'Parent topic, yes' | |
20 | } | |
21 | }, | |
22 | ||
23 | results: null | |
24 | }; | |
25 | ||
26 | describe('Post component', () => { | |
27 | ||
28 | beforeEach(() => { | |
29 | ||
30 | internals.results = render(Post, { props: { | |
31 | post: internals.basicPost | |
32 | } }); | |
33 | }); | |
34 | ||
35 | test('Should display the text of the post', () => { | |
36 | ||
37 | expect(internals.results.getByText('This is an example post qwerty')).toBeVisible(); | |
38 | }); | |
39 | ||
40 | test('Should display date of the post', () => { | |
41 | ||
42 | expect(internals.results.getByText('2021-04-19T06:06:06.666Z')) | |
43 | .toBeVisible(); | |
44 | }); | |
45 | ||
46 | test('Date of post should be a permalink to the post', () => { | |
47 | ||
48 | expect(internals.results.getByText('2021-04-19T06:06:06.666Z').closest('a')) | |
49 | .toHaveAttribute('href', '/p/e5a19d53-4c9a-4be8-afa5-00942ea3afa4'); | |
50 | }); | |
51 | ||
52 | test('Should display the glyph of the post author', () => { | |
53 | ||
54 | const glyphicon = internals.results.getByRole('img'); | |
55 | ||
56 | expect(glyphicon) | |
57 | .toBeVisible(); | |
58 | expect(glyphicon) | |
59 | .toHaveTextContent(/^. . . .$/); | |
60 | }); | |
61 | ||
62 | test('Should display author handle', () => { | |
63 | ||
64 | expect(internals.results.getByText('very_cool_user')) | |
65 | .toBeVisible(); | |
66 | }); | |
67 | ||
68 | test('Author handle should have a permalink to topic', () => { | |
69 | ||
70 | expect(internals.results.getByText('very_cool_user').closest('a')) | |
71 | .toHaveAttribute('href', '/a/very_cool_user'); | |
72 | }); | |
73 | ||
74 | test('Should display parent topic title', () => { | |
75 | ||
76 | expect(internals.results.getByText('Parent topic, yes')) | |
77 | .toBeVisible(); | |
78 | }); | |
79 | ||
80 | test('Parent topic title should have a permalink to topic', () => { | |
81 | ||
82 | expect(internals.results.getByText('Parent topic, yes').closest('a')) | |
83 | .toHaveAttribute('href', '/t/35d3c3eb-e486-42ef-994c-d8ab1f1e167a'); | |
84 | }); | |
85 | }); |