@@ -12,7 +12,7 @@ describe('uiView', function () {
12
12
var log , scope , $compile , elem ;
13
13
14
14
beforeEach ( function ( ) {
15
- var depends = [ 'ui.router' ] ;
15
+ var depends = [ 'ui.router' , 'ui.router.state.events' ] ;
16
16
17
17
try {
18
18
angular . module ( 'ngAnimate' ) ;
@@ -26,7 +26,8 @@ describe('uiView', function () {
26
26
module ( 'ui.router.test' ) ;
27
27
} ) ;
28
28
29
- beforeEach ( module ( function ( $provide ) {
29
+ beforeEach ( module ( function ( $provide , $stateEventsProvider ) {
30
+ $stateEventsProvider . enable ( ) ;
30
31
$provide . decorator ( '$uiViewScroll' , function ( ) {
31
32
return jasmine . createSpy ( '$uiViewScroll' ) ;
32
33
} ) ;
@@ -132,17 +133,13 @@ describe('uiView', function () {
132
133
. state ( 'm' , {
133
134
template : 'mState' ,
134
135
controller : function ( $scope ) {
135
- log += 'm;' ;
136
- $scope . $on ( '$destroy' , function ( ) {
137
- log += '$destroy(m);' ;
138
- } ) ;
139
- } ,
136
+ log += 'ctrl(m);' ;
137
+ $scope . $on ( '$destroy' , function ( ) { log += '$destroy(m);' ; } ) ;
138
+ }
140
139
} )
141
140
. state ( 'n' , {
142
141
template : 'nState' ,
143
- controller : function ( $scope ) {
144
- log += 'n;' ;
145
- } ,
142
+ controller : function ( $scope ) { log += 'ctrl(n);' ; }
146
143
} )
147
144
. state ( 'o' , oState )
148
145
} ) ) ;
@@ -155,23 +152,6 @@ describe('uiView', function () {
155
152
156
153
describe ( 'linking ui-directive' , function ( ) {
157
154
158
- it ( '$destroy event is triggered after animation ends' , inject ( function ( $state , $q , $animate ) {
159
- elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
160
-
161
- $state . transitionTo ( 'm' ) ;
162
- $q . flush ( ) ;
163
- expect ( log ) . toBe ( 'm;' ) ;
164
- $state . transitionTo ( 'n' ) ;
165
- $q . flush ( ) ;
166
- if ( $animate ) {
167
- expect ( log ) . toBe ( 'm;n;' ) ;
168
- animateFlush ( $animate ) ;
169
- expect ( log ) . toBe ( 'm;n;$destroy(m);' ) ;
170
- } else {
171
- expect ( log ) . toBe ( 'm;$destroy(m);n;' ) ;
172
- }
173
- } ) ) ;
174
-
175
155
it ( 'anonymous ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q ) {
176
156
elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
177
157
@@ -610,6 +590,53 @@ describe('uiView', function () {
610
590
// No more animations
611
591
expect ( $animate . queue . length ) . toBe ( 0 ) ;
612
592
} ) ) ;
593
+
594
+ it ( 'should disable animations if noanimation="true" is present' , inject ( function ( $state , $q , $compile , $animate ) {
595
+ var content = 'Initial Content' , animation ;
596
+ elem . append ( $compile ( '<div><ui-view noanimation="true">' + content + '</ui-view></div>' ) ( scope ) ) ;
597
+
598
+ animation = $animate . queue . shift ( ) ;
599
+ expect ( animation ) . toBeUndefined ( ) ;
600
+
601
+ $state . transitionTo ( aState ) ;
602
+ $q . flush ( ) ;
603
+ animation = $animate . queue . shift ( ) ;
604
+ expect ( animation ) . toBeUndefined ( ) ;
605
+ expect ( elem . text ( ) ) . toBe ( aState . template ) ;
606
+
607
+ $state . transitionTo ( bState ) ;
608
+ $q . flush ( ) ;
609
+ animation = $animate . queue . shift ( ) ;
610
+ expect ( animation ) . toBeUndefined ( ) ;
611
+ expect ( elem . text ( ) ) . toBe ( bState . template ) ;
612
+ } ) ) ;
613
+
614
+ describe ( '$destroy event' , function ( ) {
615
+ it ( 'is triggered after animation ends' , inject ( function ( $state , $q , $animate , $rootScope ) {
616
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
617
+
618
+ $state . transitionTo ( 'm' ) ;
619
+ $q . flush ( ) ;
620
+ expect ( log ) . toBe ( 'ctrl(m);' ) ;
621
+ $state . transitionTo ( 'n' ) ;
622
+ $q . flush ( ) ;
623
+
624
+ expect ( log ) . toBe ( 'ctrl(m);ctrl(n);' ) ;
625
+ animateFlush ( $animate ) ;
626
+ expect ( log ) . toBe ( 'ctrl(m);ctrl(n);$destroy(m);' ) ;
627
+ } ) ) ;
628
+
629
+ it ( 'is triggered before $stateChangeSuccess if noanimation is present' , inject ( function ( $state , $q , $animate , $rootScope ) {
630
+ elem . append ( $compile ( '<div><ui-view noanimation="true"></ui-view></div>' ) ( scope ) ) ;
631
+
632
+ $state . transitionTo ( 'm' ) ;
633
+ $q . flush ( ) ;
634
+ expect ( log ) . toBe ( 'ctrl(m);' ) ;
635
+ $state . transitionTo ( 'n' ) ;
636
+ $q . flush ( ) ;
637
+ expect ( log ) . toBe ( 'ctrl(m);$destroy(m);ctrl(n);' ) ;
638
+ } ) ) ;
639
+ } ) ;
613
640
} ) ;
614
641
} ) ;
615
642
0 commit comments