From 2f8e3554d722fa1a3411123188374304b8feaae5 Mon Sep 17 00:00:00 2001 From: Matiboux Date: Sat, 1 Nov 2025 19:49:18 +0100 Subject: [PATCH] Fix LocalesPicker spec tests --- .../LocalesPicker/LocalesPicker.spec.ts | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/app/src/components/LocalesPicker/LocalesPicker.spec.ts b/app/app/src/components/LocalesPicker/LocalesPicker.spec.ts index 7d6c4a1..628b4b3 100644 --- a/app/app/src/components/LocalesPicker/LocalesPicker.spec.ts +++ b/app/app/src/components/LocalesPicker/LocalesPicker.spec.ts @@ -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() @@ -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(/]+class="active"[^>]*>\s*]*><\/span>/) + } + else + { + expect(result).toMatch(/]+class="active"[^>]*>\s*]*><\/span>/) + } +}) + test('LocalesPicker with FR language', async () => { const container = await AstroContainer.create() @@ -22,5 +49,16 @@ test('LocalesPicker with FR language', async () => expect(result).toBeTruthy() expect(result).toContain('active') - expect(result).toMatch(/]+class="active"[^>]*>/) + + if ( + i18nConfig.routing.prefixDefaultLocale !== false + || (i18nConfig.defaultLocale as string) !== 'fr' + ) + { + expect(result).toMatch(/]+class="active"[^>]*>\s*]*><\/span>/) + } + else + { + expect(result).toMatch(/]+class="active"[^>]*>\s*]*><\/span>/) + } })