1
1
import { test , expect , describe } from 'vitest'
2
2
import { fileURLToPath } from 'node:url'
3
3
import { $fetch , setup } from '../utils'
4
- import { getDom , gotoPath , renderPage , waitForURL } from '../helper'
4
+ import { getDom , gotoPath , renderPage , startServerWithRuntimeConfig , waitForURL } from '../helper'
5
5
6
6
await setup ( {
7
7
rootDir : fileURLToPath ( new URL ( `../fixtures/basic_usage` , import . meta. url ) ) ,
@@ -12,13 +12,15 @@ await setup({
12
12
runtimeConfig : {
13
13
public : {
14
14
i18n : {
15
- baseUrl : ''
15
+ baseUrl : '' ,
16
+ alternateLinkCanonicalQueries : false
16
17
}
17
18
}
18
19
} ,
19
20
i18n : {
20
21
experimental : {
21
- switchLocalePathLinkSSR : true
22
+ switchLocalePathLinkSSR : true ,
23
+ alternateLinkCanonicalQueries : false
22
24
}
23
25
}
24
26
}
@@ -35,14 +37,45 @@ describe('experimental.switchLocalePathLinkSSR', async () => {
35
37
36
38
// Translated params are not lost on query changes
37
39
await page . locator ( '#params-add-query' ) . click ( )
38
- await waitForURL ( page , '/nl/products/rode-mok?test=123' )
39
- expect ( await page . locator ( '#switch-locale-path-link-en' ) . getAttribute ( 'href' ) ) . toEqual ( '/products/red-mug?test=123' )
40
+ await waitForURL ( page , '/nl/products/rode-mok?test=123&canonical=123' )
41
+ expect ( await page . locator ( '#switch-locale-path-link-en' ) . getAttribute ( 'href' ) ) . toEqual (
42
+ '/products/red-mug?test=123&canonical=123'
43
+ )
40
44
41
45
await page . locator ( '#params-remove-query' ) . click ( )
42
46
await waitForURL ( page , '/nl/products/rode-mok' )
43
47
expect ( await page . locator ( '#switch-locale-path-link-en' ) . getAttribute ( 'href' ) ) . toEqual ( '/products/red-mug' )
44
48
} )
45
49
50
+ test ( 'respects `experimental.alternateLinkCanonicalQueries`' , async ( ) => {
51
+ const restore = await startServerWithRuntimeConfig ( {
52
+ public : {
53
+ i18n : {
54
+ experimental : {
55
+ switchLocalePathLinkSSR : true ,
56
+ alternateLinkCanonicalQueries : true
57
+ }
58
+ }
59
+ }
60
+ } )
61
+
62
+ // head tags - alt links are updated server side
63
+ const product1Html = await $fetch ( '/products/big-chair?test=123&canonical=123' )
64
+ const product1Dom = getDom ( product1Html )
65
+ expect ( product1Dom . querySelector ( '#i18n-alt-nl' ) . href ) . toEqual ( '/nl/products/grote-stoel?canonical=123' )
66
+ expect ( product1Dom . querySelector ( '#switch-locale-path-link-nl' ) . href ) . toEqual (
67
+ '/nl/products/grote-stoel?test=123&canonical=123'
68
+ )
69
+
70
+ const product2Html = await $fetch ( '/nl/products/rode-mok?test=123&canonical=123' )
71
+ const product2dom = getDom ( product2Html )
72
+ expect ( product2dom . querySelector ( '#i18n-alt-en' ) . href ) . toEqual ( '/products/red-mug?canonical=123' )
73
+ expect ( product2dom . querySelector ( '#switch-locale-path-link-en' ) . href ) . toEqual (
74
+ '/products/red-mug?test=123&canonical=123'
75
+ )
76
+ await restore ( )
77
+ } )
78
+
46
79
test ( 'dynamic parameters rendered correctly during SSR' , async ( ) => {
47
80
// head tags - alt links are updated server side
48
81
const product1Html = await $fetch ( '/products/big-chair' )
0 commit comments