@@ -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 log , scope , $compile , elem ;
12
+ var scope , $compile , elem , log ;
18
13
19
14
beforeEach ( function ( ) {
20
- var depends = [ 'ui.router' , 'ui.router.state.events' ] ;
15
+ var depends = [ 'ui.router' ] ;
16
+ log = "" ;
21
17
22
18
try {
23
19
angular . module ( 'ngAnimate' ) ;
@@ -31,17 +27,12 @@ describe('uiView', function () {
31
27
module ( 'ui.router.test' ) ;
32
28
} ) ;
33
29
34
- beforeEach ( module ( function ( $provide , $stateEventsProvider ) {
35
- $stateEventsProvider . enable ( ) ;
30
+ beforeEach ( module ( function ( $provide ) {
36
31
$provide . decorator ( '$uiViewScroll' , function ( ) {
37
32
return jasmine . createSpy ( '$uiViewScroll' ) ;
38
33
} ) ;
39
34
} ) ) ;
40
35
41
- beforeEach ( function ( ) {
42
- log = '' ;
43
- } ) ;
44
-
45
36
var aState = {
46
37
template : 'aState template'
47
38
} ,
@@ -113,12 +104,20 @@ describe('uiView', function () {
113
104
}
114
105
}
115
106
} ,
116
-
117
- oState = {
118
- template : 'oState' ,
107
+ mState = {
108
+ template : 'mState' ,
119
109
controller : function ( $scope , $element ) {
120
110
$scope . elementId = $element . attr ( 'id' ) ;
121
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
+ }
122
121
} ;
123
122
124
123
beforeEach ( module ( function ( $stateProvider ) {
@@ -135,18 +134,8 @@ describe('uiView', function () {
135
134
. state ( 'j' , jState )
136
135
. state ( 'k' , kState )
137
136
. 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 )
150
139
} ) ) ;
151
140
152
141
beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -342,11 +331,11 @@ describe('uiView', function () {
342
331
} ) ) ;
343
332
344
333
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 ) ;
347
336
$q . flush ( ) ;
348
337
349
- expect ( elem . text ( ) ) . toBe ( 'oState ' ) ;
338
+ expect ( elem . text ( ) ) . toBe ( 'mState ' ) ;
350
339
} ) ) ;
351
340
352
341
describe ( 'play nicely with other directives' , function ( ) {
@@ -596,52 +585,33 @@ describe('uiView', function () {
596
585
expect ( $animate . queue . length ) . toBe ( 0 ) ;
597
586
} ) ) ;
598
587
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 + ';' ; } ) ;
602
592
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' ) ;
613
596
$q . flush ( ) ;
614
- animation = $animate . queue . shift ( ) ;
615
- expect ( animation ) . toBeUndefined ( ) ;
616
- expect ( elem . text ( ) ) . toBe ( bState . template ) ;
617
- } ) ) ;
618
597
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;' ) ;
622
600
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;' ) ;
628
604
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;' ) ;
633
609
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
+ } ) ) ;
636
614
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
- } ) ;
645
615
} ) ;
646
616
} ) ;
647
617
0 commit comments