@@ -295,45 +295,200 @@ describe("$animator", function() {
295
295
} ) ) ;
296
296
} ) ;
297
297
298
- describe ( "with css3 " , function ( ) {
298
+ describe ( "with CSS3 " , function ( ) {
299
299
var window , animator , prefix , vendorPrefix ;
300
300
301
301
beforeEach ( function ( ) {
302
302
module ( function ( $animationProvider , $provide ) {
303
303
$provide . value ( '$window' , window = angular . mock . createMockWindow ( ) ) ;
304
304
return function ( $sniffer , _$rootElement_ , $animator ) {
305
- vendorPrefix = '-' + $sniffer . vendorPrefix + '-' ;
305
+ vendorPrefix = '-' + $sniffer . vendorPrefix . toLowerCase ( ) + '-' ;
306
306
$rootElement = _$rootElement_ ;
307
307
$animator . enabled ( true ) ;
308
308
} ;
309
309
} )
310
310
} ) ;
311
311
312
- it ( "should skip animations if disabled and run when enabled" ,
312
+ describe ( "Animations" , function ( ) {
313
+ it ( "should properly detect and make use of CSS Animations" ,
314
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
315
+ var style = 'animation: some_animation 4s linear 0s 1 alternate;' +
316
+ vendorPrefix + 'animation: some_animation 4s linear 0s 1 alternate;' ;
317
+ element = $compile ( html ( '<div style="' + style + '">1</div>' ) ) ( $rootScope ) ;
318
+ var animator = $animator ( $rootScope , {
319
+ ngAnimate : '{show: \'inline-show\'}'
320
+ } ) ;
321
+
322
+ element . css ( 'display' , 'none' ) ;
323
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
324
+
325
+ animator . show ( element ) ;
326
+ if ( $sniffer . supportsAnimations ) {
327
+ window . setTimeout . expect ( 1 ) . process ( ) ;
328
+ window . setTimeout . expect ( 4000 ) . process ( ) ;
329
+ }
330
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
331
+ } ) ) ;
332
+
333
+ it ( "should properly detect and make use of CSS Animations with multiple iterations" ,
334
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
335
+ var style = 'animation-duration: 2s;' +
336
+ 'animation-iteration-count: 3;' +
337
+ vendorPrefix + 'animation-duration: 2s;' +
338
+ vendorPrefix + 'animation-iteration-count: 3;' ;
339
+ element = $compile ( html ( '<div style="' + style + '">1</div>' ) ) ( $rootScope ) ;
340
+ var animator = $animator ( $rootScope , {
341
+ ngAnimate : '{show: \'inline-show\'}'
342
+ } ) ;
343
+
344
+ element . css ( 'display' , 'none' ) ;
345
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
346
+
347
+ animator . show ( element ) ;
348
+ if ( $sniffer . supportsAnimations ) {
349
+ window . setTimeout . expect ( 1 ) . process ( ) ;
350
+ window . setTimeout . expect ( 6000 ) . process ( ) ;
351
+ }
352
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
353
+ } ) ) ;
354
+
355
+ it ( "should fallback to the animation duration if an infinite iteration is provided" ,
356
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
357
+ var style = 'animation-duration: 2s;' +
358
+ 'animation-iteration-count: infinite;' +
359
+ vendorPrefix + 'animation-duration: 2s;' +
360
+ vendorPrefix + 'animation-iteration-count: infinite;' ;
361
+ element = $compile ( html ( '<div style="' + style + '">1</div>' ) ) ( $rootScope ) ;
362
+ var animator = $animator ( $rootScope , {
363
+ ngAnimate : '{show: \'inline-show\'}'
364
+ } ) ;
365
+
366
+ element . css ( 'display' , 'none' ) ;
367
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
368
+
369
+ animator . show ( element ) ;
370
+ if ( $sniffer . supportsAnimations ) {
371
+ window . setTimeout . expect ( 1 ) . process ( ) ;
372
+ window . setTimeout . expect ( 2000 ) . process ( ) ;
373
+ }
374
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
375
+ } ) ) ;
376
+
377
+ it ( "should consider the animation delay is provided" ,
378
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
379
+ var style = 'animation-duration: 2s;' +
380
+ 'animation-delay: 10s;' +
381
+ 'animation-iteration-count: 5;' +
382
+ vendorPrefix + 'animation-duration: 2s;' +
383
+ vendorPrefix + 'animation-delay: 10s;' +
384
+ vendorPrefix + 'animation-iteration-count: 5;' ;
385
+ element = $compile ( html ( '<div style="' + style + '">1</div>' ) ) ( $rootScope ) ;
386
+ var animator = $animator ( $rootScope , {
387
+ ngAnimate : '{show: \'inline-show\'}'
388
+ } ) ;
389
+
390
+ element . css ( 'display' , 'none' ) ;
391
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
392
+
393
+ animator . show ( element ) ;
394
+ if ( $sniffer . supportsTransitions ) {
395
+ window . setTimeout . expect ( 1 ) . process ( ) ;
396
+ window . setTimeout . expect ( 20000 ) . process ( ) ;
397
+ }
398
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
399
+ } ) ) ;
400
+
401
+ it ( "should skip animations if disabled and run when enabled" ,
402
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
403
+ $animator . enabled ( false ) ;
404
+ var style = 'animation: some_animation 2s linear 0s 1 alternate;' +
405
+ vendorPrefix + 'animation: some_animation 2s linear 0s 1 alternate;'
406
+
407
+ element = $compile ( html ( '<div style="' + style + '">1</div>' ) ) ( $rootScope ) ;
408
+ var animator = $animator ( $rootScope , {
409
+ ngAnimate : '{show: \'inline-show\'}'
410
+ } ) ;
411
+ element . css ( 'display' , 'none' ) ;
412
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
413
+ animator . show ( element ) ;
414
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
415
+ } ) ) ;
416
+ } ) ;
417
+
418
+ describe ( "Transitions" , function ( ) {
419
+ it ( "should skip transitions if disabled and run when enabled" ,
420
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
421
+ $animator . enabled ( false ) ;
422
+ element = $compile ( html ( '<div style="' + vendorPrefix + 'transition: 1s linear all">1</div>' ) ) ( $rootScope ) ;
423
+ var animator = $animator ( $rootScope , {
424
+ ngAnimate : '{show: \'inline-show\'}'
425
+ } ) ;
426
+
427
+ element . css ( 'display' , 'none' ) ;
428
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
429
+ animator . show ( element ) ;
430
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
431
+
432
+ $animator . enabled ( true ) ;
433
+
434
+ element . css ( 'display' , 'none' ) ;
435
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
436
+
437
+ animator . show ( element ) ;
438
+ if ( $sniffer . supportsTransitions ) {
439
+ window . setTimeout . expect ( 1 ) . process ( ) ;
440
+ window . setTimeout . expect ( 1000 ) . process ( ) ;
441
+ }
442
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
443
+ } ) ) ;
444
+
445
+ it ( "should skip animations if disabled and run when enabled picking the longest specified duration" ,
313
446
inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
314
- $animator . enabled ( false ) ;
315
- element = $compile ( html ( '<div style="' + vendorPrefix + 'transition: 1s linear all">1</div>' ) ) ( $rootScope ) ;
316
- var animator = $animator ( $rootScope , {
317
- ngAnimate : '{show: \'inline-show\'}'
318
- } ) ;
447
+ $animator . enabled ( true ) ;
448
+ element = $compile ( html ( '<div style="' + vendorPrefix + 'transition-duration: 1s, 2000ms, 1s; ' + vendorPrefix + 'transition-property: height, left, opacity">foo</div>' ) ) ( $rootScope ) ;
449
+ var animator = $animator ( $rootScope , {
450
+ ngAnimate : '{show: \'inline-show\'}'
451
+ } ) ;
452
+ element . css ( 'display' , 'none' ) ;
453
+ animator . show ( element ) ;
454
+ if ( $sniffer . supportsTransitions ) {
455
+ window . setTimeout . expect ( 1 ) . process ( ) ;
456
+ window . setTimeout . expect ( 2000 ) . process ( ) ;
457
+ }
458
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
459
+ } ) ) ;
319
460
320
- element . css ( 'display' , 'none' ) ;
321
- expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
322
- animator . show ( element ) ;
323
- expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
461
+ it ( "should skip animations if disabled and run when enabled picking the longest specified duration/delay combination" ,
462
+ inject ( function ( $animator , $rootScope , $compile , $sniffer ) {
463
+ $animator . enabled ( false ) ;
464
+ element = $compile ( html ( '<div style="' + vendorPrefix +
465
+ 'transition-duration: 1s, 0s, 1s; ' + vendorPrefix +
466
+ 'transition-delay: 2s, 1000ms, 2s; ' + vendorPrefix +
467
+ 'transition-property: height, left, opacity">foo</div>' ) ) ( $rootScope ) ;
324
468
325
- $animator . enabled ( true ) ;
469
+ var animator = $animator ( $rootScope , {
470
+ ngAnimate : '{show: \'inline-show\'}'
471
+ } ) ;
326
472
327
- element . css ( 'display' , 'none' ) ;
328
- expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
473
+ element . css ( 'display' , 'none' ) ;
474
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
475
+ animator . show ( element ) ;
476
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
329
477
330
- animator . show ( element ) ;
331
- if ( $sniffer . transitions ) {
332
- window . setTimeout . expect ( 1 ) . process ( ) ;
333
- window . setTimeout . expect ( 1000 ) . process ( ) ;
334
- }
335
- expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
336
- } ) ) ;
478
+ $animator . enabled ( true ) ;
479
+
480
+ element . css ( 'display' , 'none' ) ;
481
+ expect ( element . css ( 'display' ) ) . toBe ( 'none' ) ;
482
+
483
+ animator . show ( element ) ;
484
+ if ( $sniffer . transitions ) {
485
+ window . setTimeout . expect ( 1 ) . process ( ) ;
486
+ window . setTimeout . expect ( 3000 ) . process ( ) ;
487
+ return ;
488
+ }
489
+ expect ( element [ 0 ] . style . display ) . toBe ( '' ) ;
490
+ } ) ) ;
491
+ } ) ;
337
492
} ) ;
338
493
339
494
describe ( 'anmation evaluation' , function ( ) {
0 commit comments