@@ -312,7 +312,7 @@ describe('App', () => {
312
312
} ) ;
313
313
} ) ;
314
314
315
- describe ( 'getActiveNav ' , ( ) => {
315
+ describe ( 'getActiveNavs ' , ( ) => {
316
316
317
317
it ( 'should get active NavController when using tabs with nested nav' , ( ) => {
318
318
const nav = mockNavController ( ) ;
@@ -340,6 +340,11 @@ describe('App', () => {
340
340
expect ( activeNavs . length ) . toEqual ( 2 ) ;
341
341
expect ( activeNavs [ 0 ] ) . toEqual ( nav2 ) ;
342
342
expect ( activeNavs [ 1 ] ) . toEqual ( nav3 ) ;
343
+
344
+ const activeNavsTwo = app . getActiveNavs ( ) ;
345
+ expect ( activeNavsTwo . length ) . toEqual ( 2 ) ;
346
+ expect ( activeNavsTwo [ 0 ] ) . toEqual ( nav2 ) ;
347
+ expect ( activeNavsTwo [ 1 ] ) . toEqual ( nav3 ) ;
343
348
} ) ;
344
349
345
350
it ( 'should get active NavController when using tabs, nested in a root nav' , ( ) => {
@@ -355,10 +360,12 @@ describe('App', () => {
355
360
tab2 . setSelected ( true ) ;
356
361
357
362
expect ( app . getActiveNavs ( nav . id ) [ 0 ] ) . toBe ( tab2 ) ;
363
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( tab2 ) ;
358
364
359
365
tab2 . setSelected ( false ) ;
360
366
tab3 . setSelected ( true ) ;
361
367
expect ( app . getActiveNavs ( nav . id ) [ 0 ] ) . toBe ( tab3 ) ;
368
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( tab3 ) ;
362
369
} ) ;
363
370
364
371
it ( 'should get active tab NavController when using tabs, and tabs is the root' , ( ) => {
@@ -371,10 +378,12 @@ describe('App', () => {
371
378
tab2 . setSelected ( true ) ;
372
379
373
380
expect ( app . getActiveNavs ( tabs . id ) [ 0 ] ) . toBe ( tab2 ) ;
381
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( tab2 ) ;
374
382
375
383
tab2 . setSelected ( false ) ;
376
384
tab3 . setSelected ( true ) ;
377
385
expect ( app . getActiveNavs ( tabs . id ) [ 0 ] ) . toBe ( tab3 ) ;
386
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( tab3 ) ;
378
387
} ) ;
379
388
380
389
it ( 'should get active NavController when nested 3 deep' , ( ) => {
@@ -387,6 +396,8 @@ describe('App', () => {
387
396
nav2 . registerChildNav ( nav3 ) ;
388
397
389
398
expect ( app . getActiveNavs ( nav1 . id ) [ 0 ] ) . toBe ( nav3 ) ;
399
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( nav3 ) ;
400
+ expect ( app . getActiveNavs ( ) . length ) . toBe ( 1 ) ;
390
401
} ) ;
391
402
392
403
it ( 'should get active NavController when nested 2 deep' , ( ) => {
@@ -399,12 +410,15 @@ describe('App', () => {
399
410
const activeNav = app . getActiveNavs ( nav1 . id ) [ 0 ] ;
400
411
401
412
expect ( activeNav ) . toBe ( nav2 ) ;
413
+
414
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( nav2 ) ;
402
415
} ) ;
403
416
404
417
it ( 'should get active NavController when only one nav controller' , ( ) => {
405
418
const nav = mockNavController ( ) ;
406
419
app . registerRootNav ( nav ) ;
407
420
expect ( app . getActiveNavs ( nav . id ) [ 0 ] ) . toBe ( nav ) ;
421
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( nav ) ;
408
422
} ) ;
409
423
410
424
it ( 'should set/get the root nav controller' , ( ) => {
@@ -414,9 +428,9 @@ describe('App', () => {
414
428
} ) ;
415
429
416
430
it ( 'should not get an active NavController if there is not root set' , ( ) => {
417
- const activeNav = app . getActiveNavs ( '' ) ;
431
+ const activeNavs = app . getActiveNavs ( ) ;
418
432
const rootNav = app . getRootNavById ( '' ) ;
419
- expect ( activeNav . length ) . toEqual ( 0 ) ;
433
+ expect ( activeNavs . length ) . toEqual ( 0 ) ;
420
434
expect ( rootNav ) . toBeFalsy ( ) ;
421
435
} ) ;
422
436
@@ -438,6 +452,9 @@ describe('App', () => {
438
452
439
453
expect ( activeNavOne ) . toBe ( childNavOne ) ;
440
454
expect ( activeNavTwo ) . toBe ( childNavTwo ) ;
455
+
456
+ expect ( app . getActiveNavs ( ) [ 0 ] ) . toBe ( childNavOne ) ;
457
+ expect ( app . getActiveNavs ( ) [ 1 ] ) . toBe ( childNavTwo ) ;
441
458
} ) ;
442
459
443
460
it ( 'should get the active nav when no id is provided assuming there is one nav' , ( ) => {
@@ -451,6 +468,167 @@ describe('App', () => {
451
468
452
469
expect ( result ) . toEqual ( childNavOne ) ;
453
470
} ) ;
471
+
472
+ it ( 'should return the all the active navs when there is not an id passed' , ( ) => {
473
+ const rootNavOne = mockNavController ( ) ;
474
+ app . registerRootNav ( rootNavOne ) ;
475
+
476
+ const rootNavTwo = mockNavController ( ) ;
477
+ app . registerRootNav ( rootNavTwo ) ;
478
+
479
+ const childNavOne = mockNavController ( ) ;
480
+ rootNavOne . registerChildNav ( childNavOne ) ;
481
+
482
+ const childChildNavOne = mockNavController ( ) ;
483
+ childNavOne . registerChildNav ( childChildNavOne ) ;
484
+
485
+ const childNavTwo = mockNavController ( ) ;
486
+ rootNavTwo . registerChildNav ( childNavTwo ) ;
487
+
488
+ const childChildNavTwo = mockNavController ( ) ;
489
+ childNavTwo . registerChildNav ( childChildNavTwo ) ;
490
+
491
+ const results = app . getActiveNavs ( ) ;
492
+ expect ( results . length ) . toEqual ( 2 ) ;
493
+ expect ( results [ 0 ] ) . toEqual ( childChildNavOne ) ;
494
+ expect ( results [ 1 ] ) . toEqual ( childChildNavTwo ) ;
495
+
496
+ const withIdResultsOne = app . getActiveNavs ( rootNavOne . id ) ;
497
+ expect ( withIdResultsOne . length ) . toEqual ( 1 ) ;
498
+ expect ( withIdResultsOne [ 0 ] ) . toEqual ( childChildNavOne ) ;
499
+
500
+ const withIdResultsTwo = app . getActiveNavs ( rootNavTwo . id ) ;
501
+ expect ( withIdResultsTwo . length ) . toEqual ( 1 ) ;
502
+ expect ( withIdResultsTwo [ 0 ] ) . toEqual ( childChildNavTwo ) ;
503
+ } ) ;
504
+ } ) ;
505
+
506
+ describe ( 'getActiveNav' , ( ) => {
507
+ it ( 'should get active NavController when using tabs with nested nav' , ( ) => {
508
+ const nav = mockNavController ( ) ;
509
+ app . registerRootNav ( nav ) ;
510
+
511
+ const tabs = mockTabs ( ) ;
512
+ const tab1 = mockTab ( tabs ) ;
513
+ const tab2 = mockTab ( tabs ) ;
514
+ nav . registerChildNav ( tabs ) ;
515
+
516
+ tab2 . setSelected ( true ) ;
517
+ const nav2 = mockNavController ( ) ;
518
+ nav2 . name = 'nav2' ;
519
+ const nav3 = mockNavController ( ) ;
520
+ nav3 . name = 'nav3' ;
521
+ const nav4 = mockNavController ( ) ;
522
+ nav4 . name = 'nav4' ;
523
+
524
+ tab1 . registerChildNav ( nav4 ) ;
525
+ // tab 2 registers two child navs!!
526
+ tab2 . registerChildNav ( nav2 ) ;
527
+ tab2 . registerChildNav ( nav3 ) ;
528
+
529
+ const activeNav = app . getActiveNav ( ) ;
530
+ expect ( activeNav ) . toEqual ( nav2 ) ;
531
+ } ) ;
532
+
533
+ it ( 'should get active NavController when using tabs, nested in a root nav' , ( ) => {
534
+ const nav = mockNavController ( ) ;
535
+ app . registerRootNav ( nav ) ;
536
+
537
+ const tabs = mockTabs ( ) ;
538
+ mockTab ( tabs ) ;
539
+ const tab2 = mockTab ( tabs ) ;
540
+ const tab3 = mockTab ( tabs ) ;
541
+ nav . registerChildNav ( tabs ) ;
542
+
543
+ tab2 . setSelected ( true ) ;
544
+
545
+ expect ( app . getActiveNav ( ) ) . toBe ( tab2 ) ;
546
+
547
+ tab2 . setSelected ( false ) ;
548
+ tab3 . setSelected ( true ) ;
549
+ expect ( app . getActiveNav ( ) ) . toBe ( tab3 ) ;
550
+ } ) ;
551
+
552
+ it ( 'should get active tab NavController when using tabs, and tabs is the root' , ( ) => {
553
+ const tabs = mockTabs ( ) ;
554
+ mockTab ( tabs ) ;
555
+ const tab2 = mockTab ( tabs ) ;
556
+ const tab3 = mockTab ( tabs ) ;
557
+ app . registerRootNav ( tabs ) ;
558
+
559
+ tab2 . setSelected ( true ) ;
560
+
561
+ expect ( app . getActiveNav ( ) ) . toBe ( tab2 ) ;
562
+
563
+ tab2 . setSelected ( false ) ;
564
+ tab3 . setSelected ( true ) ;
565
+ expect ( app . getActiveNav ( ) ) . toBe ( tab3 ) ;
566
+ } ) ;
567
+
568
+ it ( 'should get active NavController when nested 3 deep' , ( ) => {
569
+ const nav1 = mockNavController ( ) ;
570
+ const nav2 = mockNavController ( ) ;
571
+ const nav3 = mockNavController ( ) ;
572
+ app . registerRootNav ( nav1 ) ;
573
+
574
+ nav1 . registerChildNav ( nav2 ) ;
575
+ nav2 . registerChildNav ( nav3 ) ;
576
+
577
+ expect ( app . getActiveNav ( ) ) . toBe ( nav3 ) ;
578
+ } ) ;
579
+
580
+ it ( 'should get active NavController when nested 2 deep' , ( ) => {
581
+ const nav1 = mockNavController ( ) ;
582
+ const nav2 = mockNavController ( ) ;
583
+ app . registerRootNav ( nav1 ) ;
584
+
585
+ nav1 . registerChildNav ( nav2 ) ;
586
+
587
+ const activeNav = app . getActiveNav ( ) ;
588
+
589
+ expect ( activeNav ) . toBe ( nav2 ) ;
590
+ } ) ;
591
+
592
+ it ( 'should get active NavController when only one nav controller' , ( ) => {
593
+ const nav = mockNavController ( ) ;
594
+ app . registerRootNav ( nav ) ;
595
+ expect ( app . getActiveNav ( ) ) . toBe ( nav ) ;
596
+ } ) ;
597
+
598
+ it ( 'should not get an active NavController if there is not root set' , ( ) => {
599
+ const activeNav = app . getActiveNav ( ) ;
600
+ expect ( activeNav ) . toBeFalsy ( ) ;
601
+ } ) ;
602
+
603
+ it ( 'should just work when there are multiple active navs' , ( ) => {
604
+ const rootNavOne = mockNavController ( ) ;
605
+ const rootNavTwo = mockNavController ( ) ;
606
+
607
+ app . registerRootNav ( rootNavOne ) ;
608
+ app . registerRootNav ( rootNavTwo ) ;
609
+
610
+ const childNavOne = mockNavController ( ) ;
611
+ const childNavTwo = mockNavController ( ) ;
612
+
613
+ rootNavOne . registerChildNav ( childNavOne ) ;
614
+ rootNavTwo . registerChildNav ( childNavTwo ) ;
615
+
616
+ const activeNavOne = app . getActiveNav ( ) ;
617
+
618
+ expect ( activeNavOne ) . toBe ( childNavOne ) ;
619
+ } ) ;
620
+
621
+ it ( 'should get the active nav when no id is provided assuming there is one nav' , ( ) => {
622
+ const rootNavOne = mockNavController ( ) ;
623
+ app . registerRootNav ( rootNavOne ) ;
624
+
625
+ const childNavOne = mockNavController ( ) ;
626
+ rootNavOne . registerChildNav ( childNavOne ) ;
627
+
628
+ const result = app . getActiveNav ( ) ;
629
+
630
+ expect ( result ) . toEqual ( childNavOne ) ;
631
+ } ) ;
454
632
} ) ;
455
633
456
634
describe ( 'getRootNavs' , ( ) => {
0 commit comments