@@ -297,6 +297,24 @@ describe("ngAnimate", function() {
297
297
expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
298
298
} ) ) ;
299
299
300
+ it ( "should animate the enter animation event with native dom elements" ,
301
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
302
+ element [ 0 ] . removeChild ( child [ 0 ] ) ;
303
+
304
+ expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
305
+ $animate . enter ( child [ 0 ] , element [ 0 ] ) ;
306
+ $rootScope . $digest ( ) ;
307
+
308
+ if ( $sniffer . transitions ) {
309
+ $animate . triggerReflow ( ) ;
310
+ expect ( child . hasClass ( 'ng-enter' ) ) . toBe ( true ) ;
311
+ expect ( child . hasClass ( 'ng-enter-active' ) ) . toBe ( true ) ;
312
+ browserTrigger ( element , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1 } ) ;
313
+ }
314
+
315
+ expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
316
+ } ) ) ;
317
+
300
318
301
319
it ( "should animate the leave animation event" ,
302
320
inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
@@ -315,6 +333,22 @@ describe("ngAnimate", function() {
315
333
expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
316
334
} ) ) ;
317
335
336
+ it ( "should animate the leave animation event with native dom elements" ,
337
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
338
+
339
+ expect ( element . contents ( ) . length ) . toBe ( 1 ) ;
340
+ $animate . leave ( child [ 0 ] ) ;
341
+ $rootScope . $digest ( ) ;
342
+
343
+ if ( $sniffer . transitions ) {
344
+ $animate . triggerReflow ( ) ;
345
+ expect ( child . hasClass ( 'ng-leave' ) ) . toBe ( true ) ;
346
+ expect ( child . hasClass ( 'ng-leave-active' ) ) . toBe ( true ) ;
347
+ browserTrigger ( child , 'transitionend' , { timeStamp : Date . now ( ) + 1000 , elapsedTime : 1 } ) ;
348
+ }
349
+
350
+ expect ( element . contents ( ) . length ) . toBe ( 0 ) ;
351
+ } ) ) ;
318
352
319
353
it ( "should animate the move animation event" ,
320
354
inject ( function ( $animate , $compile , $rootScope , $timeout , $sniffer ) {
@@ -335,6 +369,24 @@ describe("ngAnimate", function() {
335
369
expect ( element . text ( ) ) . toBe ( '21' ) ;
336
370
} ) ) ;
337
371
372
+ it ( "should animate the move animation event with native dom elements" ,
373
+ inject ( function ( $animate , $compile , $rootScope , $timeout , $sniffer ) {
374
+
375
+ $rootScope . $digest ( ) ;
376
+ element . empty ( ) ;
377
+
378
+ var child1 = $compile ( '<div>1</div>' ) ( $rootScope ) ;
379
+ var child2 = $compile ( '<div>2</div>' ) ( $rootScope ) ;
380
+ element . append ( child1 ) ;
381
+ element . append ( child2 ) ;
382
+ expect ( element . text ( ) ) . toBe ( '12' ) ;
383
+ $animate . move ( child1 [ 0 ] , element [ 0 ] , child2 [ 0 ] ) ;
384
+ $rootScope . $digest ( ) ;
385
+ if ( $sniffer . transitions ) {
386
+ $animate . triggerReflow ( ) ;
387
+ }
388
+ expect ( element . text ( ) ) . toBe ( '21' ) ;
389
+ } ) ) ;
338
390
339
391
it ( "should animate the show animation event" ,
340
392
inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
@@ -354,7 +406,6 @@ describe("ngAnimate", function() {
354
406
expect ( child ) . toBeShown ( ) ;
355
407
} ) ) ;
356
408
357
-
358
409
it ( "should animate the hide animation event" ,
359
410
inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
360
411
@@ -409,6 +460,43 @@ describe("ngAnimate", function() {
409
460
} ) ;
410
461
} ) ;
411
462
463
+ it ( "should exclusively animate the setClass animation event with native dom elements" , function ( ) {
464
+ var count = 0 , fallback = jasmine . createSpy ( 'callback' ) ;
465
+ module ( function ( $animateProvider ) {
466
+ $animateProvider . register ( '.classify' , function ( ) {
467
+ return {
468
+ beforeAddClass : fallback ,
469
+ addClass : fallback ,
470
+ beforeRemoveClass : fallback ,
471
+ removeClass : fallback ,
472
+
473
+ beforeSetClass : function ( element , add , remove , done ) {
474
+ count ++ ;
475
+ expect ( add ) . toBe ( 'yes' ) ;
476
+ expect ( remove ) . toBe ( 'no' ) ;
477
+ done ( ) ;
478
+ } ,
479
+ setClass : function ( element , add , remove , done ) {
480
+ count ++ ;
481
+ expect ( add ) . toBe ( 'yes' ) ;
482
+ expect ( remove ) . toBe ( 'no' ) ;
483
+ done ( ) ;
484
+ }
485
+ } ;
486
+ } ) ;
487
+ } ) ;
488
+ inject ( function ( $animate , $rootScope , $sniffer , $timeout ) {
489
+ child . attr ( 'class' , 'classify no' ) ;
490
+ $animate . setClass ( child [ 0 ] , 'yes' , 'no' ) ;
491
+ $animate . triggerReflow ( ) ;
492
+
493
+ expect ( child . hasClass ( 'yes' ) ) . toBe ( true ) ;
494
+ expect ( child . hasClass ( 'no' ) ) . toBe ( false ) ;
495
+ expect ( count ) . toBe ( 2 ) ;
496
+
497
+ expect ( fallback ) . not . toHaveBeenCalled ( ) ;
498
+ } ) ;
499
+ } ) ;
412
500
413
501
it ( "should delegate down to addClass/removeClass if a setClass animation is not found" , function ( ) {
414
502
var count = 0 ;
@@ -2069,6 +2157,39 @@ describe("ngAnimate", function() {
2069
2157
expect ( captured ) . toBe ( 'addClass-some-class' ) ;
2070
2158
} ) ) ;
2071
2159
2160
+ it ( "should perform the animation if passed native dom element" ,
2161
+ inject ( function ( $animate , $rootScope , $sniffer , $rootElement , $timeout , $browser ) {
2162
+
2163
+ var element = jqLite ( '<div class="klassy"></div>' ) ;
2164
+ $rootElement . append ( element ) ;
2165
+ body . append ( $rootElement ) ;
2166
+
2167
+ //skipped animations
2168
+ captured = 'none' ;
2169
+ $animate . removeClass ( element [ 0 ] , 'some-class' ) ;
2170
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( false ) ;
2171
+ expect ( captured ) . toBe ( 'none' ) ;
2172
+
2173
+ element . addClass ( 'some-class' ) ;
2174
+
2175
+ captured = 'nothing' ;
2176
+ $animate . addClass ( element [ 0 ] , 'some-class' ) ;
2177
+ expect ( captured ) . toBe ( 'nothing' ) ;
2178
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( true ) ;
2179
+
2180
+ //actual animations
2181
+ captured = 'none' ;
2182
+ $animate . removeClass ( element [ 0 ] , 'some-class' ) ;
2183
+ $animate . triggerReflow ( ) ;
2184
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( false ) ;
2185
+ expect ( captured ) . toBe ( 'removeClass-some-class' ) ;
2186
+
2187
+ captured = 'nothing' ;
2188
+ $animate . addClass ( element [ 0 ] , 'some-class' ) ;
2189
+ $animate . triggerReflow ( ) ;
2190
+ expect ( element . hasClass ( 'some-class' ) ) . toBe ( true ) ;
2191
+ expect ( captured ) . toBe ( 'addClass-some-class' ) ;
2192
+ } ) ) ;
2072
2193
2073
2194
it ( "should add and remove CSS classes after an animation even if no animation is present" ,
2074
2195
inject ( function ( $animate , $rootScope , $sniffer , $rootElement ) {
@@ -2204,6 +2325,37 @@ describe("ngAnimate", function() {
2204
2325
expect ( signature ) . toBe ( 'XY' ) ;
2205
2326
} ) ) ;
2206
2327
2328
+ it ( "should properly execute JS animations if passed native dom element" ,
2329
+ inject ( function ( $animate , $rootScope , $sniffer , $rootElement , $timeout ) {
2330
+
2331
+ var parent = jqLite ( '<div><span></span></div>' ) ;
2332
+ $rootElement . append ( parent ) ;
2333
+ body . append ( $rootElement ) ;
2334
+ var element = jqLite ( parent . find ( 'span' ) ) ;
2335
+
2336
+ var signature = '' ;
2337
+
2338
+ $animate . addClass ( element [ 0 ] , 'klassy' , function ( ) {
2339
+ signature += 'X' ;
2340
+ } ) ;
2341
+ $animate . triggerReflow ( ) ;
2342
+
2343
+ $timeout . flush ( 500 ) ;
2344
+
2345
+ expect ( element . hasClass ( 'klassy' ) ) . toBe ( true ) ;
2346
+
2347
+ $animate . removeClass ( element [ 0 ] , 'klassy' , function ( ) {
2348
+ signature += 'Y' ;
2349
+ } ) ;
2350
+ $animate . triggerReflow ( ) ;
2351
+
2352
+ $timeout . flush ( 3000 ) ;
2353
+
2354
+ expect ( element . hasClass ( 'klassy' ) ) . toBe ( false ) ;
2355
+
2356
+ $animate . triggerCallbacks ( ) ;
2357
+ expect ( signature ) . toBe ( 'XY' ) ;
2358
+ } ) ) ;
2207
2359
2208
2360
it ( "should properly execute CSS animations/transitions and use callbacks when using addClass / removeClass" ,
2209
2361
inject ( function ( $animate , $rootScope , $sniffer , $rootElement , $timeout ) {
0 commit comments