Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50672 views
1
2
createTest('Nested route with the many children as a tokens, callbacks should yield historic params', {
3
'/a': {
4
'/:id': {
5
'/:id': function(a, b) {
6
shared.fired.push(location.hash, a, b);
7
}
8
}
9
}
10
}, function() {
11
shared.fired = [];
12
this.navigate('/a/b/c', function() {
13
deepEqual(shared.fired, ['#/a/b/c', 'b', 'c']);
14
this.finish();
15
});
16
});
17
18
createTest('Nested route with the first child as a token, callback should yield a param', {
19
'/foo': {
20
'/:id': {
21
on: function(id) {
22
shared.fired.push(location.hash, id);
23
}
24
}
25
}
26
}, function() {
27
shared.fired = [];
28
this.navigate('/foo/a', function() {
29
this.navigate('/foo/b/c', function() {
30
deepEqual(shared.fired, ['#/foo/a', 'a']);
31
this.finish();
32
});
33
});
34
});
35
36
createTest('Nested route with the first child as a regexp, callback should yield a param', {
37
'/foo': {
38
'/(\\w+)': {
39
on: function(value) {
40
shared.fired.push(location.hash, value);
41
}
42
}
43
}
44
}, function() {
45
shared.fired = [];
46
this.navigate('/foo/a', function() {
47
this.navigate('/foo/b/c', function() {
48
deepEqual(shared.fired, ['#/foo/a', 'a']);
49
this.finish();
50
});
51
});
52
});
53
54
createTest('Nested route with the several regular expressions, callback should yield a param', {
55
'/a': {
56
'/(\\w+)': {
57
'/(\\w+)': function(a, b) {
58
shared.fired.push(a, b);
59
}
60
}
61
}
62
}, function() {
63
shared.fired = [];
64
this.navigate('/a/b/c', function() {
65
deepEqual(shared.fired, ['b', 'c']);
66
this.finish();
67
});
68
});
69
70
71
72
createTest('Single nested route with on member containing function value', {
73
'/a': {
74
'/b': {
75
on: function() {
76
shared.fired.push(location.hash);
77
}
78
}
79
}
80
}, function() {
81
shared.fired = [];
82
this.navigate('/a/b', function() {
83
deepEqual(shared.fired, ['#/a/b']);
84
this.finish();
85
});
86
});
87
88
createTest('Single non-nested route with on member containing function value', {
89
'/a/b': {
90
on: function() {
91
shared.fired.push(location.hash);
92
}
93
}
94
}, function() {
95
shared.fired = [];
96
this.navigate('/a/b', function() {
97
deepEqual(shared.fired, ['#/a/b']);
98
this.finish();
99
});
100
});
101
102
createTest('Single nested route with on member containing array of function values', {
103
'/a': {
104
'/b': {
105
on: [function() { shared.fired.push(location.hash); },
106
function() { shared.fired.push(location.hash); }]
107
}
108
}
109
}, function() {
110
shared.fired = [];
111
this.navigate('/a/b', function() {
112
deepEqual(shared.fired, ['#/a/b', '#/a/b']);
113
this.finish();
114
});
115
});
116
117
createTest('method should only fire once on the route.', {
118
'/a': {
119
'/b': {
120
once: function() {
121
shared.fired++;
122
}
123
}
124
}
125
}, function() {
126
shared.fired = 0;
127
this.navigate('/a/b', function() {
128
this.navigate('/a/b', function() {
129
this.navigate('/a/b', function() {
130
deepEqual(shared.fired, 1);
131
this.finish();
132
});
133
});
134
});
135
});
136
137
createTest('method should only fire once on the route, multiple nesting.', {
138
'/a': {
139
on: function() { shared.fired++; },
140
once: function() { shared.fired++; }
141
},
142
'/b': {
143
on: function() { shared.fired++; },
144
once: function() { shared.fired++; }
145
}
146
}, function() {
147
shared.fired = 0;
148
this.navigate('/a', function() {
149
this.navigate('/b', function() {
150
this.navigate('/a', function() {
151
this.navigate('/b', function() {
152
deepEqual(shared.fired, 6);
153
this.finish();
154
});
155
});
156
});
157
});
158
});
159
160
createTest('overlapping routes with tokens.', {
161
'/a/:b/c' : function() {
162
shared.fired.push(location.hash);
163
},
164
'/a/:b/c/:d' : function() {
165
shared.fired.push(location.hash);
166
}
167
}, function() {
168
shared.fired = [];
169
this.navigate('/a/b/c', function() {
170
171
this.navigate('/a/b/c/d', function() {
172
deepEqual(shared.fired, ['#/a/b/c', '#/a/b/c/d']);
173
this.finish();
174
});
175
});
176
});
177
178
// // //
179
// // // Recursion features
180
// // // ----------------------------------------------------------
181
182
createTest('Nested routes with no recursion', {
183
'/a': {
184
'/b': {
185
'/c': {
186
on: function c() {
187
shared.fired.push('c');
188
}
189
},
190
on: function b() {
191
shared.fired.push('b');
192
}
193
},
194
on: function a() {
195
shared.fired.push('a');
196
}
197
}
198
}, function() {
199
shared.fired = [];
200
201
this.navigate('/a/b/c', function() {
202
deepEqual(shared.fired, ['c']);
203
this.finish();
204
});
205
});
206
207
createTest('Nested routes with backward recursion', {
208
'/a': {
209
'/b': {
210
'/c': {
211
on: function c() {
212
shared.fired.push('c');
213
}
214
},
215
on: function b() {
216
shared.fired.push('b');
217
}
218
},
219
on: function a() {
220
shared.fired.push('a');
221
}
222
}
223
}, {
224
recurse: 'backward'
225
}, function() {
226
shared.fired = [];
227
228
this.navigate('/a/b/c', function() {
229
deepEqual(shared.fired, ['c', 'b', 'a']);
230
this.finish();
231
});
232
});
233
234
createTest('Breaking out of nested routes with backward recursion', {
235
'/a': {
236
'/:b': {
237
'/c': {
238
on: function c() {
239
shared.fired.push('c');
240
}
241
},
242
on: function b() {
243
shared.fired.push('b');
244
return false;
245
}
246
},
247
on: function a() {
248
shared.fired.push('a');
249
}
250
}
251
}, {
252
recurse: 'backward'
253
}, function() {
254
shared.fired = [];
255
256
this.navigate('/a/b/c', function() {
257
deepEqual(shared.fired, ['c', 'b']);
258
this.finish();
259
});
260
});
261
262
createTest('Nested routes with forward recursion', {
263
'/a': {
264
'/b': {
265
'/c': {
266
on: function c() {
267
shared.fired.push('c');
268
}
269
},
270
on: function b() {
271
shared.fired.push('b');
272
}
273
},
274
on: function a() {
275
shared.fired.push('a');
276
}
277
}
278
}, {
279
recurse: 'forward'
280
}, function() {
281
shared.fired = [];
282
283
this.navigate('/a/b/c', function() {
284
deepEqual(shared.fired, ['a', 'b', 'c']);
285
this.finish();
286
});
287
});
288
289
createTest('Nested routes with forward recursion, single route with an after event.', {
290
'/a': {
291
'/b': {
292
'/c': {
293
on: function c() {
294
shared.fired.push('c');
295
},
296
after: function() {
297
shared.fired.push('c-after');
298
}
299
},
300
on: function b() {
301
shared.fired.push('b');
302
}
303
},
304
on: function a() {
305
shared.fired.push('a');
306
}
307
}
308
}, {
309
recurse: 'forward'
310
}, function() {
311
shared.fired = [];
312
313
this.navigate('/a/b/c', function() {
314
this.navigate('/a/b', function() {
315
deepEqual(shared.fired, ['a', 'b', 'c', 'c-after', 'a', 'b']);
316
this.finish();
317
});
318
});
319
});
320
321
createTest('Breaking out of nested routes with forward recursion', {
322
'/a': {
323
'/b': {
324
'/c': {
325
on: function c() {
326
shared.fired.push('c');
327
}
328
},
329
on: function b() {
330
shared.fired.push('b');
331
return false;
332
}
333
},
334
on: function a() {
335
shared.fired.push('a');
336
}
337
}
338
}, {
339
recurse: 'forward'
340
}, function() {
341
shared.fired = [];
342
343
this.navigate('/a/b/c', function() {
344
deepEqual(shared.fired, ['a', 'b']);
345
this.finish();
346
});
347
});
348
349
//
350
// ABOVE IS WORKING
351
//
352
353
// //
354
// // Special Events
355
// // ----------------------------------------------------------
356
357
createTest('All global event should fire after every route', {
358
'/a': {
359
on: function a() {
360
shared.fired.push('a');
361
}
362
},
363
'/b': {
364
'/c': {
365
on: function a() {
366
shared.fired.push('a');
367
}
368
}
369
},
370
'/d': {
371
'/:e': {
372
on: function a() {
373
shared.fired.push('a');
374
}
375
}
376
}
377
}, {
378
after: function() {
379
shared.fired.push('b');
380
}
381
}, function() {
382
shared.fired = [];
383
384
this.navigate('/a', function() {
385
this.navigate('/b/c', function() {
386
this.navigate('/d/e', function() {
387
deepEqual(shared.fired, ['a', 'b', 'a', 'b', 'a']);
388
this.finish();
389
});
390
});
391
});
392
393
});
394
395
createTest('Not found.', {
396
'/a': {
397
on: function a() {
398
shared.fired.push('a');
399
}
400
},
401
'/b': {
402
on: function a() {
403
shared.fired.push('b');
404
}
405
}
406
}, {
407
notfound: function() {
408
shared.fired.push('notfound');
409
}
410
}, function() {
411
shared.fired = [];
412
413
this.navigate('/c', function() {
414
this.navigate('/d', function() {
415
deepEqual(shared.fired, ['notfound', 'notfound']);
416
this.finish();
417
});
418
});
419
});
420
421
createTest('On all.', {
422
'/a': {
423
on: function a() {
424
shared.fired.push('a');
425
}
426
},
427
'/b': {
428
on: function a() {
429
shared.fired.push('b');
430
}
431
}
432
}, {
433
on: function() {
434
shared.fired.push('c');
435
}
436
}, function() {
437
shared.fired = [];
438
439
this.navigate('/a', function() {
440
this.navigate('/b', function() {
441
deepEqual(shared.fired, ['a', 'c', 'b', 'c']);
442
this.finish();
443
});
444
});
445
});
446
447
448
createTest('After all.', {
449
'/a': {
450
on: function a() {
451
shared.fired.push('a');
452
}
453
},
454
'/b': {
455
on: function a() {
456
shared.fired.push('b');
457
}
458
}
459
}, {
460
after: function() {
461
shared.fired.push('c');
462
}
463
}, function() {
464
shared.fired = [];
465
466
this.navigate('/a', function() {
467
this.navigate('/b', function() {
468
deepEqual(shared.fired, ['a', 'c', 'b']);
469
this.finish();
470
});
471
});
472
});
473
474
createTest('resource object.', {
475
'/a': {
476
'/b/:c': {
477
on: 'f1'
478
},
479
on: 'f2'
480
},
481
'/d': {
482
on: ['f1', 'f2']
483
}
484
},
485
{
486
resource: {
487
f1: function (name){
488
shared.fired.push("f1-" + name);
489
},
490
f2: function (name){
491
shared.fired.push("f2");
492
}
493
}
494
}, function() {
495
shared.fired = [];
496
497
this.navigate('/a/b/c', function() {
498
this.navigate('/d', function() {
499
deepEqual(shared.fired, ['f1-c', 'f1-undefined', 'f2']);
500
this.finish();
501
});
502
});
503
});
504
505
createTest('argument matching should be case agnostic', {
506
'/fooBar/:name': {
507
on: function(name) {
508
shared.fired.push("fooBar-" + name);
509
}
510
}
511
}, function() {
512
shared.fired = [];
513
this.navigate('/fooBar/tesTing', function() {
514
deepEqual(shared.fired, ['fooBar-tesTing']);
515
this.finish();
516
});
517
});
518
519
createTest('sanity test', {
520
'/is/:this/:sane': {
521
on: function(a, b) {
522
shared.fired.push('yes ' + a + ' is ' + b);
523
}
524
},
525
'/': {
526
on: function() {
527
shared.fired.push('is there sanity?');
528
}
529
}
530
}, function() {
531
shared.fired = [];
532
this.navigate('/is/there/sanity', function() {
533
deepEqual(shared.fired, ['yes there is sanity']);
534
this.finish();
535
});
536
});
537
538
createTest('`/` route should be navigable from the routing table', {
539
'/': {
540
on: function root() {
541
shared.fired.push('/');
542
}
543
},
544
'/:username': {
545
on: function afunc(username) {
546
shared.fired.push('/' + username);
547
}
548
}
549
}, function() {
550
shared.fired = [];
551
this.navigate('/', function root() {
552
deepEqual(shared.fired, ['/']);
553
this.finish();
554
});
555
});
556
557
createTest('`/` route should not override a `/:token` route', {
558
'/': {
559
on: function root() {
560
shared.fired.push('/');
561
}
562
},
563
'/:username': {
564
on: function afunc(username) {
565
shared.fired.push('/' + username);
566
}
567
}
568
}, function() {
569
shared.fired = [];
570
this.navigate('/a', function afunc() {
571
deepEqual(shared.fired, ['/a']);
572
this.finish();
573
});
574
});
575
576
createTest('should accept the root as a token.', {
577
'/:a': {
578
on: function root() {
579
shared.fired.push(location.hash);
580
}
581
}
582
}, function() {
583
shared.fired = [];
584
this.navigate('/a', function root() {
585
deepEqual(shared.fired, ['#/a']);
586
this.finish();
587
});
588
});
589
590
createTest('routes should allow wildcards.', {
591
'/:a/b*d': {
592
on: function() {
593
shared.fired.push(location.hash);
594
}
595
}
596
}, function() {
597
shared.fired = [];
598
this.navigate('/a/bcd', function root() {
599
deepEqual(shared.fired, ['#/a/bcd']);
600
this.finish();
601
});
602
});
603
604
createTest('functions should have |this| context of the router instance.', {
605
'/': {
606
on: function root() {
607
shared.fired.push(!!this.routes);
608
}
609
}
610
}, function() {
611
shared.fired = [];
612
this.navigate('/', function root() {
613
deepEqual(shared.fired, [true]);
614
this.finish();
615
});
616
});
617
618
createTest('setRoute with a single parameter should change location correctly', {
619
'/bonk': {
620
on: function() {
621
shared.fired.push(window.location.hash);
622
}
623
}
624
}, function() {
625
var self = this;
626
shared.fired = [];
627
this.router.setRoute('/bonk');
628
setTimeout(function() {
629
deepEqual(shared.fired, ['#/bonk']);
630
self.finish();
631
}, 14)
632
});
633
634
createTest('route should accept _ and . within parameters', {
635
'/:a': {
636
on: function root() {
637
shared.fired.push(location.hash);
638
}
639
}
640
}, function() {
641
shared.fired = [];
642
this.navigate('/a_complex_route.co.uk', function root() {
643
deepEqual(shared.fired, ['#/a_complex_route.co.uk']);
644
this.finish();
645
});
646
});
647
648
createTest('initializing with a default route should only result in one route handling', {
649
'/': {
650
on: function root() {
651
if (!shared.init){
652
shared.init = 0;
653
}
654
shared.init++;
655
}
656
},
657
'/test': {
658
on: function root() {
659
if (!shared.test){
660
shared.test = 0;
661
}
662
shared.test++;
663
}
664
}
665
}, function() {
666
this.navigate('/test', function root() {
667
equal(shared.init, 1);
668
equal(shared.test, 1);
669
this.finish();
670
});
671
},
672
null,
673
'/');
674
675
createTest('changing the hash twice should call each route once', {
676
'/hash1': {
677
on: function root() {
678
shared.fired.push('hash1');
679
}
680
},
681
'/hash2': {
682
on: function root() {
683
shared.fired.push('hash2');
684
}
685
}
686
}, function() {
687
shared.fired = [];
688
this.navigate('/hash1', function(){});
689
this.navigate('/hash2', function(){
690
deepEqual(shared.fired, ['hash1', 'hash2']);
691
this.finish();
692
});
693
}
694
);
695
696