Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion app/app/src/components/LocalesPicker/LocalesPicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { experimental_AstroContainer as AstroContainer } from 'astro/container'
import { expect, test } from 'vitest'
import LocalesPicker from './LocalesPicker.astro'

import { i18n as i18nConfig } from '~/config'

test('LocalesPicker with defaults', async () =>
{
const container = await AstroContainer.create()
Expand All @@ -11,6 +13,31 @@ test('LocalesPicker with defaults', async () =>
expect(result).not.toContain('active')
})

test('LocalesPicker with EN language', async () =>
{
const container = await AstroContainer.create()
const result = await container.renderToString(LocalesPicker, {
props: {
lang: 'en',
}
})

expect(result).toBeTruthy()
expect(result).toContain('active')

if (
i18nConfig.routing.prefixDefaultLocale !== false
|| (i18nConfig.defaultLocale as string) !== 'en'
)
{
expect(result).toMatch(/<a href="\/en\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-united-kingdom][^"]*"[^>]*><\/span>/)
}
else
{
expect(result).toMatch(/<a href="\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-united-kingdom][^"]*"[^>]*><\/span>/)
}
})

test('LocalesPicker with FR language', async () =>
{
const container = await AstroContainer.create()
Expand All @@ -22,5 +49,16 @@ test('LocalesPicker with FR language', async () =>

expect(result).toBeTruthy()
expect(result).toContain('active')
expect(result).toMatch(/<a href="\/fr"[^>]+class="active"[^>]*>/)

if (
i18nConfig.routing.prefixDefaultLocale !== false
|| (i18nConfig.defaultLocale as string) !== 'fr'
)
{
expect(result).toMatch(/<a href="\/fr\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-france][^"]*"[^>]*><\/span>/)
}
else
{
expect(result).toMatch(/<a href="\/"[^>]+class="active"[^>]*>\s*<span class="icon icon-\[twemoji--flag-france][^"]*"[^>]*><\/span>/)
}
})
Loading