diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-04-19 21:04:59 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-04-19 21:04:59 +0200 |
| commit | 879fa389c2592760def75177eefbd3193e1845c9 (patch) | |
| tree | 8648bb1790cea8b482b18ef10b4b5cab508b0ba3 /src/components/forum_list | |
| parent | 77182aa8d0fa96b594d1c2582a168e2ebe15964d (diff) | |
Add tests for first batch of components
- Glyph
- Forum List
- Error Block
- Post
Diffstat (limited to 'src/components/forum_list')
| -rw-r--r-- | src/components/forum_list/forum_list.svelte | 42 | ||||
| -rw-r--r-- | src/components/forum_list/forum_list.test.js | 90 |
2 files changed, 104 insertions, 28 deletions
diff --git a/src/components/forum_list/forum_list.svelte b/src/components/forum_list/forum_list.svelte index 7bfb7b2..a33358c 100644 --- a/src/components/forum_list/forum_list.svelte +++ b/src/components/forum_list/forum_list.svelte @@ -1,36 +1,22 @@ <script> - import { _ } from 'svelte-i18n'; - import { forums } from '$/stores/forums'; - import Loader from '$/components/loader/loader.svelte'; - import ErrorBlock from '$/components/error_block/error_block.svelte'; +import { _ } from 'svelte-i18n'; +export let forums; + +$: sortedForums = forums.sort((a, b) => a.position - b.position); </script> -<nav title={$_('forum_list.title')}> - {#if $forums.loading} - <Loader /> - {/if} - {#if $forums.error} - <ErrorBlock message={$_('forum_list.error.unavailable')} /> - {/if} - <ul> - {#each $forums.data as forum} - <li> - <a href="/f/{forum.id}"> - <span aria-hidden="true" class="navigation-glyph {forum.glyph}">{forum.glyph}</span> - <span class="navigation-label">{$_(forum.label)}</span> - </a> - </li> - {/each} - </ul> -</nav> +<ul> + {#each sortedForums as forum} + <li> + <a href="/f/{forum.id}"> + <span aria-hidden="true" class="navigation-glyph {forum.glyph}">{forum.glyph}</span> + <span class="navigation-label">{$_(forum.label)}</span> + </a> + </li> + {/each} +</ul> <style> - nav { - grid-column: col-start 1; - grid-row: 2; - border-right: 1px solid black; - } - ul { padding: 0; } diff --git a/src/components/forum_list/forum_list.test.js b/src/components/forum_list/forum_list.test.js new file mode 100644 index 0000000..3066e8a --- /dev/null +++ b/src/components/forum_list/forum_list.test.js @@ -0,0 +1,90 @@ +import '@testing-library/jest-dom/extend-expect'; + +import { render } from '@testing-library/svelte'; +import '$/config/i18n'; + +import { addMessages } from 'svelte-i18n'; + +import ForumList from './forum_list.svelte'; + +const internals = { + results: null +}; + +describe('Glyph component', () => { + + beforeAll(() => { + + addMessages('en', { + 'test_forums.yes': 'Absolutely yes', + 'test_forums.no': 'No, not at all', + 'test_forums.maybe': 'OK, maybe...' + }); + }); + + beforeEach(() => { + + internals.results = render(ForumList, { props: { + forums: [ + { + id: 'yes', + glyph: '☆', + label: 'test_forums.yes', + position: 2 + }, + { + id: 'no', + glyph: '◯', + label: 'test_forums.no', + position: 0 + }, + { + id: 'maybe', + glyph: '⏀', + label: 'test_forums.maybe', + position: 1 + } + ] + } }); + }); + + test('It should display each forum according to their position', () => { + + expect(internals.results.container) + .toHaveTextContent(/^◯.+⏀.+☆.+$/); + }); + + test('It should translate forum labels', () => { + + expect(internals.results.getByText('Absolutely yes')).toBeVisible(); + expect(internals.results.getByText('No, not at all')).toBeVisible(); + expect(internals.results.getByText('OK, maybe...')).toBeVisible(); + }); + + test('It should display forum glyphs', () => { + + expect(internals.results.getByText('☆')).toBeVisible(); + expect(internals.results.getByText('◯')).toBeVisible(); + expect(internals.results.getByText('⏀')).toBeVisible(); + }); + + test('Label should be a permalink to the forum', () => { + + expect(internals.results.getByText('Absolutely yes').closest('a')) + .toHaveAttribute('href', '/f/yes'); + expect(internals.results.getByText('No, not at all').closest('a')) + .toHaveAttribute('href', '/f/no'); + expect(internals.results.getByText('OK, maybe...').closest('a')) + .toHaveAttribute('href', '/f/maybe'); + }); + + test('Glyph should be a permalink to the forum', () => { + + expect(internals.results.getByText('☆').closest('a')) + .toHaveAttribute('href', '/f/yes'); + expect(internals.results.getByText('◯').closest('a')) + .toHaveAttribute('href', '/f/no'); + expect(internals.results.getByText('⏀').closest('a')) + .toHaveAttribute('href', '/f/maybe'); + }); +}); |