@@ -426,8 +426,16 @@ describe('uiSrefActive', function() {
426
426
} ) ;
427
427
} ) ) ;
428
428
429
- beforeEach ( inject ( function ( $document ) {
429
+ beforeEach ( inject ( function ( $document , $timeout ) {
430
430
document = $document [ 0 ] ;
431
+ timeoutFlush = function ( ) {
432
+ try {
433
+ $timeout . flush ( ) ;
434
+ } catch ( e ) {
435
+ // Angular 1.0.8 throws 'No deferred tasks to be flushed' if there is nothing in queue.
436
+ // Behave as Angular >=1.1.5 and do nothing in such case.
437
+ }
438
+ }
431
439
} ) ) ;
432
440
433
441
it ( 'should update class for sibling uiSref' , inject ( function ( $rootScope , $q , $compile , $state ) {
@@ -438,11 +446,12 @@ describe('uiSrefActive', function() {
438
446
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
439
447
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
440
448
$q . flush ( ) ;
441
-
449
+ timeoutFlush ( ) ;
442
450
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
443
451
444
452
$state . transitionTo ( 'contacts.item' , { id : 2 } ) ;
445
453
$q . flush ( ) ;
454
+ timeoutFlush ( ) ;
446
455
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
447
456
} ) ) ;
448
457
@@ -454,10 +463,12 @@ describe('uiSrefActive', function() {
454
463
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
455
464
$state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'bar' } ) ;
456
465
$q . flush ( ) ;
466
+ timeoutFlush ( ) ;
457
467
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
458
468
459
469
$state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'baz' } ) ;
460
470
$q . flush ( ) ;
471
+ timeoutFlush ( ) ;
461
472
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
462
473
} ) ) ;
463
474
@@ -468,10 +479,12 @@ describe('uiSrefActive', function() {
468
479
469
480
$state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
470
481
$q . flush ( ) ;
482
+ timeoutFlush ( ) ;
471
483
expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
472
484
473
485
$state . transitionTo ( 'contacts.item.edit' , { id : 4 } ) ;
474
486
$q . flush ( ) ;
487
+ timeoutFlush ( ) ;
475
488
expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e / ) ;
476
489
} ) ) ;
477
490
@@ -482,28 +495,51 @@ describe('uiSrefActive', function() {
482
495
483
496
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
484
497
$q . flush ( ) ;
498
+ timeoutFlush ( ) ;
485
499
expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
486
500
487
501
$state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
488
502
$q . flush ( ) ;
503
+ timeoutFlush ( ) ;
489
504
expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e / ) ;
490
505
} ) ) ;
491
506
507
+ it ( 'should match on child states when active-equals and active-equals-eq is used' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
508
+ template = $compile ( '<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active" ui-sref-active-eq="active-eq">Contacts</a></div>' ) ( $rootScope ) ;
509
+ $rootScope . $digest ( ) ;
510
+ var a = angular . element ( template [ 0 ] . getElementsByTagName ( 'a' ) [ 0 ] ) ;
511
+
512
+ $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
513
+ $q . flush ( ) ;
514
+ timeoutFlush ( ) ;
515
+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
516
+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e - e q / ) ;
517
+
518
+ $state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
519
+ $q . flush ( ) ;
520
+ timeoutFlush ( ) ;
521
+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
522
+ expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e - e q / ) ;
523
+ } ) ) ;
524
+
492
525
it ( 'should resolve relative state refs' , inject ( function ( $rootScope , $q , $compile , $state ) {
493
526
el = angular . element ( '<section><div ui-view></div></section>' ) ;
494
527
template = $compile ( el ) ( $rootScope ) ;
495
528
$rootScope . $digest ( ) ;
496
529
497
530
$state . transitionTo ( 'contacts' ) ;
498
531
$q . flush ( ) ;
532
+ timeoutFlush ( ) ;
499
533
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
500
534
501
535
$state . transitionTo ( 'contacts.item' , { id : 6 } ) ;
502
536
$q . flush ( ) ;
537
+ timeoutFlush ( ) ;
503
538
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
504
539
505
540
$state . transitionTo ( 'contacts.item' , { id : 5 } ) ;
506
541
$q . flush ( ) ;
542
+ timeoutFlush ( ) ;
507
543
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
508
544
} ) ) ;
509
545
@@ -516,10 +552,12 @@ describe('uiSrefActive', function() {
516
552
517
553
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
518
554
$q . flush ( ) ;
555
+ timeoutFlush ( ) ;
519
556
expect ( angular . element ( template [ 0 ] ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
520
557
521
558
$state . transitionTo ( 'contacts.item' , { id : 2 } ) ;
522
559
$q . flush ( ) ;
560
+ timeoutFlush ( ) ;
523
561
expect ( angular . element ( template [ 0 ] ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
524
562
} ) ) ;
525
563
@@ -534,10 +572,12 @@ describe('uiSrefActive', function() {
534
572
535
573
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
536
574
$q . flush ( ) ;
575
+ timeoutFlush ( ) ;
537
576
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
538
577
539
578
$state . transitionTo ( 'contacts.lazy' ) ;
540
579
$q . flush ( ) ;
580
+ timeoutFlush ( ) ;
541
581
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
542
582
} ) ) ;
543
583
@@ -552,10 +592,12 @@ describe('uiSrefActive', function() {
552
592
553
593
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
554
594
$q . flush ( ) ;
595
+ timeoutFlush ( ) ;
555
596
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
556
597
557
598
$state . transitionTo ( 'contacts.lazy' ) ;
558
599
$q . flush ( ) ;
600
+ timeoutFlush ( ) ;
559
601
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
560
602
} ) ) ;
561
603
} ) ;
0 commit comments