@@ -416,8 +416,16 @@ describe('uiSrefActive', function() {
416
416
} ) ;
417
417
} ) ) ;
418
418
419
- beforeEach ( inject ( function ( $document ) {
419
+ beforeEach ( inject ( function ( $document , $timeout ) {
420
420
document = $document [ 0 ] ;
421
+ timeoutFlush = function ( ) {
422
+ try {
423
+ $timeout . flush ( ) ;
424
+ } catch ( e ) {
425
+ // Angular 1.0.8 throws 'No deferred tasks to be flushed' if there is nothing in queue.
426
+ // Behave as Angular >=1.1.5 and do nothing in such case.
427
+ }
428
+ }
421
429
} ) ) ;
422
430
423
431
it ( 'should update class for sibling uiSref' , inject ( function ( $rootScope , $q , $compile , $state ) {
@@ -428,11 +436,12 @@ describe('uiSrefActive', function() {
428
436
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
429
437
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
430
438
$q . flush ( ) ;
431
-
439
+ timeoutFlush ( ) ;
432
440
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
433
441
434
442
$state . transitionTo ( 'contacts.item' , { id : 2 } ) ;
435
443
$q . flush ( ) ;
444
+ timeoutFlush ( ) ;
436
445
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
437
446
} ) ) ;
438
447
@@ -444,10 +453,12 @@ describe('uiSrefActive', function() {
444
453
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
445
454
$state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'bar' } ) ;
446
455
$q . flush ( ) ;
456
+ timeoutFlush ( ) ;
447
457
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
448
458
449
459
$state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'baz' } ) ;
450
460
$q . flush ( ) ;
461
+ timeoutFlush ( ) ;
451
462
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
452
463
} ) ) ;
453
464
@@ -458,10 +469,12 @@ describe('uiSrefActive', function() {
458
469
459
470
$state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
460
471
$q . flush ( ) ;
472
+ timeoutFlush ( ) ;
461
473
expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
462
474
463
475
$state . transitionTo ( 'contacts.item.edit' , { id : 4 } ) ;
464
476
$q . flush ( ) ;
477
+ timeoutFlush ( ) ;
465
478
expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e / ) ;
466
479
} ) ) ;
467
480
@@ -472,28 +485,51 @@ describe('uiSrefActive', function() {
472
485
473
486
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
474
487
$q . flush ( ) ;
488
+ timeoutFlush ( ) ;
475
489
expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
476
490
477
491
$state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
478
492
$q . flush ( ) ;
493
+ timeoutFlush ( ) ;
479
494
expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e / ) ;
480
495
} ) ) ;
481
496
497
+ it ( 'should match on child states when active-equals and active-equals-eq is used' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
498
+ template = $compile ( '<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active" ui-sref-active-eq="active-eq">Contacts</a></div>' ) ( $rootScope ) ;
499
+ $rootScope . $digest ( ) ;
500
+ var a = angular . element ( template [ 0 ] . getElementsByTagName ( 'a' ) [ 0 ] ) ;
501
+
502
+ $state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
503
+ $q . flush ( ) ;
504
+ timeoutFlush ( ) ;
505
+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
506
+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e - e q / ) ;
507
+
508
+ $state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
509
+ $q . flush ( ) ;
510
+ timeoutFlush ( ) ;
511
+ expect ( a . attr ( 'class' ) ) . toMatch ( / a c t i v e / ) ;
512
+ expect ( a . attr ( 'class' ) ) . not . toMatch ( / a c t i v e - e q / ) ;
513
+ } ) ) ;
514
+
482
515
it ( 'should resolve relative state refs' , inject ( function ( $rootScope , $q , $compile , $state ) {
483
516
el = angular . element ( '<section><div ui-view></div></section>' ) ;
484
517
template = $compile ( el ) ( $rootScope ) ;
485
518
$rootScope . $digest ( ) ;
486
519
487
520
$state . transitionTo ( 'contacts' ) ;
488
521
$q . flush ( ) ;
522
+ timeoutFlush ( ) ;
489
523
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
490
524
491
525
$state . transitionTo ( 'contacts.item' , { id : 6 } ) ;
492
526
$q . flush ( ) ;
527
+ timeoutFlush ( ) ;
493
528
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
494
529
495
530
$state . transitionTo ( 'contacts.item' , { id : 5 } ) ;
496
531
$q . flush ( ) ;
532
+ timeoutFlush ( ) ;
497
533
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
498
534
} ) ) ;
499
535
@@ -506,10 +542,12 @@ describe('uiSrefActive', function() {
506
542
507
543
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
508
544
$q . flush ( ) ;
545
+ timeoutFlush ( ) ;
509
546
expect ( angular . element ( template [ 0 ] ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
510
547
511
548
$state . transitionTo ( 'contacts.item' , { id : 2 } ) ;
512
549
$q . flush ( ) ;
550
+ timeoutFlush ( ) ;
513
551
expect ( angular . element ( template [ 0 ] ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
514
552
} ) ) ;
515
553
@@ -524,10 +562,12 @@ describe('uiSrefActive', function() {
524
562
525
563
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
526
564
$q . flush ( ) ;
565
+ timeoutFlush ( ) ;
527
566
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
528
567
529
568
$state . transitionTo ( 'contacts.lazy' ) ;
530
569
$q . flush ( ) ;
570
+ timeoutFlush ( ) ;
531
571
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
532
572
} ) ) ;
533
573
@@ -542,10 +582,12 @@ describe('uiSrefActive', function() {
542
582
543
583
$state . transitionTo ( 'contacts.item' , { id : 1 } ) ;
544
584
$q . flush ( ) ;
585
+ timeoutFlush ( ) ;
545
586
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
546
587
547
588
$state . transitionTo ( 'contacts.lazy' ) ;
548
589
$q . flush ( ) ;
590
+ timeoutFlush ( ) ;
549
591
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
550
592
} ) ) ;
551
593
} ) ;
0 commit comments