Skip to content

Commit 25d8edd

Browse files
authored
Fix locale switch component (#24)
1 parent a3ba798 commit 25d8edd

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

app/app/src/components/LocalesPicker/LocalesPicker.spec.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { experimental_AstroContainer as AstroContainer } from 'astro/container'
22
import { expect, test } from 'vitest'
33
import LocalesPicker from './LocalesPicker.astro'
44

5+
import { i18n as i18nConfig } from '~/config'
6+
57
test('LocalesPicker with defaults', async () =>
68
{
79
const container = await AstroContainer.create()
@@ -11,6 +13,31 @@ test('LocalesPicker with defaults', async () =>
1113
expect(result).not.toContain('active')
1214
})
1315

16+
test('LocalesPicker with EN language', async () =>
17+
{
18+
const container = await AstroContainer.create()
19+
const result = await container.renderToString(LocalesPicker, {
20+
props: {
21+
lang: 'en',
22+
}
23+
})
24+
25+
expect(result).toBeTruthy()
26+
expect(result).toContain('active')
27+
28+
if (
29+
i18nConfig.routing.prefixDefaultLocale !== false
30+
|| (i18nConfig.defaultLocale as string) !== 'en'
31+
)
32+
{
33+
expect(result).toMatch(/<a href="\/en\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-united-kingdom][^"]*"[^>]*><\/span>/)
34+
}
35+
else
36+
{
37+
expect(result).toMatch(/<a href="\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-united-kingdom][^"]*"[^>]*><\/span>/)
38+
}
39+
})
40+
1441
test('LocalesPicker with FR language', async () =>
1542
{
1643
const container = await AstroContainer.create()
@@ -22,5 +49,16 @@ test('LocalesPicker with FR language', async () =>
2249

2350
expect(result).toBeTruthy()
2451
expect(result).toContain('active')
25-
expect(result).toMatch(/<a href="\/fr"[^>]+class="active"[^>]*>/)
52+
53+
if (
54+
i18nConfig.routing.prefixDefaultLocale !== false
55+
|| (i18nConfig.defaultLocale as string) !== 'fr'
56+
)
57+
{
58+
expect(result).toMatch(/<a href="\/fr\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-france][^"]*"[^>]*><\/span>/)
59+
}
60+
else
61+
{
62+
expect(result).toMatch(/<a href="\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-france][^"]*"[^>]*><\/span>/)
63+
}
2664
})

0 commit comments

Comments
 (0)