@@ -8,6 +8,20 @@ describe("$animator", function() {
8
8
dealoc ( element ) ;
9
9
} ) ;
10
10
11
+ describe ( "enable / disable" , function ( ) {
12
+
13
+ it ( "should disable and enable the animations" , inject ( function ( $animator ) {
14
+ expect ( $animator . enabled ( ) ) . toBe ( true ) ;
15
+
16
+ expect ( $animator . enabled ( 0 ) ) . toBe ( false ) ;
17
+ expect ( $animator . enabled ( ) ) . toBe ( false ) ;
18
+
19
+ expect ( $animator . enabled ( 1 ) ) . toBe ( true ) ;
20
+ expect ( $animator . enabled ( ) ) . toBe ( true ) ;
21
+ } ) ) ;
22
+
23
+ } ) ;
24
+
11
25
describe ( "without animation" , function ( ) {
12
26
var window , animator ;
13
27
@@ -46,20 +60,27 @@ describe("$animator", function() {
46
60
expect ( element . text ( ) ) . toBe ( '21' ) ;
47
61
} ) ) ;
48
62
49
- it ( "should animate the show animation event" , inject ( function ( $animator , $compile , $rootScope ) {
63
+ it ( "should animate the show animation event" , inject ( function ( ) {
50
64
element . css ( 'display' , 'none' ) ;
51
65
expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
52
66
animator . show ( element ) ;
53
67
expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
54
68
} ) ) ;
55
69
56
- it ( "should animate the hide animation event" , inject ( function ( $animator , $compile , $rootScope ) {
70
+ it ( "should animate the hide animation event" , inject ( function ( ) {
57
71
element . css ( 'display' , 'block' ) ;
58
72
expect ( element . css ( 'display' ) ) . toBe ( 'block' ) ;
59
73
animator . hide ( element ) ;
60
74
expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
61
75
} ) ) ;
62
76
77
+ it ( "should still perform DOM operations even if animations are disabled" , inject ( function ( $animator ) {
78
+ $animator . enabled ( false ) ;
79
+ element . css ( 'display' , 'block' ) ;
80
+ expect ( element . css ( 'display' ) ) . toBe ( 'block' ) ;
81
+ animator . hide ( element ) ;
82
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
83
+ } ) ) ;
63
84
} ) ;
64
85
65
86
describe ( "with polyfill" , function ( ) {
@@ -206,6 +227,63 @@ describe("$animator", function() {
206
227
window . setTimeout . expect ( 1 ) . process ( ) ;
207
228
expect ( element . text ( ) ) . toBe ( 'memento' ) ;
208
229
} ) ) ;
230
+
231
+ it ( "should not run if animations are disabled" , inject ( function ( $animator , $rootScope ) {
232
+ $animator . enabled ( false ) ;
233
+
234
+ animator = $animator ( $rootScope , {
235
+ ngAnimate : '{show: \'setup-memo\'}'
236
+ } ) ;
237
+ element . text ( '123' ) ;
238
+ expect ( element . text ( ) ) . toBe ( '123' ) ;
239
+ animator . show ( element ) ;
240
+ expect ( element . text ( ) ) . toBe ( '123' ) ;
241
+
242
+ $animator . enabled ( true ) ;
243
+
244
+ animator . show ( element ) ;
245
+ window . setTimeout . expect ( 1 ) . process ( ) ;
246
+ expect ( element . text ( ) ) . toBe ( 'memento' ) ;
247
+ } ) ) ;
248
+ } ) ;
249
+
250
+ describe ( "with css3" , function ( ) {
251
+ var window , animator , prefix , vendorPrefix ;
252
+
253
+ beforeEach ( function ( ) {
254
+ module ( function ( $animationProvider , $provide ) {
255
+ $provide . value ( '$window' , window = angular . mock . createMockWindow ( ) ) ;
256
+ return function ( $sniffer ) {
257
+ vendorPrefix = '-' + $sniffer . vendorPrefix + '-' ;
258
+ } ;
259
+ } )
260
+ } ) ;
261
+
262
+ it ( "should skip animations if disabled and run when enabled" ,
263
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
264
+ $animator . enabled ( false ) ;
265
+ element = $compile ( '<div style="transition: 1s linear all">1</div>' ) ( $rootScope ) ;
266
+ var animator = $animator ( $rootScope , {
267
+ ngAnimate : '{show: \'inline-show\'}'
268
+ } ) ;
269
+
270
+ element . css ( 'display' , 'none' ) ;
271
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
272
+ animator . show ( element ) ;
273
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
274
+
275
+ $animator . enabled ( true ) ;
276
+
277
+ element . css ( 'display' , 'none' ) ;
278
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
279
+
280
+ animator . show ( element ) ;
281
+ if ( $sniffer . supportsTransitions ) {
282
+ window . setTimeout . expect ( 1 ) . process ( ) ;
283
+ window . setTimeout . expect ( 1000 ) . process ( ) ;
284
+ }
285
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
286
+ } ) ) ;
209
287
} ) ;
210
288
211
289
it ( "should throw an error when an invalid ng-animate syntax is provided" , inject ( function ( $compile , $rootScope ) {
0 commit comments