@@ -72,6 +72,18 @@ describe('uiStateRef', function() {
72
72
el [ 0 ] . dispatchEvent ( e ) ;
73
73
}
74
74
75
+ function triggerHTMLEvent ( name ) {
76
+ var event = document . createEvent ( 'HTMLEvents' ) ;
77
+ event . initEvent ( name , false , true ) ;
78
+ el [ 0 ] . dispatchEvent ( event ) ;
79
+ }
80
+
81
+ function triggerMouseEvent ( name ) {
82
+ var event = document . createEvent ( 'MouseEvents' ) ;
83
+ event . initEvent ( name , true , true ) ;
84
+ el [ 0 ] . dispatchEvent ( event ) ;
85
+ }
86
+
75
87
describe ( 'links with promises' , function ( ) {
76
88
77
89
it ( 'should update the href when promises on parameters change before scope is applied' , inject ( function ( $rootScope , $compile , $q ) {
@@ -523,6 +535,84 @@ describe('uiStateRef', function() {
523
535
expect ( transitionOptions . reload ) . toEqual ( true ) ;
524
536
expect ( transitionOptions . absolute ) . toBeUndefined ( ) ;
525
537
} ) ) ;
538
+
539
+ describe ( 'option event' , function ( ) {
540
+ it ( 'should bind click event by default' , inject ( function ( $compile , $state , $timeout ) {
541
+ expect ( $state . current . name ) . toBe ( 'top' ) ;
542
+
543
+ el = angular . element ( '<a ui-state="state"></a>' ) ;
544
+
545
+ scope . state = 'contacts' ;
546
+ $compile ( el ) ( scope ) ;
547
+ scope . $digest ( ) ;
548
+
549
+ triggerClick ( el ) ;
550
+ $timeout . flush ( ) ;
551
+
552
+ expect ( $state . current . name ) . toBe ( 'contacts' ) ;
553
+ } ) ) ;
554
+
555
+ it ( 'should bind single HTML events' , inject ( function ( $compile , $state , $timeout ) {
556
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
557
+
558
+ el = angular . element ( '<input type="text" ui-state="state" ui-state-opts="{ event: [\'change\'] }">' ) ;
559
+
560
+ scope . state = 'contacts' ;
561
+ $compile ( el ) ( scope ) ;
562
+ scope . $digest ( ) ;
563
+
564
+ triggerHTMLEvent ( 'change' ) ;
565
+ $timeout . flush ( ) ;
566
+
567
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
568
+ } ) ) ;
569
+
570
+ it ( 'should bind multiple HTML events' , inject ( function ( $compile , $state , $timeout ) {
571
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
572
+
573
+ el = angular . element ( '<input type="text" ui-state="state" ui-state-opts="{ event: [\'change\', \'blur\'] }">' ) ;
574
+
575
+ scope . state = 'contacts' ;
576
+ $compile ( el ) ( scope ) ;
577
+ scope . $digest ( ) ;
578
+
579
+ triggerHTMLEvent ( 'change' ) ;
580
+ $timeout . flush ( ) ;
581
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
582
+
583
+ $state . go ( 'top' ) ;
584
+ scope . $digest ( ) ;
585
+
586
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
587
+
588
+ triggerHTMLEvent ( 'blur' ) ;
589
+ $timeout . flush ( ) ;
590
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
591
+ } ) ) ;
592
+
593
+ it ( 'should bind multiple Mouse events' , inject ( function ( $compile , $state , $timeout ) {
594
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
595
+
596
+ el = angular . element ( '<a ui-state="state" ui-state-opts="{ event: [\'mouseover\', \'mousedown\'] }">' ) ;
597
+
598
+ scope . state = 'contacts' ;
599
+ $compile ( el ) ( scope ) ;
600
+ scope . $digest ( ) ;
601
+
602
+ triggerMouseEvent ( 'mouseover' ) ;
603
+ $timeout . flush ( ) ;
604
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
605
+
606
+ $state . go ( 'top' ) ;
607
+ scope . $digest ( ) ;
608
+
609
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
610
+
611
+ triggerMouseEvent ( 'mousedown' ) ;
612
+ $timeout . flush ( ) ;
613
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
614
+ } ) ) ;
615
+ } ) ;
526
616
} ) ;
527
617
528
618
describe ( 'forms' , function ( ) {
@@ -597,6 +687,76 @@ describe('uiStateRef', function() {
597
687
expect ( $state . $current . name ) . toBe ( "contacts" ) ;
598
688
} ) ) ;
599
689
} ) ;
690
+
691
+ describe ( 'option event' , function ( ) {
692
+ it ( 'should bind click event by default' , inject ( function ( $rootScope , $compile , $state , $timeout ) {
693
+ el = angular . element ( '<a ui-sref="contacts"></a>' ) ;
694
+ $compile ( el ) ( $rootScope ) ;
695
+ $rootScope . $digest ( ) ;
696
+
697
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
698
+
699
+ triggerClick ( el ) ;
700
+ $timeout . flush ( ) ;
701
+
702
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
703
+ } ) ) ;
704
+
705
+ it ( 'should bind single HTML events' , inject ( function ( $rootScope , $compile , $state , $timeout ) {
706
+ el = angular . element ( '<input type="text" ui-sref="contacts" ui-sref-opts="{ event: [\'change\'] }">' ) ;
707
+ $compile ( el ) ( $rootScope ) ;
708
+ $rootScope . $digest ( ) ;
709
+
710
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
711
+
712
+ triggerHTMLEvent ( 'change' ) ;
713
+ $timeout . flush ( ) ;
714
+
715
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
716
+ } ) ) ;
717
+
718
+ it ( 'should bind multiple HTML events' , inject ( function ( $rootScope , $compile , $state , $timeout ) {
719
+ el = angular . element ( '<input type="text" ui-sref="contacts" ui-sref-opts="{ event: [\'change\', \'blur\'] }">' ) ;
720
+ $compile ( el ) ( $rootScope ) ;
721
+ $rootScope . $digest ( ) ;
722
+
723
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
724
+
725
+ triggerHTMLEvent ( 'change' ) ;
726
+ $timeout . flush ( ) ;
727
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
728
+
729
+ $state . go ( 'top' ) ;
730
+ $rootScope . $digest ( ) ;
731
+
732
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
733
+
734
+ triggerHTMLEvent ( 'blur' ) ;
735
+ $timeout . flush ( ) ;
736
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
737
+ } ) ) ;
738
+
739
+ it ( 'should bind multiple Mouse events' , inject ( function ( $rootScope , $compile , $state , $timeout ) {
740
+ el = angular . element ( '<a ui-sref="contacts" ui-sref-opts="{ event: [\'mouseover\', \'mousedown\'] }">' ) ;
741
+ $compile ( el ) ( $rootScope ) ;
742
+ $rootScope . $digest ( ) ;
743
+
744
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
745
+
746
+ triggerMouseEvent ( 'mouseover' ) ;
747
+ $timeout . flush ( ) ;
748
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
749
+
750
+ $state . go ( 'top' ) ;
751
+ $rootScope . $digest ( ) ;
752
+
753
+ expect ( $state . current . name ) . toEqual ( 'top' ) ;
754
+
755
+ triggerMouseEvent ( 'mousedown' ) ;
756
+ $timeout . flush ( ) ;
757
+ expect ( $state . current . name ) . toEqual ( 'contacts' ) ;
758
+ } ) ) ;
759
+ } ) ;
600
760
} ) ;
601
761
602
762
describe ( 'uiSrefActive' , function ( ) {
0 commit comments