@@ -480,7 +480,7 @@ describe("localePrefix: 'always', custom `prefixes`", () => {
480480} ) ;
481481
482482describe ( "localePrefix: 'as-needed'" , ( ) => {
483- const { usePathname, useRouter} = createNavigation ( {
483+ const { Link , usePathname, useRouter} = createNavigation ( {
484484 locales,
485485 defaultLocale,
486486 localePrefix : 'as-needed'
@@ -493,6 +493,20 @@ describe("localePrefix: 'as-needed'", () => {
493493 render ( < Component /> ) ;
494494 }
495495
496+ describe ( 'Link' , ( ) => {
497+ it ( 'sets a cookie when switching to the default locale' , ( ) => {
498+ mockCurrentLocale ( 'de' ) ;
499+ global . document . cookie = 'NEXT_LOCALE=de' ;
500+ render (
501+ < Link href = "/" locale = "en" >
502+ Test
503+ </ Link >
504+ ) ;
505+ fireEvent . click ( screen . getByRole ( 'link' , { name : 'Test' } ) ) ;
506+ expect ( document . cookie ) . toContain ( 'NEXT_LOCALE=en' ) ;
507+ } ) ;
508+ } ) ;
509+
496510 describe ( 'useRouter' , ( ) => {
497511 const invokeRouter = getInvokeRouter ( useRouter ) ;
498512
@@ -514,9 +528,16 @@ describe("localePrefix: 'as-needed'", () => {
514528 expect ( useNextRouter ( ) [ method ] ) . toHaveBeenCalledWith ( '/de/about' ) ;
515529 } ) ;
516530
517- it ( 'does not prefix the default locale when being switched to' , ( ) => {
531+ it ( 'does prefix the default locale when being switched to' , ( ) => {
518532 invokeRouter ( ( router ) => router [ method ] ( '/about' , { locale : 'en' } ) ) ;
519- expect ( useNextRouter ( ) [ method ] ) . toHaveBeenCalledWith ( '/about' ) ;
533+ expect ( useNextRouter ( ) [ method ] ) . toHaveBeenCalledWith ( '/en/about' ) ;
534+ } ) ;
535+
536+ it ( 'sets a cookie when switching to the default locale' , ( ) => {
537+ global . document . cookie = 'NEXT_LOCALE=de' ;
538+ mockCurrentLocale ( 'de' ) ;
539+ invokeRouter ( ( router ) => router [ method ] ( '/about' , { locale : 'en' } ) ) ;
540+ expect ( document . cookie ) . toContain ( 'NEXT_LOCALE=en' ) ;
520541 } ) ;
521542 } ) ;
522543
@@ -606,7 +627,7 @@ describe("localePrefix: 'as-needed', with `basePath` and `domains`", () => {
606627 it ( 'can compute the correct pathname when on a secondary locale and navigating to the default locale' , ( ) => {
607628 mockCurrentLocale ( 'ja' ) ;
608629 invokeRouter ( ( router ) => router . push ( '/test' , { locale : 'en' } ) ) ;
609- expect ( useNextRouter ( ) . push ) . toHaveBeenCalledWith ( '/test' ) ;
630+ expect ( useNextRouter ( ) . push ) . toHaveBeenCalledWith ( '/en/ test' ) ;
610631 } ) ;
611632 } ) ;
612633} ) ;
@@ -737,9 +758,9 @@ describe("localePrefix: 'never'", () => {
737758 expect ( useNextRouter ( ) [ method ] ) . toHaveBeenCalledWith ( '/about' ) ;
738759 } ) ;
739760
740- it ( 'does not prefix a secondary locale' , ( ) => {
761+ it ( 'does prefix a pathname when switching to another locale' , ( ) => {
741762 invokeRouter ( ( router ) => router [ method ] ( '/about' , { locale : 'de' } ) ) ;
742- expect ( useNextRouter ( ) [ method ] ) . toHaveBeenCalledWith ( '/about' ) ;
763+ expect ( useNextRouter ( ) [ method ] ) . toHaveBeenCalledWith ( '/de/ about' ) ;
743764 } ) ;
744765 } ) ;
745766
@@ -771,9 +792,9 @@ describe("localePrefix: 'never'", () => {
771792 expect ( useNextRouter ( ) . prefetch ) . toHaveBeenCalledWith ( '/about' ) ;
772793 } ) ;
773794
774- it ( 'does not prefix a secondary locale' , ( ) => {
795+ it ( 'does prefix a pathname when switching to another locale' , ( ) => {
775796 invokeRouter ( ( router ) => router . prefetch ( '/about' , { locale : 'de' } ) ) ;
776- expect ( useNextRouter ( ) . prefetch ) . toHaveBeenCalledWith ( '/about' ) ;
797+ expect ( useNextRouter ( ) . prefetch ) . toHaveBeenCalledWith ( '/de/ about' ) ;
777798 } ) ;
778799 } ) ;
779800 } ) ;
0 commit comments