diff options
Diffstat (limited to 'src/components/post/post.test.js')
| -rw-r--r-- | src/components/post/post.test.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/components/post/post.test.js b/src/components/post/post.test.js new file mode 100644 index 0000000..3a76482 --- /dev/null +++ b/src/components/post/post.test.js @@ -0,0 +1,85 @@ +import '@testing-library/jest-dom/extend-expect'; + +import { render } from '@testing-library/svelte'; +import '$/config/i18n'; + +import Post from './post.svelte'; + +const internals = { + basicPost: { + id: 'e5a19d53-4c9a-4be8-afa5-00942ea3afa4', + text: 'This is an example post qwerty', + created_at: Date.UTC(2021, 3, 19, 6, 6, 6, 666).valueOf(), + author: { + handle: 'very_cool_user', + id: 'b01bdb48-4b5e-46a4-97f3-6db789bcd33b' + }, + topic: { + id: '35d3c3eb-e486-42ef-994c-d8ab1f1e167a', + title: 'Parent topic, yes' + } + }, + + results: null +}; + +describe('Post component', () => { + + beforeEach(() => { + + internals.results = render(Post, { props: { + post: internals.basicPost + } }); + }); + + test('Should display the text of the post', () => { + + expect(internals.results.getByText('This is an example post qwerty')).toBeVisible(); + }); + + test('Should display date of the post', () => { + + expect(internals.results.getByText('2021-04-19T06:06:06.666Z')) + .toBeVisible(); + }); + + test('Date of post should be a permalink to the post', () => { + + expect(internals.results.getByText('2021-04-19T06:06:06.666Z').closest('a')) + .toHaveAttribute('href', '/p/e5a19d53-4c9a-4be8-afa5-00942ea3afa4'); + }); + + test('Should display the glyph of the post author', () => { + + const glyphicon = internals.results.getByRole('img'); + + expect(glyphicon) + .toBeVisible(); + expect(glyphicon) + .toHaveTextContent(/^. . . .$/); + }); + + test('Should display author handle', () => { + + expect(internals.results.getByText('very_cool_user')) + .toBeVisible(); + }); + + test('Author handle should have a permalink to topic', () => { + + expect(internals.results.getByText('very_cool_user').closest('a')) + .toHaveAttribute('href', '/a/very_cool_user'); + }); + + test('Should display parent topic title', () => { + + expect(internals.results.getByText('Parent topic, yes')) + .toBeVisible(); + }); + + test('Parent topic title should have a permalink to topic', () => { + + expect(internals.results.getByText('Parent topic, yes').closest('a')) + .toHaveAttribute('href', '/t/35d3c3eb-e486-42ef-994c-d8ab1f1e167a'); + }); +}); |