aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2021-04-22 00:58:09 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2021-04-22 00:58:09 +0200
commit4e6be9f49b9697d9577014b3ee2b7988129823a9 (patch)
tree5317704cc353ade186eaafbf13d377285828d92e /src
parentccfa62b1a1c79cad28aa4cb05ea560be535e601f (diff)
Add test for forum topic list
Also adds URL test for tag topic list
Diffstat (limited to 'src')
-rw-r--r--src/components/forum/forum.test.js69
-rw-r--r--src/components/tag/tag.test.js8
2 files changed, 77 insertions, 0 deletions
diff --git a/src/components/forum/forum.test.js b/src/components/forum/forum.test.js
new file mode 100644
index 0000000..832fd6c
--- /dev/null
+++ b/src/components/forum/forum.test.js
@@ -0,0 +1,69 @@
+import '@testing-library/jest-dom/extend-expect';
+
+import { addMessages } from 'svelte-i18n';
+
+import { render } from '@testing-library/svelte';
+import '$/config/i18n';
+
+import Forum from './forum.svelte';
+
+const internals = {
+ results: null
+};
+
+describe('Forum component', () => {
+
+ beforeAll(() => {
+
+ addMessages('en', {
+ 'test_forums.oleo': 'Oleo'
+ });
+ });
+
+ beforeEach(() => {
+
+ internals.results = render(Forum, { props: {
+ forum: {
+ id: 'oleo',
+ glyph: '☽',
+ label: 'test_forums.oleo',
+ topics: [
+ {
+ id: '0575d375-5bea-44df-a597-bee3adda624d',
+ title: 'Very forumy topic',
+ ttl: 160 * 1000,
+ updated_at: Date.now()
+ },
+ {
+ id: 'aeeb56e4-751d-4400-8aa7-d0f3a20d4e25',
+ title: 'Only mildly forum-like',
+ ttl: 160 * 1000,
+ updated_at: Date.now()
+ }
+ ]
+ }
+ } });
+ });
+
+ test('It should display the forum glyph and label', () => {
+
+ expect(internals.results.getByText(/^\s*☽\s*Oleo\s*$/))
+ .toBeVisible();
+ });
+
+ test('It should display the topics', () => {
+
+ expect(internals.results.getByText('Very forumy topic'))
+ .toBeVisible();
+ expect(internals.results.getByText('Only mildly forum-like'))
+ .toBeVisible();
+ });
+
+ test('It should link to the topics', () => {
+
+ expect(internals.results.getByText('Very forumy topic').closest('a'))
+ .toHaveAttribute('href', '/t/0575d375-5bea-44df-a597-bee3adda624d');
+ expect(internals.results.getByText('Only mildly forum-like').closest('a'))
+ .toHaveAttribute('href', '/t/aeeb56e4-751d-4400-8aa7-d0f3a20d4e25');
+ });
+});
diff --git a/src/components/tag/tag.test.js b/src/components/tag/tag.test.js
index 3f19598..a2b6e0d 100644
--- a/src/components/tag/tag.test.js
+++ b/src/components/tag/tag.test.js
@@ -47,4 +47,12 @@ describe('Tag component', () => {
expect(internals.results.getByText('And its companion'))
.toBeVisible();
});
+
+ test('It should link to the topics', () => {
+
+ expect(internals.results.getByText('A single topic').closest('a'))
+ .toHaveAttribute('href', '/t/eb751e7a-5777-46c3-b81b-cc66546d5157');
+ expect(internals.results.getByText('And its companion').closest('a'))
+ .toHaveAttribute('href', '/t/b4a5613c-237b-4147-a867-9c105d51e365');
+ });
});