]> git.r.bdr.sh - rbdr/forum/commitdiff
Add test for forum topic list
authorRuben Beltran del Rio <redacted>
Wed, 21 Apr 2021 22:58:09 +0000 (00:58 +0200)
committerRuben Beltran del Rio <redacted>
Wed, 21 Apr 2021 22:58:09 +0000 (00:58 +0200)
Also adds URL test for tag topic list

src/components/forum/forum.test.js [new file with mode: 0644]
src/components/tag/tag.test.js

diff --git a/src/components/forum/forum.test.js b/src/components/forum/forum.test.js
new file mode 100644 (file)
index 0000000..832fd6c
--- /dev/null
@@ -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');
+  });
+});
index 3f19598b4a3eb0a92fb27285f656e04f8c08ffa7..a2b6e0dcfddb7ce183538f7e5caee8079a9af50e 100644 (file)
@@ -47,4 +47,12 @@ describe('Tag component', () => {
     expect(internals.results.getByText('And its companion'))
       .toBeVisible();
   });
     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');
+  });
 });
 });