-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathrouting.cy.js
More file actions
372 lines (321 loc) · 15.4 KB
/
routing.cy.js
File metadata and controls
372 lines (321 loc) · 15.4 KB
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
const port = 3000;
describe('Routing Tests', () => {
// before(() => {
// Cypress.config('userAgent', 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1')
// });
it('/ > Details 1, the details screen should appear', () => {
cy.visit(`http://localhost:${port}/routing`);
cy.ionPageVisible('home-page');
cy.ionNav('ion-item', 'Details 1');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Details 1');
});
it('/ > Details 1 > Back, should go back to home', () => {
cy.visit(`http://localhost:${port}/routing`);
cy.ionNav('ion-item', 'Details 1');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Details 1');
cy.ionBackClick('home-details-page-1');
cy.contains('[data-pageid=home-page] ion-title', 'Home');
});
it('/ > Details 1 > Settings Tab > Home Tab, should go back to details 1 on home tab', () => {
cy.visit(`http://localhost:${port}/routing`);
cy.ionNav('ion-item', 'Details 1');
cy.ionPageVisible('home-details-page-1');
cy.ionTabClick('Settings');
cy.ionPageVisible('settings-page');
cy.ionTabClick('Home');
cy.ionPageVisible('home-details-page-1');
});
it('/ > Details 1 > Settings Tab > Home Tab > Home Tab, should go back to home', () => {
cy.visit(`http://localhost:${port}/routing`);
cy.ionNav('ion-item', 'Details 1');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Details 1');
cy.ionTabClick('Settings');
cy.ionPageVisible('settings-page');
cy.ionTabClick('Home');
cy.ionPageVisible('home-details-page-1');
cy.ionTabClick('Home');
cy.ionPageVisible('home-page');
});
it('When going directly to /tabs, it should load home page', () => {
cy.visit(`http://localhost:${port}/routing/tabs`);
cy.ionPageVisible('home-page');
});
it('When going directly to /tabs/home, it should load home page', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home`);
cy.ionPageVisible('home-page');
});
it('When going directly to /tabs/settings, it should load settings page', () => {
cy.visit(`http://localhost:${port}/routing/tabs/settings`);
cy.ionPageVisible('settings-page');
});
it('Home Details 1 > Settings Tab > Home Tab, details 1 page should still be active', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home/details/1`);
cy.ionTabClick('Settings');
cy.ionPageVisible('settings-page');
cy.ionTabClick('Home');
cy.ionPageVisible('home-details-page-1');
});
it('/ > Home Details 1+2+3 > Settings Tab > Setting Details 1+2+3 > Home Tab > Back * 3 > Settings Tab > Back * 3, should be at settings page', () => {
// This was a bug when loading the root of the app and not going directly to the home tab
cy.visit(`http://localhost:${port}/routing/`);
cy.ionNav('ion-item', 'Details 1');
cy.ionNav('ion-button', 'Go to Details 2');
cy.ionNav('ion-button', 'Go to Details 3');
cy.contains('[data-pageid=home-details-page-3] ion-label', 'Details 3');
cy.ionTabClick('Settings');
cy.ionNav('ion-item', 'Settings Details 1');
cy.ionNav('ion-button', 'Go to Settings Details 2');
cy.ionNav('ion-button', 'Go to Settings Details 3');
cy.contains('[data-pageid=settings-details-page-3] ion-label', 'Details 3');
cy.ionTabClick('Home');
cy.contains('[data-pageid=home-details-page-3] ion-label', 'Details 3');
cy.ionBackClick('home-details-page-3');
cy.contains('[data-pageid=home-details-page-2] ion-label', 'Details 2');
cy.ionBackClick('home-details-page-2');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Details 1');
cy.ionBackClick('home-details-page-1');
cy.ionPageVisible('home-page');
});
it('/ > Details 1 with Query Param > Details 2 > Back, Query param should show on screen', () => {
cy.visit(`http://localhost:${port}/routing/`);
cy.ionNav('ion-item', 'Details 1 with Query Params');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Query Params: ');
cy.ionNav('ion-button', 'Go to Details 2');
cy.contains('[data-pageid=home-details-page-2] ion-label', 'Details 2');
cy.ionBackClick('home-details-page-2');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Query Params: ');
});
it('/ > Details 1 with Query Param > Settings Tab > Home Tab > Query param should show on screen', () => {
cy.visit(`http://localhost:${port}/routing/`);
cy.ionNav('ion-item', 'Details 1 with Query Params');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Query Params: ');
cy.ionTabClick('Settings');
cy.ionPageVisible('settings-page');
cy.ionTabClick('Home');
cy.contains('[data-pageid=home-details-page-1] ion-label', 'Query Params: ');
});
it('Home Details 1 > Home Tab > Details 1 > Home Tab, should be on home page', () => {
// Tests a bug when landing directly on a page thats not the originalHref and going back to home
cy.visit(`http://localhost:${port}/routing/tabs/home/details/1`);
cy.ionTabClick('Home');
cy.ionPageVisible('home-page');
cy.ionNav('ion-item', 'Details 1');
cy.ionPageVisible('home-details-page-1');
cy.ionTabClick('Home');
cy.ionPageVisible('home-page');
});
it('Home > Session Details Link > Session Details 2 > Back > Back, should be at home page', () => {
// Tests a bug when landing directly on a page thats not the originalHref and going back to home
cy.visit(`http://localhost:${port}/routing/tabs/home`);
cy.ionNav('a', 'Go to details 1 on settings');
cy.ionPageVisible('settings-details-page-1');
cy.ionNav('ion-button', 'Go to Settings Details 2');
cy.ionPageVisible('settings-details-page-2');
cy.ionBackClick('settings-details-page-2');
cy.ionPageVisible('settings-details-page-1');
cy.ionBackClick('settings-details-page-1');
cy.ionPageVisible('home-page');
});
it('Tab 3 > Other Page > Back, should be back on Tab 3', () => {
// Tests transferring from one outlet to another and back again with animation
cy.visit(`http://localhost:${port}/routing/tabs/tab3`);
cy.ionNav('ion-button', 'Go to Other Page');
cy.ionPageVisible('other-page');
cy.ionBackClick('other-page');
cy.ionPageVisible('tab3-page');
});
it('/ > Menu > Favorites > Menu > Tabs, should be back on Home', () => {
// Tests transferring from one outlet to another and back again via menu
cy.visit(`http://localhost:${port}/routing`);
cy.ionMenuClick();
cy.ionMenuNav('Favorites');
cy.ionPageVisible('favorites-page');
cy.ionMenuClick();
cy.ionMenuNav('Tabs');
cy.ionPageVisible('home-page');
});
it('/ > Session Details > Details 2 > Details 3 > Browser Back * 3, should be back on home', () => {
// Tests browser back button
cy.visit(`http://localhost:${port}/routing/`);
cy.ionNav('ion-item', 'Details 1');
cy.ionPageVisible('home-details-page-1');
cy.ionNav('ion-button', 'Go to Details 2');
cy.ionPageVisible('home-details-page-2');
cy.ionNav('ion-button', 'Go to Details 3');
cy.ionPageVisible('home-details-page-3');
cy.go('back');
cy.ionPageVisible('home-details-page-2');
cy.go('back');
cy.ionPageVisible('home-details-page-1');
cy.go('back');
cy.ionPageVisible('home-page');
});
it('/ > Details 1 > Details 2 > Details 3 > Settings Tab > Home Tab > Browser Back, should be back on home', () => {
// Tests browser back button with a tab switch
cy.visit(`http://localhost:${port}/routing/`);
cy.ionNav('ion-item', 'Details 1');
cy.ionPageVisible('home-details-page-1');
cy.ionNav('ion-button', 'Go to Details 2');
cy.ionPageVisible('home-details-page-2');
cy.ionNav('ion-button', 'Go to Details 3');
cy.ionPageVisible('home-details-page-3');
cy.ionTabClick('Settings');
cy.ionPageVisible('settings-page');
cy.ionTabClick('Home');
cy.ionPageVisible('home-details-page-3');
cy.go('back');
cy.ionPageVisible('home-details-page-2');
cy.get('ion-tab-button.tab-selected').contains('Home');
});
it('/ > Details 1 > Details 2 > Details 3 > Browser Back > Back > Back, should be back on home', () => {
// Tests browser back button with a tab switch
cy.visit(`http://localhost:${port}/routing/`);
cy.ionNav('ion-item', 'Details 1');
cy.ionPageVisible('home-details-page-1');
cy.ionNav('ion-button', 'Go to Details 2');
cy.ionPageVisible('home-details-page-2');
cy.ionNav('ion-button', 'Go to Details 3');
cy.ionPageVisible('home-details-page-3');
cy.go('back');
cy.ionPageVisible('home-details-page-2');
cy.ionBackClick('home-details-page-2');
cy.ionPageVisible('home-details-page-1');
cy.ionBackClick('home-details-page-1');
cy.ionPageVisible('home-page');
});
it('when props get passed into a route render, the component should update', () => {
cy.visit(`http://localhost:${port}/routing/propstest`);
cy.ionPageVisible('props-test');
cy.get('div[data-testid=count-label]').contains('1');
cy.contains('Increment').click();
cy.get('div[data-testid=count-label]').contains('2');
cy.contains('Increment').click();
cy.get('div[data-testid=count-label]').contains('3');
});
it('/routing/asdf, when accessing a route not defined from root outlet, should show not found page', () => {
cy.visit(`http://localhost:${port}/routing/asdf`, { failOnStatusCode: false });
cy.ionPageVisible('not-found');
cy.get('div').contains('Not found');
});
it('/tabs/home > Details 1 on settings > Home Tab, should be back on home page', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home`);
cy.ionNav('ion-item', 'Details 1 on settings');
cy.ionPageVisible('settings-details-page-1');
cy.ionTabClick('Home');
cy.ionPageVisible('home-page');
});
it('/ > Details 1 on settings > Back > Settings Tab, should be on setting home', () => {
// For bug https://github.com/ionic-team/ionic-framework/issues/21031
cy.visit(`http://localhost:${port}/routing/`);
cy.ionNav('ion-item', 'Details 1 on settings');
cy.ionPageVisible('settings-details-page-1');
cy.ionBackClick('settings-details-page-1');
cy.ionPageVisible('home-page');
cy.ionTabClick('Settings');
cy.ionPageVisible('settings-page');
});
it('/routing/tabs/redirect > Should be on settings page > Home Tab > Should be on home page', () => {
// tests that a redirect going to a tab other than the first tab works
// fixes bug https://github.com/ionic-team/ionic-framework/issues/21830
cy.visit(`http://localhost:${port}/routing/tabs/redirect`);
cy.ionPageVisible('settings-page');
cy.ionTabClick('Home');
cy.ionPageVisible('home-page');
});
it('/routing/ > Details 1 > Details 2 > Details 3 > Back > Settings Tab > Home Tab > Should be at details 2 page', () => {
// fixes an issue where route history was being lost after starting to go back, switching tabs
// and switching back to the same tab again
// for bug https://github.com/ionic-team/ionic-framework/issues/21834
cy.visit(`http://localhost:${port}/routing`);
cy.ionPageVisible('home-page');
cy.ionNav('ion-item', 'Details 1');
cy.ionPageVisible('home-details-page-1');
cy.ionNav('ion-button', 'Go to Details 2');
cy.ionPageVisible('home-details-page-2');
cy.ionNav('ion-button', 'Go to Details 3');
cy.ionPageVisible('home-details-page-3');
cy.ionBackClick('home-details-page-3');
cy.ionPageVisible('home-details-page-2');
cy.ionTabClick('Settings');
cy.ionPageVisible('settings-page');
cy.ionTabClick('Home');
cy.ionPageVisible('home-details-page-2');
});
it('/routing/tabs/home Menu > Favorites > Menu > Home with redirect, Home page should be visible, and Favorites should be hidden', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home`);
cy.ionMenuClick();
cy.ionMenuNav('Favorites');
cy.ionPageVisible('favorites-page');
cy.ionMenuClick();
cy.ionMenuNav('Home with redirect');
cy.ionPageVisible('home-page');
cy.ionPageDoesNotExist('favorites-page');
});
it('/routing/tabs/home Menu > Favorites > Menu > Home with router, Home page should be visible, and Favorites should be hidden', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home`);
cy.ionMenuClick();
cy.ionMenuNav('Favorites');
cy.ionPageVisible('favorites-page');
cy.ionMenuClick();
cy.ionMenuNav('Home with router');
cy.ionPageVisible('home-page');
cy.ionPageHidden('favorites-page');
});
it('should show back button when going back to a pushed page', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home`);
cy.ionNav('ion-item', 'Details 1');
cy.ionPageHidden('home-page');
cy.ionPageVisible('home-details-page-1');
cy.get('ion-tab-button#tab-button-settings').click();
cy.ionPageHidden('home-details-page-1');
cy.ionPageVisible('settings-page');
cy.get('ion-tab-button#tab-button-home').click();
cy.ionPageHidden('settings-page');
cy.ionPageVisible('home-details-page-1');
cy.ionBackClick('home-details-page-1');
cy.ionPageDoesNotExist('home-details-page-1');
cy.ionPageVisible('home-page');
});
it('should mount new view item instances of parameterized routes', () => {
cy.visit(`http://localhost:${port}/routing/tabs/home/details/1`);
cy.get('div.ion-page[data-pageid=home-details-page-1]')
.get('[data-testid="details-input"]')
.should('have.value', '');
cy.get('div.ion-page[data-pageid=home-details-page-1] [data-testid="details-input"]').type('1');
cy.ionNav('ion-button', 'Go to Details 2');
cy.ionPageVisible('home-details-page-2');
cy.get('div.ion-page[data-pageid=home-details-page-2] [data-testid="details-input"]').should('have.value', '');
cy.get('div.ion-page[data-pageid=home-details-page-2] [data-testid="details-input"]').type('2');
cy.ionNav('ion-button', 'Go to Details 3');
cy.ionPageVisible('home-details-page-3');
cy.get('div.ion-page[data-pageid=home-details-page-3] [data-testid="details-input"]').should('have.value', '');
cy.get('div.ion-page[data-pageid=home-details-page-3] [data-testid="details-input"]').type('3');
cy.ionBackClick('home-details-page-3');
cy.ionPageVisible('home-details-page-2');
cy.get('div.ion-page[data-pageid=home-details-page-2] [data-testid="details-input"]').should('have.value', '2');
cy.ionBackClick('home-details-page-2');
cy.ionPageVisible('home-details-page-1');
cy.get('div.ion-page[data-pageid=home-details-page-1] [data-testid="details-input"]').should('have.value', '1');
});
it('Details 1 with Query Params > pop a same-URL history entry, should stay on details 1', () => {
// Regression: popstate over a same-URL entry on a search-bearing route used to trigger a false POP transition.
cy.visit(`http://localhost:${port}/routing`);
cy.ionNav('ion-item', 'Details 1 with Query Params');
cy.ionPageVisible('home-details-page-1');
cy.location('search').should('eq', '?hello=there');
cy.window().then((win) => {
win.history.pushState({ marker: true }, '', win.location.href);
});
cy.go('back');
// No teleport: still on details 1, URL unchanged.
cy.ionPageVisible('home-details-page-1');
cy.location('pathname').should('eq', '/routing/tabs/home/details/1');
cy.location('search').should('eq', '?hello=there');
});
/*
Tests to add:
Test that lifecycle events fire
Test unmounting components by passing unmount to routerOptions
Test components mount/unmount properly
*/
});