]> git.r.bdr.sh - rbdr/forum/blob - src/lib/components/language_selector/language_selector.test.ts
74156bc31e291c1eb5fa76b2e968c40195ec014c
[rbdr/forum] / src / lib / components / language_selector / language_selector.test.ts
1 /**
2 * @jest-environment jsdom
3 */
4
5 import '@testing-library/jest-dom/extend-expect';
6
7 import { locale } from 'svelte-i18n';
8 import { act, render } from '@testing-library/svelte';
9 import userEvent from '@testing-library/user-event';
10 import '$lib/i18n';
11
12 import LanguageSelector from './language_selector.svelte';
13
14 const internals = {
15 results: null
16 };
17
18 describe('Language Selector component', () => {
19
20 beforeEach(() => {
21
22 internals.results = render(LanguageSelector);
23 });
24
25 test('Should display languages in their own language', () => {
26
27 expect(internals.results.getByText('English'))
28 .toBeVisible();
29 expect(internals.results.getByText('Español'))
30 .toBeVisible();
31 });
32
33 test('Should change locale when a language is selected', async () => {
34
35 locale.subscribe((localeValue) => {
36
37 expect(localeValue).toBe('en');
38 })();
39 const spanish = internals.results.getByText('Español');
40 await userEvent.selectOptions(spanish.closest('select'), spanish);
41 await act();
42 locale.subscribe((localeValue) => {
43
44 expect(localeValue).toBe('es');
45 })();
46 });
47 });
48