@@ -41,7 +41,22 @@ const commonPages = [
41
41
path : `/app/` ,
42
42
matchPath : `/app/*` ,
43
43
} ,
44
+ {
45
+ path : `/app/p1/page/` ,
46
+ matchPath : `/app/:p1/page` ,
47
+ } ,
48
+ {
49
+ path : `/app/p1/p2/` ,
50
+ matchPath : `/app/:p1/:p2` ,
51
+ } ,
52
+ {
53
+ path : `/app/p1/page2/` ,
54
+ // this is very similar to `/app/:p1/page`, point of adding 2 of those is to make sure order of pages in state
55
+ // doesn't impact deterministic page selection
56
+ matchPath : `/app/:p1/page2` ,
57
+ } ,
44
58
`/app/static/` ,
59
+ `/app/static/page/` ,
45
60
]
46
61
47
62
const state = generatePagesState ( [ ...commonPages ] )
@@ -121,16 +136,56 @@ describe(`findPageByPath`, () => {
121
136
expect ( page ?. path ) . toEqual ( `/app/` )
122
137
} )
123
138
139
+ it ( `Picks most specific matchPath` , ( ) => {
140
+ {
141
+ const page = findPageByPath ( state , `/app/foo` )
142
+ expect ( page ) . toBeDefined ( )
143
+ expect ( page ?. path ) . toEqual ( `/app/` )
144
+ }
145
+
146
+ {
147
+ const page = findPageByPath ( state , `/app/foo/bar/baz` )
148
+ expect ( page ) . toBeDefined ( )
149
+ expect ( page ?. path ) . toEqual ( `/app/` )
150
+ }
151
+
152
+ {
153
+ const page = findPageByPath ( state , `/app/foo/bar` )
154
+ expect ( page ) . toBeDefined ( )
155
+ expect ( page ?. path ) . toEqual ( `/app/p1/p2/` )
156
+ }
157
+
158
+ {
159
+ const page = findPageByPath ( state , `/app/foo/page` )
160
+ expect ( page ) . toBeDefined ( )
161
+ expect ( page ?. path ) . toEqual ( `/app/p1/page/` )
162
+ }
163
+
164
+ {
165
+ const page = findPageByPath ( state , `/app/foo/page2` )
166
+ expect ( page ) . toBeDefined ( )
167
+ expect ( page ?. path ) . toEqual ( `/app/p1/page2/` )
168
+ }
169
+ } )
170
+
124
171
it ( `Can match client-only path by static` , ( ) => {
125
172
const page = findPageByPath ( state , `/app` )
126
173
expect ( page ) . toBeDefined ( )
127
174
expect ( page ?. path ) . toEqual ( `/app/` )
128
175
} )
129
176
130
177
it ( `Will prefer static page over client-only in case both match` , ( ) => {
131
- const page = findPageByPath ( state , `/app/static` )
132
- expect ( page ) . toBeDefined ( )
133
- expect ( page ?. path ) . toEqual ( `/app/static/` )
178
+ {
179
+ const page = findPageByPath ( state , `/app/static` )
180
+ expect ( page ) . toBeDefined ( )
181
+ expect ( page ?. path ) . toEqual ( `/app/static/` )
182
+ }
183
+
184
+ {
185
+ const page = findPageByPath ( state , `/app/static/page` )
186
+ expect ( page ) . toBeDefined ( )
187
+ expect ( page ?. path ) . toEqual ( `/app/static/page/` )
188
+ }
134
189
} )
135
190
} )
136
191
0 commit comments