@@ -290,6 +290,24 @@ describe("ngAnimate", function() {
290
290
expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
291
291
} ) ) ;
292
292
293
+ it ( "should animate the enter animation event with native dom elements" ,
294
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
295
+ element [ 0 ] . removeChild ( child [ 0 ] ) ;
296
+
297
+ expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
298
+ $animate . enter ( child [ 0 ] , element [ 0 ] ) ;
299
+ $rootScope . $digest ( ) ;
300
+
301
+ if ( $sniffer . transitions ) {
302
+ $animate . triggerReflow ( ) ;
303
+ expect ( child . hasClass ( 'ng-enter' ) ) . toBe ( true ) ;
304
+ expect ( child . hasClass ( 'ng-enter-active' ) ) . toBe ( true ) ;
305
+ browserTrigger ( element , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1 } ) ;
306
+ }
307
+
308
+ expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
309
+ } ) ) ;
310
+
293
311
294
312
it ( "should animate the leave animation event" ,
295
313
inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
@@ -308,6 +326,22 @@ describe("ngAnimate", function() {
308
326
expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
309
327
} ) ) ;
310
328
329
+ it ( "should animate the leave animation event with native dom elements" ,
330
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
331
+
332
+ expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
333
+ $animate . leave ( child [ 0 ] ) ;
334
+ $rootScope . $digest ( ) ;
335
+
336
+ if ( $sniffer . transitions ) {
337
+ $animate . triggerReflow ( ) ;
338
+ expect ( child . hasClass ( 'ng-leave' ) ) . toBe ( true ) ;
339
+ expect ( child . hasClass ( 'ng-leave-active' ) ) . toBe ( true ) ;
340
+ browserTrigger ( child , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1 } ) ;
341
+ }
342
+
343
+ expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
344
+ } ) ) ;
311
345
312
346
it ( "should animate the move animation event" ,
313
347
inject ( function ( $animate , $compile , $rootScope , $timeout , $sniffer ) {
@@ -328,6 +362,24 @@ describe("ngAnimate", function() {
328
362
expect ( element . text ( ) ) . toBe ( '21' ) ;
329
363
} ) ) ;
330
364
365
+ it ( "should animate the move animation event with native dom elements" ,
366
+ inject ( function ( $animate , $compile , $rootScope , $timeout , $sniffer ) {
367
+
368
+ $rootScope . $digest ( ) ;
369
+ element . empty ( ) ;
370
+
371
+ var child1 = $compile ( '<div>1</div>' ) ( $rootScope ) ;
372
+ var child2 = $compile ( '<div>2</div>' ) ( $rootScope ) ;
373
+ element . append ( child1 ) ;
374
+ element . append ( child2 ) ;
375
+ expect ( element . text ( ) ) . toBe ( '12' ) ;
376
+ $animate . move ( child1 [ 0 ] , element [ 0 ] , child2 [ 0 ] ) ;
377
+ $rootScope . $digest ( ) ;
378
+ if ( $sniffer . transitions ) {
379
+ $animate . triggerReflow ( ) ;
380
+ }
381
+ expect ( element . text ( ) ) . toBe ( '21' ) ;
382
+ } ) ) ;
331
383
332
384
it ( "should animate the show animation event" ,
333
385
inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
@@ -347,7 +399,6 @@ describe("ngAnimate", function() {
347
399
expect ( child ) . toBeShown ( ) ;
348
400
} ) ) ;
349
401
350
-
351
402
it ( "should animate the hide animation event" ,
352
403
inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
353
404
@@ -401,6 +452,43 @@ describe("ngAnimate", function() {
401
452
} ) ;
402
453
} ) ;
403
454
455
+ it ( "should exclusively animate the setClass animation event with native dom elements" , function ( ) {
456
+ var count = 0 , fallback = jasmine . createSpy ( 'callback' ) ;
457
+ module ( function ( $animateProvider ) {
458
+ $animateProvider . register ( '.classify' , function ( ) {
459
+ return {
460
+ beforeAddClass : fallback ,
461
+ addClass : fallback ,
462
+ beforeRemoveClass : fallback ,
463
+ removeClass : fallback ,
464
+
465
+ beforeSetClass : function ( element , add , remove , done ) {
466
+ count ++ ;
467
+ expect ( add ) . toBe ( 'yes' ) ;
468
+ expect ( remove ) . toBe ( 'no' ) ;
469
+ done ( ) ;
470
+ } ,
471
+ setClass : function ( element , add , remove , done ) {
472
+ count ++ ;
473
+ expect ( add ) . toBe ( 'yes' ) ;
474
+ expect ( remove ) . toBe ( 'no' ) ;
475
+ done ( ) ;
476
+ }
477
+ } ;
478
+ } ) ;
479
+ } ) ;
480
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
481
+ child . attr ( 'class' , 'classify no' ) ;
482
+ $animate . setClass ( child [ 0 ] , 'yes' , 'no' ) ;
483
+ $animate . triggerReflow ( ) ;
484
+
485
+ expect ( child . hasClass ( 'yes' ) ) . toBe ( true ) ;
486
+ expect ( child . hasClass ( 'no' ) ) . toBe ( false ) ;
487
+ expect ( count ) . toBe ( 2 ) ;
488
+
489
+ expect ( fallback ) . not . toHaveBeenCalled ( ) ;
490
+ } ) ;
491
+ } ) ;
404
492
405
493
it ( "should delegate down to addClass/removeClass if a setClass animation is not found" , function ( ) {
406
494
var count = 0 ;
@@ -2003,6 +2091,39 @@ describe("ngAnimate", function() {
2003
2091
expect ( captured ) . toBe ( 'addClass-some-class' ) ;
2004
2092
} ) ) ;
2005
2093
2094
+ it ( "should perform the animation if passed native dom element" ,
2095
+ inject ( function ( $animate , $rootScope , $sniffer , $rootElement , $timeout , $browser ) {
2096
+
2097
+ var element = jqLite ( '<div class="klassy"></div>' ) ;
2098
+ $rootElement . append ( element ) ;
2099
+ body . append ( $rootElement ) ;
2100
+
2101
+ //skipped animations
2102
+ captured = 'none' ;
2103
+ $animate . removeClass ( element [ 0 ] , 'some-class' ) ;
2104
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( false ) ;
2105
+ expect ( captured ) . toBe ( 'none' ) ;
2106
+
2107
+ element . addClass ( 'some-class' ) ;
2108
+
2109
+ captured = 'nothing' ;
2110
+ $animate . addClass ( element [ 0 ] , 'some-class' ) ;
2111
+ expect ( captured ) . toBe ( 'nothing' ) ;
2112
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( true ) ;
2113
+
2114
+ //actual animations
2115
+ captured = 'none' ;
2116
+ $animate . removeClass ( element [ 0 ] , 'some-class' ) ;
2117
+ $animate . triggerReflow ( ) ;
2118
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( false ) ;
2119
+ expect ( captured ) . toBe ( 'removeClass-some-class' ) ;
2120
+
2121
+ captured = 'nothing' ;
2122
+ $animate . addClass ( element [ 0 ] , 'some-class' ) ;
2123
+ $animate . triggerReflow ( ) ;
2124
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( true ) ;
2125
+ expect ( captured ) . toBe ( 'addClass-some-class' ) ;
2126
+ } ) ) ;
2006
2127
2007
2128
it ( "should add and remove CSS classes after an animation even if no animation is present" ,
2008
2129
inject ( function ( $animate , $rootScope , $sniffer , $rootElement ) {
@@ -2132,6 +2253,37 @@ describe("ngAnimate", function() {
2132
2253
expect ( signature ) . toBe ( 'XY' ) ;
2133
2254
} ) ) ;
2134
2255
2256
+ it ( "should properly execute JS animations if passed native dom element" ,
2257
+ inject ( function ( $animate , $rootScope , $sniffer , $rootElement , $timeout ) {
2258
+
2259
+ var parent = jqLite ( '<div><span></span></div>' ) ;
2260
+ $rootElement . append ( parent ) ;
2261
+ body . append ( $rootElement ) ;
2262
+ var element = jqLite ( parent . find ( 'span' ) ) ;
2263
+
2264
+ var signature = '' ;
2265
+
2266
+ $animate . addClass ( element [ 0 ] , 'klassy' , function ( ) {
2267
+ signature += 'X' ;
2268
+ } ) ;
2269
+ $animate . triggerReflow ( ) ;
2270
+
2271
+ $timeout . flush ( 500 ) ;
2272
+
2273
+ expect ( element . hasClass ( 'klassy' ) ) . toBe ( true ) ;
2274
+
2275
+ $animate . removeClass ( element [ 0 ] , 'klassy' , function ( ) {
2276
+ signature += 'Y' ;
2277
+ } ) ;
2278
+ $animate . triggerReflow ( ) ;
2279
+
2280
+ $timeout . flush ( 3000 ) ;
2281
+
2282
+ expect ( element . hasClass ( 'klassy' ) ) . toBe ( false ) ;
2283
+
2284
+ $animate . triggerCallbacks ( ) ;
2285
+ expect ( signature ) . toBe ( 'XY' ) ;
2286
+ } ) ) ;
2135
2287
2136
2288
it ( "should properly execute CSS animations/transitions and use callbacks when using addClass / removeClass" ,
2137
2289
inject ( function ( $animate , $rootScope , $sniffer , $rootElement , $timeout ) {
0 commit comments