forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 11
/
parallel-routes-and-interception.test.ts
269 lines (234 loc) · 8.07 KB
/
parallel-routes-and-interception.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
createNextDescribe(
'parallel-routes-and-interception',
{
files: __dirname,
// TODO: remove after deployment handling is updated
skipDeployment: true,
},
({ next }) => {
describe('parallel routes', () => {
it('should support parallel route tab bars', async () => {
const browser = await next.browser('/parallel-tab-bar')
const hasHome = async () => {
await check(
() => browser.waitForElementByCss('#home').text(),
'Tab bar page (@children)'
)
}
const hasViewsHome = async () => {
await check(
() => browser.waitForElementByCss('#views-home').text(),
'Views home'
)
}
const hasViewDuration = async () => {
await check(
() => browser.waitForElementByCss('#view-duration').text(),
'View duration'
)
}
const hasImpressions = async () => {
await check(
() => browser.waitForElementByCss('#impressions').text(),
'Impressions'
)
}
const hasAudienceHome = async () => {
await check(
() => browser.waitForElementByCss('#audience-home').text(),
'Audience home'
)
}
const hasDemographics = async () => {
await check(
() => browser.waitForElementByCss('#demographics').text(),
'Demographics'
)
}
const hasSubscribers = async () => {
await check(
() => browser.waitForElementByCss('#subscribers').text(),
'Subscribers'
)
}
const checkUrlPath = async (path: string) => {
await check(
() => browser.url(),
`${next.url}/parallel-tab-bar${path}`
)
}
// Initial page
const step1 = async () => {
await hasHome()
await hasViewsHome()
await hasAudienceHome()
await checkUrlPath('')
}
await step1()
console.log('step1')
// Navigate to /views/duration
await browser.elementByCss('#view-duration-link').click()
const step2 = async () => {
await hasHome()
await hasViewDuration()
await hasAudienceHome()
await checkUrlPath('/view-duration')
}
await step2()
console.log('step2')
// Navigate to /views/impressions
await browser.elementByCss('#impressions-link').click()
const step3 = async () => {
await hasHome()
await hasImpressions()
await hasAudienceHome()
await checkUrlPath('/impressions')
}
await step3()
console.log('step3')
// Navigate to /audience/demographics
await browser.elementByCss('#demographics-link').click()
const step4 = async () => {
await hasHome()
await hasImpressions()
await hasDemographics()
await checkUrlPath('/demographics')
}
await step4()
console.log('step4')
// Navigate to /audience/subscribers
await browser.elementByCss('#subscribers-link').click()
const step5 = async () => {
await hasHome()
await hasImpressions()
await hasSubscribers()
await checkUrlPath('/subscribers')
}
await step5()
console.log('step5')
// Navigate to /
await browser.elementByCss('#home-link-audience').click()
await checkUrlPath('')
// TODO: home link behavior
// await step1()
// TODO: fix back/forward navigation test
// Test that back navigation works as intended
await browser.back()
await step5()
console.log('step5 back')
await browser.back()
await step4()
console.log('step4 back')
await browser.back()
await step3()
console.log('step3 back')
await browser.back()
await step2()
console.log('step2 back')
await browser.back()
await step1()
console.log('step1 back')
console.log('step6')
// Test that forward navigation works as intended
await browser.forward()
await step2()
console.log('step2 forward')
await browser.forward()
await step3()
console.log('step3 forward')
await browser.forward()
await step4()
console.log('step4 forward')
await browser.forward()
await step5()
})
it('should match parallel routes', async () => {
const html = await next.render('/parallel/nested')
expect(html).toContain('parallel/layout')
expect(html).toContain('parallel/@foo/nested/layout')
expect(html).toContain('parallel/@foo/nested/@a/page')
expect(html).toContain('parallel/@foo/nested/@b/page')
expect(html).toContain('parallel/@bar/nested/layout')
expect(html).toContain('parallel/@bar/nested/@a/page')
expect(html).toContain('parallel/@bar/nested/@b/page')
expect(html).toContain('parallel/nested/page')
})
it('should match parallel routes in route groups', async () => {
const html = await next.render('/parallel/nested-2')
expect(html).toContain('parallel/layout')
expect(html).toContain('parallel/(new)/layout')
expect(html).toContain('parallel/(new)/@baz/nested/page')
})
})
describe('route intercepting', () => {
it('should render intercepted route', async () => {
const browser = await next.browser('/intercepting-routes/feed')
// Check if navigation to modal route works.
await check(
() =>
browser
.elementByCss('[href="/intercepting-routes/photos/1"]')
.click()
.waitForElementByCss('#photo-intercepted-1')
.text(),
'Photo INTERCEPTED 1'
)
// Check if intercepted route was rendered while existing page content was removed.
// Content would only be preserved when combined with parallel routes.
// await check(() => browser.elementByCss('#feed-page').text()).not.toBe('Feed')
// Check if url matches even though it was intercepted.
await check(
() => browser.url(),
next.url + '/intercepting-routes/photos/1'
)
// Trigger a refresh, this should load the normal page, not the modal.
await check(
() => browser.refresh().waitForElementByCss('#photo-page-1').text(),
'Photo PAGE 1'
)
// Check if the url matches still.
await check(
() => browser.url(),
next.url + '/intercepting-routes/photos/1'
)
})
it('should render modal when paired with parallel routes', async () => {
const browser = await next.browser(
'/intercepting-parallel-modal/vercel'
)
// Check if navigation to modal route works.
await check(
() =>
browser
.elementByCss('[href="/intercepting-parallel-modal/photo/1"]')
.click()
.waitForElementByCss('#photo-modal-1')
.text(),
'Photo MODAL 1'
)
// Check if modal was rendered while existing page content is preserved.
await check(
() => browser.elementByCss('#user-page').text(),
'Feed for vercel'
)
// Check if url matches even though it was intercepted.
await check(
() => browser.url(),
next.url + '/intercepting-parallel-modal/photo/1'
)
// Trigger a refresh, this should load the normal page, not the modal.
await check(
() => browser.refresh().waitForElementByCss('#photo-page-1').text(),
'Photo PAGE 1'
)
// Check if the url matches still.
await check(
() => browser.url(),
next.url + '/intercepting-parallel-modal/photo/1'
)
})
})
}
)