2 * @jest-environment jsdom
5 import '@testing-library/jest-dom/extend-expect';
7 import { cleanup, render } from '@testing-library/svelte';
10 import Post from './post.svelte';
14 id: 'e5a19d53-4c9a-4be8-afa5-00942ea3afa4',
15 text: 'This is an example post qwerty',
16 created_at: Date.UTC(2021, 3, 19, 6, 6, 6, 666).valueOf(),
18 handle: 'very_cool_user',
19 id: 'b01bdb48-4b5e-46a4-97f3-6db789bcd33b'
22 id: '35d3c3eb-e486-42ef-994c-d8ab1f1e167a',
23 title: 'Parent topic, yes'
27 id: '9e52e38e-9007-4a20-bbf1-cea4e2f950f3',
28 text: 'This is a post without a topic',
29 created_at: Date.UTC(2022, 8, 21, 4, 3, 1, 340).valueOf(),
31 handle: 'my_normal_user',
32 id: '121f8f97-de02-4102-b25d-f34fd619009b'
39 describe('Post component', () => {
41 internals.results = render(Post, {
43 post: internals.basicPost
48 test('Should display the text of the post', () => {
49 expect(internals.results.getByText('This is an example post qwerty')).toBeVisible();
52 test('Should display date of the post', () => {
53 expect(internals.results.getByText('2021-04-19T06:06:06.666Z')).toBeVisible();
56 test('Date of post should be a permalink to the post', () => {
57 expect(internals.results.getByText('2021-04-19T06:06:06.666Z').closest('a')).toHaveAttribute(
59 '/p/e5a19d53-4c9a-4be8-afa5-00942ea3afa4'
63 test('Should display the glyph of the post author', () => {
64 const glyphicon = internals.results.getByRole('img');
66 expect(glyphicon).toBeVisible();
67 expect(glyphicon).toHaveTextContent(/^. . . .$/);
70 test('Should display author handle', () => {
71 expect(internals.results.getByText('very_cool_user')).toBeVisible();
74 test('Author handle should have a permalink to topic', () => {
75 expect(internals.results.getByText('very_cool_user').closest('a')).toHaveAttribute(
81 test('Should display parent topic title', () => {
82 expect(internals.results.getByText('Parent topic, yes')).toBeVisible();
85 test('Parent topic title should have a permalink to topic', () => {
86 expect(internals.results.getByText('Parent topic, yes').closest('a')).toHaveAttribute(
88 '/t/35d3c3eb-e486-42ef-994c-d8ab1f1e167a'
92 test('Parent topic title should have a permalink to topic', () => {
94 internals.results = render(Post, {
96 post: internals.postWithoutTopic
100 expect(internals.results.queryByText('Parent topic, yes')).toBe(null);
103 test('It should default to 1/1 when no index or count is passed', () => {
104 expect(internals.results.getByTitle('Post 1 of 1 by very_cool_user')).toBeVisible();
107 test('Parent topic title should have a permalink to topic', () => {
109 internals.results = render(Post, {
113 post: internals.postWithoutTopic
117 expect(internals.results.getByTitle('Post 3 of 5 by my_normal_user')).toBeVisible();