@@ -292,6 +292,129 @@ describe("animations", function() {
292
292
} ) ;
293
293
} ) ;
294
294
295
+ describe ( 'customFilter()' , function ( ) {
296
+ it ( 'should clear the `customFilter` if no function is passed' ,
297
+ module ( function ( $animateProvider ) {
298
+ expect ( $animateProvider . customFilter ( ) ) . toBeNull ( ) ;
299
+
300
+ $animateProvider . customFilter ( angular . noop ) ;
301
+ expect ( $animateProvider . customFilter ( ) ) . toEqual ( jasmine . any ( Function ) ) ;
302
+
303
+ $animateProvider . customFilter ( { } ) ;
304
+ expect ( $animateProvider . customFilter ( ) ) . toBeNull ( ) ;
305
+ } )
306
+ ) ;
307
+
308
+ it ( 'should animate only elements that pass through `$animateProvider.customFilter()`' ,
309
+ function ( ) {
310
+ var animationsAllowed = false ;
311
+
312
+ module ( function ( $animateProvider ) {
313
+ $animateProvider . customFilter ( function ( ) { return animationsAllowed ; } ) ;
314
+ } ) ;
315
+
316
+ inject ( function ( $animate , $rootScope ) {
317
+ $animate . enter ( element , parent ) ;
318
+ $rootScope . $digest ( ) ;
319
+ expect ( capturedAnimation ) . toBeFalsy ( ) ;
320
+
321
+ $animate . leave ( element , parent ) ;
322
+ $rootScope . $digest ( ) ;
323
+ expect ( capturedAnimation ) . toBeFalsy ( ) ;
324
+
325
+ animationsAllowed = true ;
326
+
327
+ $animate . enter ( element , parent ) ;
328
+ $rootScope . $digest ( ) ;
329
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
330
+
331
+ capturedAnimation = null ;
332
+
333
+ $animate . leave ( element , parent ) ;
334
+ $rootScope . $digest ( ) ;
335
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
336
+ } ) ;
337
+ }
338
+ ) ;
339
+
340
+ it ( 'should animate only elements that pass through `$animateProvider.customFilter()`' ,
341
+ function ( ) {
342
+ var animationsAllowed = false ;
343
+
344
+ module ( function ( $animateProvider ) {
345
+ $animateProvider . customFilter ( function ( ) { return animationsAllowed ; } ) ;
346
+ } ) ;
347
+
348
+ inject ( function ( $animate , $compile , $rootScope ) {
349
+ var svgElement = $compile ( '<svg class="element"></svg>' ) ( $rootScope ) ;
350
+
351
+ $animate . enter ( svgElement , parent ) ;
352
+ $rootScope . $digest ( ) ;
353
+ expect ( capturedAnimation ) . toBeFalsy ( ) ;
354
+
355
+ $animate . leave ( svgElement , parent ) ;
356
+ $rootScope . $digest ( ) ;
357
+ expect ( capturedAnimation ) . toBeFalsy ( ) ;
358
+
359
+ animationsAllowed = true ;
360
+
361
+ $animate . enter ( svgElement , parent ) ;
362
+ $rootScope . $digest ( ) ;
363
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
364
+
365
+ capturedAnimation = null ;
366
+
367
+ $animate . leave ( svgElement , parent ) ;
368
+ $rootScope . $digest ( ) ;
369
+ expect ( capturedAnimation ) . toBeTruthy ( ) ;
370
+ } ) ;
371
+ }
372
+ ) ;
373
+
374
+ it ( 'should pass the DOM element, event name and options to the filter function' , function ( ) {
375
+ var filterFn = jasmine . createSpy ( 'filterFn' ) ;
376
+ var options = { } ;
377
+
378
+ module ( function ( $animateProvider ) {
379
+ $animateProvider . customFilter ( filterFn ) ;
380
+ } ) ;
381
+
382
+ inject ( function ( $animate , $rootScope ) {
383
+ $animate . enter ( element , parent , null , options ) ;
384
+ expect ( filterFn ) . toHaveBeenCalledOnceWith ( element [ 0 ] , 'enter' , options ) ;
385
+
386
+ filterFn . calls . reset ( ) ;
387
+
388
+ $animate . leave ( element ) ;
389
+ expect ( filterFn ) . toHaveBeenCalledOnceWith ( element [ 0 ] , 'leave' , jasmine . any ( Object ) ) ;
390
+ } ) ;
391
+ } ) ;
392
+
393
+ it ( 'should complete the DOM operation even if filtered out' , function ( ) {
394
+ var filterFn = jasmine . createSpy ( 'filterFn' ) . and . returnValue ( false ) ;
395
+
396
+ module ( function ( $animateProvider ) {
397
+ $animateProvider . customFilter ( filterFn ) ;
398
+ } ) ;
399
+
400
+ inject ( function ( $animate , $rootScope ) {
401
+ expect ( element . parent ( ) [ 0 ] ) . toBeUndefined ( ) ;
402
+
403
+ $animate . enter ( element , parent ) ;
404
+ $rootScope . $digest ( ) ;
405
+
406
+ expect ( capturedAnimation ) . toBeFalsy ( ) ;
407
+ expect ( element . parent ( ) [ 0 ] ) . toBe ( parent [ 0 ] ) ;
408
+
409
+ $animate . leave ( element ) ;
410
+ $rootScope . $digest ( ) ;
411
+
412
+ expect ( capturedAnimation ) . toBeFalsy ( ) ;
413
+ expect ( element . parent ( ) [ 0 ] ) . toBeUndefined ( ) ;
414
+ } ) ;
415
+ } ) ;
416
+ } ) ;
417
+
295
418
describe ( 'enabled()' , function ( ) {
296
419
it ( "should work for all animations" , inject ( function ( $animate ) {
297
420
0 commit comments