@@ -15,7 +15,11 @@ describe('uiView', function () {
15
15
16
16
var scope , $compile , elem ;
17
17
18
- beforeEach ( module ( 'ui.router' ) ) ;
18
+ beforeEach ( function ( ) {
19
+ angular . module ( 'ui.router.test' , [ 'ui.router' , 'ngAnimate' ] ) ;
20
+ module ( 'ui.router.test' ) ;
21
+ module ( 'mock.animate' ) ;
22
+ } ) ;
19
23
20
24
beforeEach ( module ( function ( $provide ) {
21
25
$provide . decorator ( '$uiViewScroll' , function ( $delegate ) {
@@ -96,60 +100,72 @@ describe('uiView', function () {
96
100
} ) ) ;
97
101
98
102
describe ( 'linking ui-directive' , function ( ) {
99
- it ( 'anonymous ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q ) {
103
+ it ( 'anonymous ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q , $animate ) {
100
104
elem . append ( $compile ( '<div ui-view></div>' ) ( scope ) ) ;
101
105
102
106
$state . transitionTo ( aState ) ;
103
107
$q . flush ( ) ;
104
108
105
- expect ( elem . text ( ) ) . toBe ( aState . template ) ;
109
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( '' ) ;
110
+ expect ( $animate . flushNext ( 'enter' ) . element . text ( ) ) . toBe ( aState . template ) ;
106
111
} ) ) ;
107
112
108
- it ( 'named ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q ) {
113
+ it ( 'named ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q , $animate ) {
109
114
elem . append ( $compile ( '<div ui-view="cview"></div>' ) ( scope ) ) ;
110
115
111
116
$state . transitionTo ( cState ) ;
112
117
$q . flush ( ) ;
113
118
114
- expect ( elem . text ( ) ) . toBe ( cState . views . cview . template ) ;
119
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( '' ) ;
120
+ expect ( $animate . flushNext ( 'enter' ) . element . text ( ) ) . toBe ( cState . views . cview . template ) ;
115
121
} ) ) ;
116
122
117
- it ( 'ui-view should be updated after transition to another state' , inject ( function ( $state , $q ) {
123
+ it ( 'ui-view should be updated after transition to another state' , inject ( function ( $state , $q , $animate ) {
118
124
elem . append ( $compile ( '<div ui-view></div>' ) ( scope ) ) ;
119
125
120
126
$state . transitionTo ( aState ) ;
121
127
$q . flush ( ) ;
122
128
123
- expect ( elem . text ( ) ) . toBe ( aState . template ) ;
129
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( '' ) ;
130
+ expect ( $animate . flushNext ( 'enter' ) . element . text ( ) ) . toBe ( aState . template ) ;
124
131
125
132
$state . transitionTo ( bState ) ;
126
133
$q . flush ( ) ;
127
134
128
- expect ( elem . text ( ) ) . toBe ( bState . template ) ;
135
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( aState . template ) ;
136
+ expect ( $animate . flushNext ( 'enter' ) . element . text ( ) ) . toBe ( bState . template ) ;
129
137
} ) ) ;
130
138
131
- it ( 'should handle NOT nested ui-views' , inject ( function ( $state , $q ) {
139
+ it ( 'should handle NOT nested ui-views' , inject ( function ( $state , $q , $animate ) {
132
140
elem . append ( $compile ( '<div ui-view="dview1" class="dview1"></div><div ui-view="dview2" class="dview2"></div>' ) ( scope ) ) ;
133
141
134
142
$state . transitionTo ( dState ) ;
135
143
$q . flush ( ) ;
136
144
137
- expect ( innerText ( elem [ 0 ] . querySelector ( '.dview1' ) ) ) . toBe ( dState . views . dview1 . template ) ;
138
- expect ( innerText ( elem [ 0 ] . querySelector ( '.dview2' ) ) ) . toBe ( dState . views . dview2 . template ) ;
145
+ // expect(innerText(elem[0].querySelector('.dview1'))).toBe(dState.views.dview1.template);
146
+ // expect(innerText(elem[0].querySelector('.dview2'))).toBe(dState.views.dview2.template);
147
+
148
+ expect ( $animate . flushNext ( 'leave' ) . element . html ( ) ) . toBeUndefined ( ) ;
149
+ expect ( $animate . flushNext ( 'enter' ) . element . html ( ) ) . toBe ( dState . views . dview1 . template ) ;
150
+ expect ( $animate . flushNext ( 'leave' ) . element . html ( ) ) . toBeUndefined ( ) ;
151
+ expect ( $animate . flushNext ( 'enter' ) . element . html ( ) ) . toBe ( dState . views . dview2 . template ) ;
139
152
} ) ) ;
140
153
141
- it ( 'should handle nested ui-views (testing two levels deep)' , inject ( function ( $state , $q ) {
154
+ it ( 'should handle nested ui-views (testing two levels deep)' , inject ( function ( $state , $q , $animate ) {
142
155
elem . append ( $compile ( '<div ui-view class="view"></div>' ) ( scope ) ) ;
143
156
144
157
$state . transitionTo ( fState ) ;
145
158
$q . flush ( ) ;
146
159
147
- expect ( innerText ( elem [ 0 ] . querySelector ( '.view' ) . querySelector ( '.eview' ) ) ) . toBe ( fState . views . eview . template ) ;
160
+ // expect(innerText(elem[0].querySelector('.view').querySelector('.eview'))).toBe(fState.views.eview.template);
161
+
162
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( '' ) ;
163
+ expect ( $animate . flushNext ( 'enter' ) . element . parent ( ) . parent ( ) [ 0 ] . querySelector ( '.view' ) . querySelector ( '.eview' ) . innerText ) . toBe ( fState . views . eview . template ) ;
148
164
} ) ) ;
149
165
} ) ;
150
166
151
167
describe ( 'handling initial view' , function ( ) {
152
- it ( 'initial view should be compiled if the view is empty' , inject ( function ( $state , $q ) {
168
+ it ( 'initial view should be compiled if the view is empty' , inject ( function ( $state , $q , $animate ) {
153
169
var content = 'inner content' ;
154
170
155
171
elem . append ( $compile ( '<div ui-view></div>' ) ( scope ) ) ;
@@ -158,10 +174,16 @@ describe('uiView', function () {
158
174
$state . transitionTo ( gState ) ;
159
175
$q . flush ( ) ;
160
176
161
- expect ( innerText ( elem [ 0 ] . querySelector ( '.test' ) ) ) . toBe ( content ) ;
177
+ // expect(innerText(elem[0].querySelector('.test'))).toBe(content);
178
+
179
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( "" ) ;
180
+ expect ( $animate . flushNext ( 'enter' ) . element . text ( ) ) . toBe ( content ) ;
181
+
182
+ // For some reason the ng-class expression is no longer evaluated
183
+ expect ( $animate . flushNext ( 'addClass' ) . element . parent ( ) [ 0 ] . querySelector ( '.test' ) . innerText ) . toBe ( content ) ;
162
184
} ) ) ;
163
185
164
- it ( 'initial view should be put back after removal of the view' , inject ( function ( $state , $q ) {
186
+ it ( 'initial view should be put back after removal of the view' , inject ( function ( $state , $q , $animate ) {
165
187
var content = 'inner content' ;
166
188
167
189
elem . append ( $compile ( '<div ui-view></div>' ) ( scope ) ) ;
@@ -170,13 +192,20 @@ describe('uiView', function () {
170
192
$state . transitionTo ( hState ) ;
171
193
$q . flush ( ) ;
172
194
173
- expect ( elem . text ( ) ) . toBe ( hState . views . inner . template ) ;
195
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( '' ) ;
196
+ expect ( $animate . flushNext ( 'enter' ) . element . text ( ) ) . toBe ( hState . views . inner . template ) ;
197
+
198
+ expect ( $animate . flushNext ( 'addClass' ) . element . text ( ) ) . toBe ( hState . views . inner . template ) ;
199
+ expect ( $animate . flushNext ( 'addClass' ) . element . text ( ) ) . toBe ( hState . views . inner . template ) ;
174
200
175
201
// going to the parent state which makes the inner view empty
176
202
$state . transitionTo ( gState ) ;
177
203
$q . flush ( ) ;
178
204
179
- expect ( innerText ( elem [ 0 ] . querySelector ( '.test' ) ) ) . toBe ( content ) ;
205
+ // expect(innerText(elem[0].querySelector('.test'))).toBe(content);
206
+
207
+ expect ( $animate . flushNext ( 'leave' ) . element . text ( ) ) . toBe ( hState . views . inner . template ) ;
208
+ expect ( $animate . flushNext ( 'enter' ) . element . text ( ) ) . toBe ( content ) ;
180
209
} ) ) ;
181
210
182
211
// related to issue #435
0 commit comments