From: Ruben Beltran del Rio Date: Wed, 21 Apr 2021 22:58:09 +0000 (+0200) Subject: Add test for forum topic list X-Git-Url: https://git.r.bdr.sh/rbdr/forum/commitdiff_plain/4e6be9f49b9697d9577014b3ee2b7988129823a9?ds=sidebyside;hp=ccfa62b1a1c79cad28aa4cb05ea560be535e601f Add test for forum topic list Also adds URL test for tag topic list --- 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'); + }); });