@@ -2,6 +2,8 @@ import { experimental_AstroContainer as AstroContainer } from 'astro/container'
22import { expect , test } from 'vitest'
33import LocalesPicker from './LocalesPicker.astro'
44
5+ import { i18n as i18nConfig } from '~/config'
6+
57test ( '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 h r e f = " \/ e n \/ " [ ^ > ] + c l a s s = " a c t i v e " [ ^ > ] * > \s * < s p a n c l a s s = " i c o n i c o n - \[ t w e m o j i - - f l a g - u n i t e d - k i n g d o m ] [ ^ " ] * " [ ^ > ] * > < \/ s p a n > / )
34+ }
35+ else
36+ {
37+ expect ( result ) . toMatch ( / < a h r e f = " \/ " [ ^ > ] + c l a s s = " a c t i v e " [ ^ > ] * > \s * < s p a n c l a s s = " i c o n i c o n - \[ t w e m o j i - - f l a g - u n i t e d - k i n g d o m ] [ ^ " ] * " [ ^ > ] * > < \/ s p a n > / )
38+ }
39+ } )
40+
1441test ( '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 h r e f = " \/ f r " [ ^ > ] + c l a s s = " a c t i v e " [ ^ > ] * > / )
52+
53+ if (
54+ i18nConfig . routing . prefixDefaultLocale !== false
55+ || ( i18nConfig . defaultLocale as string ) !== 'fr'
56+ )
57+ {
58+ expect ( result ) . toMatch ( / < a h r e f = " \/ f r \/ " [ ^ > ] + c l a s s = " a c t i v e " [ ^ > ] * > \s * < s p a n c l a s s = " i c o n i c o n - \[ t w e m o j i - - f l a g - f r a n c e ] [ ^ " ] * " [ ^ > ] * > < \/ s p a n > / )
59+ }
60+ else
61+ {
62+ expect ( result ) . toMatch ( / < a h r e f = " \/ " [ ^ > ] + c l a s s = " a c t i v e " [ ^ > ] * > \s * < s p a n c l a s s = " i c o n i c o n - \[ t w e m o j i - - f l a g - f r a n c e ] [ ^ " ] * " [ ^ > ] * > < \/ s p a n > / )
63+ }
2664} )
0 commit comments