@@ -6,18 +6,14 @@ function animateFlush($animate) {
6
6
$animate && $animate . flush && $animate . flush ( ) ; // 1.4
7
7
}
8
8
9
- function animateFlush ( $animate ) {
10
- $animate && $animate . triggerCallbacks && $animate . triggerCallbacks ( ) ; // 1.2-1.3
11
- $animate && $animate . flush && $animate . flush ( ) ; // 1.4
12
- }
13
-
14
9
describe ( 'uiView' , function ( ) {
15
10
'use strict' ;
16
11
17
- var scope , $compile , elem ;
12
+ var scope , $compile , elem , log ;
18
13
19
14
beforeEach ( function ( ) {
20
15
var depends = [ 'ui.router' ] ;
16
+ log = "" ;
21
17
22
18
try {
23
19
angular . module ( 'ngAnimate' ) ;
@@ -113,6 +109,15 @@ describe('uiView', function () {
113
109
controller : function ( $scope , $element ) {
114
110
$scope . elementId = $element . attr ( 'id' ) ;
115
111
}
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
+ }
116
121
} ;
117
122
118
123
beforeEach ( module ( function ( $stateProvider ) {
@@ -130,6 +135,7 @@ describe('uiView', function () {
130
135
. state ( 'k' , kState )
131
136
. state ( 'l' , lState )
132
137
. state ( 'm' , mState )
138
+ . state ( 'n' , nState )
133
139
} ) ) ;
134
140
135
141
beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -578,6 +584,34 @@ describe('uiView', function () {
578
584
// No more animations
579
585
expect ( $animate . queue . length ) . toBe ( 0 ) ;
580
586
} ) ) ;
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
+
581
615
} ) ;
582
616
} ) ;
583
617
0 commit comments