]> git.r.bdr.sh - rbdr/forum/blobdiff - src/components/post/post.test.js
Update sveltekit version
[rbdr/forum] / src / components / post / post.test.js
index 3a764824757bc0c9059525e96b8ecb3e86bab2c2..e158ce9948154e7aef709bf0f6fd72f4a08a7b29 100644 (file)
@@ -1,6 +1,6 @@
 import '@testing-library/jest-dom/extend-expect';
 
-import { render } from '@testing-library/svelte';
+import { cleanup, render } from '@testing-library/svelte';
 import '$/config/i18n';
 
 import Post from './post.svelte';
@@ -19,6 +19,15 @@ const internals = {
       title: 'Parent topic, yes'
     }
   },
+  postWithoutTopic: {
+    id: '9e52e38e-9007-4a20-bbf1-cea4e2f950f3',
+    text: 'This is a post without a topic',
+    created_at: Date.UTC(2022, 8, 21, 4, 3, 1, 340).valueOf(),
+    author: {
+      handle: 'my_normal_user',
+      id: '121f8f97-de02-4102-b25d-f34fd619009b'
+    }
+  },
 
   results: null
 };
@@ -82,4 +91,34 @@ describe('Post component', () => {
     expect(internals.results.getByText('Parent topic, yes').closest('a'))
       .toHaveAttribute('href', '/t/35d3c3eb-e486-42ef-994c-d8ab1f1e167a');
   });
+
+  test('Parent topic title should have a permalink to topic', () => {
+
+    cleanup();
+    internals.results = render(Post, { props: {
+      post: internals.postWithoutTopic
+    } });
+
+    expect(internals.results.queryByText('Parent topic, yes'))
+      .toBe(null);
+  });
+
+  test('It should default to 1/1 when no index or count is passed', () => {
+
+    expect(internals.results.getByTitle('Post 1 of 1 by very_cool_user'))
+      .toBeVisible();
+  });
+
+  test('Parent topic title should have a permalink to topic', () => {
+
+    cleanup();
+    internals.results = render(Post, { props: {
+      index: 2,
+      count: 5,
+      post: internals.postWithoutTopic
+    } });
+
+    expect(internals.results.getByTitle('Post 3 of 5 by my_normal_user'))
+      .toBeVisible();
+  });
 });