11import { applyTrailingSlashOption } from "../../utils"
22
3- Cypress . on ( "uncaught:exception" , ( err ) => {
3+ Cypress . on ( "uncaught:exception" , err => {
44 if ( err . message . includes ( "Minified React error" ) ) {
55 return false
66 }
@@ -14,44 +14,149 @@ describe("Redirects", () => {
1414 it ( "should redirect from non-existing page to existing" , ( ) => {
1515 cy . visit ( applyTrailingSlashOption ( `/redirect` , TRAILING_SLASH ) , {
1616 failOnStatusCode : false ,
17- } ) . waitForRouteChange ( )
18- . assertRoute ( applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH ) )
17+ } )
18+ . waitForRouteChange ( )
19+ . assertRoute (
20+ applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH )
21+ )
1922
2023 cy . get ( `h1` ) . should ( `have.text` , `Hit` )
2124 } )
2225 it ( "should respect that pages take precedence over redirects" , ( ) => {
23- cy . visit ( applyTrailingSlashOption ( `/routes/redirect/existing` , TRAILING_SLASH ) , {
24- failOnStatusCode : false ,
25- } ) . waitForRouteChange ( )
26- . assertRoute ( applyTrailingSlashOption ( `/routes/redirect/existing` , TRAILING_SLASH ) )
26+ cy . visit (
27+ applyTrailingSlashOption ( `/routes/redirect/existing` , TRAILING_SLASH ) ,
28+ {
29+ failOnStatusCode : false ,
30+ }
31+ )
32+ . waitForRouteChange ( )
33+ . assertRoute (
34+ applyTrailingSlashOption ( `/routes/redirect/existing` , TRAILING_SLASH )
35+ )
2736
2837 cy . get ( `h1` ) . should ( `have.text` , `Existing` )
2938 } )
39+ it ( "should respect force redirect" , ( ) => {
40+ cy . visit (
41+ applyTrailingSlashOption (
42+ `/routes/redirect/existing-force` ,
43+ TRAILING_SLASH
44+ ) ,
45+ {
46+ failOnStatusCode : false ,
47+ }
48+ )
49+ . waitForRouteChange ( )
50+ . assertRoute (
51+ applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH )
52+ )
53+
54+ cy . get ( `h1` ) . should ( `have.text` , `Hit` )
55+ } )
56+ it ( "should respect country condition on redirect" , ( ) => {
57+ cy . visit (
58+ applyTrailingSlashOption (
59+ `/routes/redirect/country-condition` ,
60+ TRAILING_SLASH
61+ ) ,
62+ {
63+ failOnStatusCode : false ,
64+ headers : {
65+ "x-nf-country" : "us" ,
66+ } ,
67+ }
68+ )
69+ . waitForRouteChange ( )
70+ . assertRoute (
71+ applyTrailingSlashOption ( `/routes/redirect/hit-us` , TRAILING_SLASH )
72+ )
73+
74+ cy . get ( `h1` ) . should ( `have.text` , `Hit US` )
75+
76+ cy . visit (
77+ applyTrailingSlashOption (
78+ `/routes/redirect/country-condition` ,
79+ TRAILING_SLASH
80+ ) ,
81+ {
82+ failOnStatusCode : false ,
83+ headers : {
84+ "x-nf-country" : "de" ,
85+ } ,
86+ }
87+ )
88+ . waitForRouteChange ( )
89+ . assertRoute (
90+ applyTrailingSlashOption ( `/routes/redirect/hit-de` , TRAILING_SLASH )
91+ )
92+
93+ cy . get ( `h1` ) . should ( `have.text` , `Hit DE` )
94+
95+ // testing fallback
96+ cy . visit (
97+ applyTrailingSlashOption (
98+ `/routes/redirect/country-condition` ,
99+ TRAILING_SLASH
100+ ) ,
101+ {
102+ failOnStatusCode : false ,
103+ headers : {
104+ "x-nf-country" : "fr" ,
105+ } ,
106+ }
107+ )
108+ . waitForRouteChange ( )
109+ . assertRoute (
110+ applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH )
111+ )
112+
113+ cy . get ( `h1` ) . should ( `have.text` , `Hit` )
114+ } )
30115 it ( "should support hash parameter on direct visit" , ( ) => {
31- cy . visit ( applyTrailingSlashOption ( `/redirect` , TRAILING_SLASH ) + `#anchor` , {
32- failOnStatusCode : false ,
33- } ) . waitForRouteChange ( )
116+ cy . visit (
117+ applyTrailingSlashOption ( `/redirect` , TRAILING_SLASH ) + `#anchor` ,
118+ {
119+ failOnStatusCode : false ,
120+ }
121+ ) . waitForRouteChange ( )
34122
35- cy . location ( `pathname` ) . should ( `equal` , applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH ) )
123+ cy . location ( `pathname` ) . should (
124+ `equal` ,
125+ applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH )
126+ )
36127 cy . location ( `hash` ) . should ( `equal` , `#anchor` )
37128 cy . location ( `search` ) . should ( `equal` , `` )
38129 } )
39130 it ( "should support search parameter on direct visit" , ( ) => {
40- cy . visit ( applyTrailingSlashOption ( `/redirect` , TRAILING_SLASH ) + `?query_param=hello` , {
41- failOnStatusCode : false ,
42- } ) . waitForRouteChange ( )
131+ cy . visit (
132+ applyTrailingSlashOption ( `/redirect` , TRAILING_SLASH ) +
133+ `?query_param=hello` ,
134+ {
135+ failOnStatusCode : false ,
136+ }
137+ ) . waitForRouteChange ( )
43138
44- cy . location ( `pathname` ) . should ( `equal` , applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH ) )
139+ cy . location ( `pathname` ) . should (
140+ `equal` ,
141+ applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH )
142+ )
45143 cy . location ( `hash` ) . should ( `equal` , `` )
46144 cy . location ( `search` ) . should ( `equal` , `?query_param=hello` )
47145 } )
48146 it ( "should support search & hash parameter on direct visit" , ( ) => {
49- cy . visit ( applyTrailingSlashOption ( `/redirect` , TRAILING_SLASH ) + `?query_param=hello#anchor` , {
50- failOnStatusCode : false ,
51- } ) . waitForRouteChange ( )
147+ cy . visit (
148+ applyTrailingSlashOption ( `/redirect` , TRAILING_SLASH ) +
149+ `?query_param=hello#anchor` ,
150+ {
151+ failOnStatusCode : false ,
152+ }
153+ ) . waitForRouteChange ( )
52154
53- cy . location ( `pathname` ) . should ( `equal` , applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH ) )
155+ cy . location ( `pathname` ) . should (
156+ `equal` ,
157+ applyTrailingSlashOption ( `/routes/redirect/hit` , TRAILING_SLASH )
158+ )
54159 cy . location ( `hash` ) . should ( `equal` , `#anchor` )
55160 cy . location ( `search` ) . should ( `equal` , `?query_param=hello` )
56161 } )
57- } )
162+ } )
0 commit comments