@@ -6,18 +6,14 @@ function animateFlush($animate) {
66 $animate && $animate . flush && $animate . flush ( ) ; // 1.4
77}
88
9- function animateFlush ( $animate ) {
10- $animate && $animate . triggerCallbacks && $animate . triggerCallbacks ( ) ; // 1.2-1.3
11- $animate && $animate . flush && $animate . flush ( ) ; // 1.4
12- }
13-
149describe ( 'uiView' , function ( ) {
1510 'use strict' ;
1611
17- var log , scope , $compile , elem ;
12+ var scope , $compile , elem , log ;
1813
1914 beforeEach ( function ( ) {
20- var depends = [ 'ui.router' , 'ui.router.state.events' ] ;
15+ var depends = [ 'ui.router' ] ;
16+ log = "" ;
2117
2218 try {
2319 angular . module ( 'ngAnimate' ) ;
@@ -31,17 +27,12 @@ describe('uiView', function () {
3127 module ( 'ui.router.test' ) ;
3228 } ) ;
3329
34- beforeEach ( module ( function ( $provide , $stateEventsProvider ) {
35- $stateEventsProvider . enable ( ) ;
30+ beforeEach ( module ( function ( $provide ) {
3631 $provide . decorator ( '$uiViewScroll' , function ( ) {
3732 return jasmine . createSpy ( '$uiViewScroll' ) ;
3833 } ) ;
3934 } ) ) ;
4035
41- beforeEach ( function ( ) {
42- log = '' ;
43- } ) ;
44-
4536 var aState = {
4637 template : 'aState template'
4738 } ,
@@ -113,12 +104,20 @@ describe('uiView', function () {
113104 }
114105 }
115106 } ,
116-
117- oState = {
118- template : 'oState' ,
107+ mState = {
108+ template : 'mState' ,
119109 controller : function ( $scope , $element ) {
120110 $scope . elementId = $element . attr ( 'id' ) ;
121111 }
112+ } ,
113+ nState = {
114+ template : 'nState' ,
115+ controller : function ( $scope , $element ) {
116+ var data = $element . data ( '$uiView' ) ;
117+ $scope . $on ( "$destroy" , function ( ) { log += 'destroy;' } ) ;
118+ data . $animEnter . then ( function ( ) { log += "animEnter;" } ) ;
119+ data . $animLeave . then ( function ( ) { log += "animLeave;" } ) ;
120+ }
122121 } ;
123122
124123 beforeEach ( module ( function ( $stateProvider ) {
@@ -135,18 +134,8 @@ describe('uiView', function () {
135134 . state ( 'j' , jState )
136135 . state ( 'k' , kState )
137136 . state ( 'l' , lState )
138- . state ( 'm' , {
139- template : 'mState' ,
140- controller : function ( $scope ) {
141- log += 'ctrl(m);' ;
142- $scope . $on ( '$destroy' , function ( ) { log += '$destroy(m);' ; } ) ;
143- }
144- } )
145- . state ( 'n' , {
146- template : 'nState' ,
147- controller : function ( $scope ) { log += 'ctrl(n);' ; }
148- } )
149- . state ( 'o' , oState )
137+ . state ( 'm' , mState )
138+ . state ( 'n' , nState )
150139 } ) ) ;
151140
152141 beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -342,11 +331,11 @@ describe('uiView', function () {
342331 } ) ) ;
343332
344333 it ( 'should instantiate a controller with both $scope and $element injections' , inject ( function ( $state , $q ) {
345- elem . append ( $compile ( '<div><ui-view id="oState ">{{elementId}}</ui-view></div>' ) ( scope ) ) ;
346- $state . transitionTo ( oState ) ;
334+ elem . append ( $compile ( '<div><ui-view id="mState ">{{elementId}}</ui-view></div>' ) ( scope ) ) ;
335+ $state . transitionTo ( mState ) ;
347336 $q . flush ( ) ;
348337
349- expect ( elem . text ( ) ) . toBe ( 'oState ' ) ;
338+ expect ( elem . text ( ) ) . toBe ( 'mState ' ) ;
350339 } ) ) ;
351340
352341 describe ( 'play nicely with other directives' , function ( ) {
@@ -596,52 +585,33 @@ describe('uiView', function () {
596585 expect ( $animate . queue . length ) . toBe ( 0 ) ;
597586 } ) ) ;
598587
599- it ( 'should disable animations if noanimation="true" is present' , inject ( function ( $state , $q , $compile , $animate ) {
600- var content = 'Initial Content' , animation ;
601- elem . append ( $compile ( '<div><ui-view noanimation="true">' + content + '</ui-view></div>' ) ( scope ) ) ;
588+ it ( 'should expose animation promises to controllers' , inject ( function ( $state , $q , $compile , $animate , $transitions ) {
589+ $transitions . onStart ( { } , function ( $transition$ ) { log += 'start:' + $transition$ . to ( ) . name + ';' ; } ) ;
590+ $transitions . onFinish ( { } , function ( $transition$ ) { log += 'finish:' + $transition$ . to ( ) . name + ';' ; } ) ;
591+ $transitions . onSuccess ( { } , function ( $transition$ ) { log += 'success:' + $transition$ . to ( ) . name + ';' ; } ) ;
602592
603- animation = $animate . queue . shift ( ) ;
604- expect ( animation ) . toBeUndefined ( ) ;
605-
606- $state . transitionTo ( aState ) ;
607- $q . flush ( ) ;
608- animation = $animate . queue . shift ( ) ;
609- expect ( animation ) . toBeUndefined ( ) ;
610- expect ( elem . text ( ) ) . toBe ( aState . template ) ;
611-
612- $state . transitionTo ( bState ) ;
593+ var content = 'Initial Content' ;
594+ elem . append ( $compile ( '<div><ui-view>' + content + '</ui-view></div>' ) ( scope ) ) ;
595+ $state . transitionTo ( 'n' ) ;
613596 $q . flush ( ) ;
614- animation = $animate . queue . shift ( ) ;
615- expect ( animation ) . toBeUndefined ( ) ;
616- expect ( elem . text ( ) ) . toBe ( bState . template ) ;
617- } ) ) ;
618597
619- describe ( '$destroy event' , function ( ) {
620- it ( 'is triggered after animation ends' , inject ( function ( $state , $q , $animate , $rootScope ) {
621- elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
598+ expect ( $state . current . name ) . toBe ( 'n' ) ;
599+ expect ( log ) . toBe ( 'start:n;finish:n;success:n;' ) ;
622600
623- $state . transitionTo ( 'm' ) ;
624- $q . flush ( ) ;
625- expect ( log ) . toBe ( 'ctrl(m);' ) ;
626- $state . transitionTo ( 'n' ) ;
627- $q . flush ( ) ;
601+ animateFlush ( $animate ) ;
602+ $q . flush ( ) ;
603+ expect ( log ) . toBe ( 'start:n;finish:n;success:n;animEnter;' ) ;
628604
629- expect ( log ) . toBe ( 'ctrl(m);ctrl(n); ') ;
630- animateFlush ( $animate ) ;
631- expect ( log ) . toBe ( 'ctrl(m);ctrl(n);$destroy(m); ' ) ;
632- } ) ) ;
605+ $state . transitionTo ( 'a ') ;
606+ $q . flush ( ) ;
607+ expect ( $state . current . name ) . toBe ( 'a ' ) ;
608+ expect ( log ) . toBe ( 'start:n;finish:n;success:n;animEnter;start:a;finish:a;destroy;success:a;' ) ;
633609
634- it ( 'is triggered before $stateChangeSuccess if noanimation is present' , inject ( function ( $state , $q , $animate , $rootScope ) {
635- elem . append ( $compile ( '<div><ui-view noanimation="true"></ui-view></div>' ) ( scope ) ) ;
610+ animateFlush ( $animate ) ;
611+ $q . flush ( ) ;
612+ expect ( log ) . toBe ( 'start:n;finish:n;success:n;animEnter;start:a;finish:a;destroy;success:a;animLeave;' ) ;
613+ } ) ) ;
636614
637- $state . transitionTo ( 'm' ) ;
638- $q . flush ( ) ;
639- expect ( log ) . toBe ( 'ctrl(m);' ) ;
640- $state . transitionTo ( 'n' ) ;
641- $q . flush ( ) ;
642- expect ( log ) . toBe ( 'ctrl(m);$destroy(m);ctrl(n);' ) ;
643- } ) ) ;
644- } ) ;
645615 } ) ;
646616} ) ;
647617
0 commit comments