@@ -12,7 +12,7 @@ describe('uiView', function () {
1212 var log , scope , $compile , elem ;
1313
1414 beforeEach ( function ( ) {
15- var depends = [ 'ui.router' ] ;
15+ var depends = [ 'ui.router' , 'ui.router.state.events' ] ;
1616
1717 try {
1818 angular . module ( 'ngAnimate' ) ;
@@ -26,7 +26,8 @@ describe('uiView', function () {
2626 module ( 'ui.router.test' ) ;
2727 } ) ;
2828
29- beforeEach ( module ( function ( $provide ) {
29+ beforeEach ( module ( function ( $provide , $stateEventsProvider ) {
30+ $stateEventsProvider . enable ( ) ;
3031 $provide . decorator ( '$uiViewScroll' , function ( ) {
3132 return jasmine . createSpy ( '$uiViewScroll' ) ;
3233 } ) ;
@@ -132,17 +133,13 @@ describe('uiView', function () {
132133 . state ( 'm' , {
133134 template : 'mState' ,
134135 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+ }
140139 } )
141140 . state ( 'n' , {
142141 template : 'nState' ,
143- controller : function ( $scope ) {
144- log += 'n;' ;
145- } ,
142+ controller : function ( $scope ) { log += 'ctrl(n);' ; }
146143 } )
147144 . state ( 'o' , oState )
148145 } ) ) ;
@@ -155,23 +152,6 @@ describe('uiView', function () {
155152
156153 describe ( 'linking ui-directive' , function ( ) {
157154
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-
175155 it ( 'anonymous ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q ) {
176156 elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
177157
@@ -610,6 +590,53 @@ describe('uiView', function () {
610590 // No more animations
611591 expect ( $animate . queue . length ) . toBe ( 0 ) ;
612592 } ) ) ;
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+ } ) ;
613640 } ) ;
614641} ) ;
615642
0 commit comments