@@ -167,6 +167,7 @@ function runTests(isDev) {
167167 it ( 'should navigate with locale prop correctly' , async ( ) => {
168168 const browser = await webdriver ( appPort , '/links?nextLocale=fr' )
169169 await addDefaultLocaleCookie ( browser )
170+ await browser . eval ( 'window.beforeNav = 1' )
170171
171172 expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe ( '/links' )
172173 expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
@@ -208,7 +209,7 @@ function runTests(isDev) {
208209 expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
209210 '/links?nextLocale=fr'
210211 )
211- expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'fr ' )
212+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'en-US ' )
212213 expect (
213214 JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
214215 ) . toEqual ( locales )
@@ -217,7 +218,7 @@ function runTests(isDev) {
217218 ) . toEqual ( { nextLocale : 'fr' } )
218219
219220 parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
220- expect ( parsedUrl . pathname ) . toBe ( '/fr/ links' )
221+ expect ( parsedUrl . pathname ) . toBe ( '/links' )
221222 expect ( parsedUrl . query ) . toEqual ( { nextLocale : 'fr' } )
222223
223224 await browser . eval ( 'window.history.forward()' )
@@ -240,6 +241,7 @@ function runTests(isDev) {
240241 parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
241242 expect ( parsedUrl . pathname ) . toBe ( '/fr/another' )
242243 expect ( parsedUrl . query ) . toEqual ( { } )
244+ expect ( await browser . eval ( 'window.beforeNav' ) ) . toBe ( 1 )
243245 } )
244246
245247 it ( 'should navigate with locale prop correctly GSP' , async ( ) => {
@@ -286,16 +288,182 @@ function runTests(isDev) {
286288 expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
287289 '/links?nextLocale=nl'
288290 )
291+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'en-US' )
292+ expect (
293+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
294+ ) . toEqual ( locales )
295+ expect (
296+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
297+ ) . toEqual ( { nextLocale : 'nl' } )
298+
299+ parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
300+ expect ( parsedUrl . pathname ) . toBe ( '/links' )
301+ expect ( parsedUrl . query ) . toEqual ( { nextLocale : 'nl' } )
302+
303+ await browser . eval ( 'window.history.forward()' )
304+ await browser . waitForElementByCss ( '#gsp' )
305+
306+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
307+ '/gsp/fallback/[slug]'
308+ )
309+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
310+ '/gsp/fallback/first'
311+ )
312+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'nl' )
313+ expect (
314+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
315+ ) . toEqual ( locales )
316+ expect (
317+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
318+ ) . toEqual ( { slug : 'first' } )
319+
320+ parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
321+ expect ( parsedUrl . pathname ) . toBe ( '/nl/gsp/fallback/first' )
322+ expect ( parsedUrl . query ) . toEqual ( { } )
323+ } )
324+
325+ it ( 'should navigate with locale false correctly' , async ( ) => {
326+ const browser = await webdriver ( appPort , '/locale-false?nextLocale=fr' )
327+ await addDefaultLocaleCookie ( browser )
328+ await browser . eval ( 'window.beforeNav = 1' )
329+
330+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
331+ '/locale-false'
332+ )
333+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
334+ '/locale-false?nextLocale=fr'
335+ )
336+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'en-US' )
337+ expect (
338+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
339+ ) . toEqual ( locales )
340+ expect (
341+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
342+ ) . toEqual ( { nextLocale : 'fr' } )
343+
344+ await browser . elementByCss ( '#to-another' ) . click ( )
345+ await browser . waitForElementByCss ( '#another' )
346+
347+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
348+ '/another'
349+ )
350+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
351+ '/another'
352+ )
353+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'fr' )
354+ expect (
355+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
356+ ) . toEqual ( locales )
357+ expect (
358+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
359+ ) . toEqual ( { } )
360+
361+ let parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
362+ expect ( parsedUrl . pathname ) . toBe ( '/fr/another' )
363+ expect ( parsedUrl . query ) . toEqual ( { } )
364+
365+ await browser . eval ( 'window.history.back()' )
366+ await browser . waitForElementByCss ( '#links' )
367+
368+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
369+ '/locale-false'
370+ )
371+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
372+ '/locale-false?nextLocale=fr'
373+ )
374+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'en-US' )
375+ expect (
376+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
377+ ) . toEqual ( locales )
378+ expect (
379+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
380+ ) . toEqual ( { nextLocale : 'fr' } )
381+
382+ parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
383+ expect ( parsedUrl . pathname ) . toBe ( '/locale-false' )
384+ expect ( parsedUrl . query ) . toEqual ( { nextLocale : 'fr' } )
385+
386+ await browser . eval ( 'window.history.forward()' )
387+ await browser . waitForElementByCss ( '#another' )
388+
389+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
390+ '/another'
391+ )
392+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
393+ '/another'
394+ )
395+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'fr' )
396+ expect (
397+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
398+ ) . toEqual ( locales )
399+ expect (
400+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
401+ ) . toEqual ( { } )
402+
403+ parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
404+ expect ( parsedUrl . pathname ) . toBe ( '/fr/another' )
405+ expect ( parsedUrl . query ) . toEqual ( { } )
406+ expect ( await browser . eval ( 'window.beforeNav' ) ) . toBe ( 1 )
407+ } )
408+
409+ it ( 'should navigate with locale false correctly GSP' , async ( ) => {
410+ const browser = await webdriver ( appPort , '/locale-false?nextLocale=nl' )
411+ await addDefaultLocaleCookie ( browser )
412+
413+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
414+ '/locale-false'
415+ )
416+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
417+ '/locale-false?nextLocale=nl'
418+ )
419+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'en-US' )
420+ expect (
421+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
422+ ) . toEqual ( locales )
423+ expect (
424+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
425+ ) . toEqual ( { nextLocale : 'nl' } )
426+
427+ await browser . elementByCss ( '#to-fallback-first' ) . click ( )
428+ await browser . waitForElementByCss ( '#gsp' )
429+
430+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
431+ '/gsp/fallback/[slug]'
432+ )
433+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
434+ '/gsp/fallback/first'
435+ )
289436 expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'nl' )
290437 expect (
291438 JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
292439 ) . toEqual ( locales )
440+ expect (
441+ JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
442+ ) . toEqual ( { slug : 'first' } )
443+
444+ let parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
445+ expect ( parsedUrl . pathname ) . toBe ( '/nl/gsp/fallback/first' )
446+ expect ( parsedUrl . query ) . toEqual ( { } )
447+
448+ await browser . eval ( 'window.history.back()' )
449+ await browser . waitForElementByCss ( '#links' )
450+
451+ expect ( await browser . elementByCss ( '#router-pathname' ) . text ( ) ) . toBe (
452+ '/locale-false'
453+ )
454+ expect ( await browser . elementByCss ( '#router-as-path' ) . text ( ) ) . toBe (
455+ '/locale-false?nextLocale=nl'
456+ )
457+ expect ( await browser . elementByCss ( '#router-locale' ) . text ( ) ) . toBe ( 'en-US' )
458+ expect (
459+ JSON . parse ( await browser . elementByCss ( '#router-locales' ) . text ( ) )
460+ ) . toEqual ( locales )
293461 expect (
294462 JSON . parse ( await browser . elementByCss ( '#router-query' ) . text ( ) )
295463 ) . toEqual ( { nextLocale : 'nl' } )
296464
297465 parsedUrl = url . parse ( await browser . eval ( 'window.location.href' ) , true )
298- expect ( parsedUrl . pathname ) . toBe ( '/nl/links ' )
466+ expect ( parsedUrl . pathname ) . toBe ( '/locale-false ' )
299467 expect ( parsedUrl . query ) . toEqual ( { nextLocale : 'nl' } )
300468
301469 await browser . eval ( 'window.history.forward()' )
0 commit comments