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