@@ -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 scope , $compile , elem ;
12+ var scope , $compile , elem , log ;
1813
1914 beforeEach ( function ( ) {
2015 var depends = [ 'ui.router' ] ;
16+ log = "" ;
2117
2218 try {
2319 angular . module ( 'ngAnimate' ) ;
@@ -113,6 +109,15 @@ describe('uiView', function () {
113109 controller : function ( $scope , $element ) {
114110 $scope . elementId = $element . attr ( 'id' ) ;
115111 }
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+ }
116121 } ;
117122
118123 beforeEach ( module ( function ( $stateProvider ) {
@@ -130,6 +135,7 @@ describe('uiView', function () {
130135 . state ( 'k' , kState )
131136 . state ( 'l' , lState )
132137 . state ( 'm' , mState )
138+ . state ( 'n' , nState )
133139 } ) ) ;
134140
135141 beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -578,6 +584,34 @@ describe('uiView', function () {
578584 // No more animations
579585 expect ( $animate . queue . length ) . toBe ( 0 ) ;
580586 } ) ) ;
587+
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 + ';' ; } ) ;
592+
593+ var content = 'Initial Content' ;
594+ elem . append ( $compile ( '<div><ui-view>' + content + '</ui-view></div>' ) ( scope ) ) ;
595+ $state . transitionTo ( 'n' ) ;
596+ $q . flush ( ) ;
597+
598+ expect ( $state . current . name ) . toBe ( 'n' ) ;
599+ expect ( log ) . toBe ( 'start:n;finish:n;success:n;' ) ;
600+
601+ animateFlush ( $animate ) ;
602+ $q . flush ( ) ;
603+ expect ( log ) . toBe ( 'start:n;finish:n;success:n;animEnter;' ) ;
604+
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;' ) ;
609+
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+ } ) ) ;
614+
581615 } ) ;
582616} ) ;
583617
0 commit comments