]>
Commit | Line | Data |
---|---|---|
1 | import '@testing-library/jest-dom/extend-expect'; | |
2 | ||
3 | import { locale } from 'svelte-i18n'; | |
4 | import { act, render } from '@testing-library/svelte'; | |
5 | import userEvent from '@testing-library/user-event'; | |
6 | import '$/config/i18n'; | |
7 | ||
8 | import LanguageSelector from './language_selector.svelte'; | |
9 | ||
10 | const internals = { | |
11 | results: null | |
12 | }; | |
13 | ||
14 | describe('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 |