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