@@ -312,7 +312,7 @@ describe('ngInclude', function() {
312
312
} ) ) ;
313
313
314
314
315
- describe ( 'autoscoll ' , function ( ) {
315
+ describe ( 'autoscroll ' , function ( ) {
316
316
var autoScrollSpy ;
317
317
318
318
function spyOnAnchorScroll ( ) {
@@ -328,52 +328,114 @@ describe('ngInclude', function() {
328
328
} ;
329
329
}
330
330
331
- function changeTplAndValueTo ( template , value ) {
332
- return function ( $rootScope , $browser ) {
333
- $rootScope . $apply ( function ( ) {
334
- $rootScope . tpl = template ;
335
- $rootScope . value = value ;
336
- } ) ;
337
- } ;
338
- }
339
-
340
- beforeEach ( module ( spyOnAnchorScroll ( ) ) ) ;
331
+ beforeEach ( module ( spyOnAnchorScroll ( ) , 'mock.animate' ) ) ;
341
332
beforeEach ( inject (
342
333
putIntoCache ( 'template.html' , 'CONTENT' ) ,
343
334
putIntoCache ( 'another.html' , 'CONTENT' ) ) ) ;
344
335
345
-
346
336
it ( 'should call $anchorScroll if autoscroll attribute is present' , inject (
347
337
compileAndLink ( '<div><ng:include src="tpl" autoscroll></ng:include></div>' ) ,
348
- changeTplAndValueTo ( 'template.html' ) , function ( ) {
338
+ function ( $rootScope , $animate , $timeout ) {
339
+
340
+ $rootScope . $apply ( function ( ) {
341
+ $rootScope . tpl = 'template.html' ;
342
+ } ) ;
343
+
344
+ expect ( autoScrollSpy ) . not . toHaveBeenCalled ( ) ;
345
+ $animate . flushNext ( 'enter' ) ;
346
+ $timeout . flush ( ) ;
347
+
349
348
expect ( autoScrollSpy ) . toHaveBeenCalledOnce ( ) ;
350
349
} ) ) ;
351
350
352
351
353
- it ( 'should call $anchorScroll if autoscroll evaluates to true' , inject (
354
- compileAndLink ( '<div><ng:include src="tpl" autoscroll="value"></ng:include></div>' ) ,
355
- changeTplAndValueTo ( 'template.html' , true ) ,
356
- changeTplAndValueTo ( 'another.html' , 'some-string' ) ,
357
- changeTplAndValueTo ( 'template.html' , 100 ) , function ( ) {
352
+ it ( 'should call $anchorScroll if autoscroll evaluates to true' ,
353
+ inject ( function ( $rootScope , $compile , $animate , $timeout ) {
354
+
355
+ element = $compile ( '<div><ng:include src="tpl" autoscroll="value"></ng:include></div>' ) ( $rootScope ) ;
356
+
357
+ $rootScope . $apply ( function ( ) {
358
+ $rootScope . tpl = 'template.html' ;
359
+ $rootScope . value = true ;
360
+ } ) ;
361
+
362
+ $animate . flushNext ( 'enter' ) ;
363
+ $timeout . flush ( ) ;
364
+
365
+ $rootScope . $apply ( function ( ) {
366
+ $rootScope . tpl = 'another.html' ;
367
+ $rootScope . value = 'some-string' ;
368
+ } ) ;
369
+
370
+ $animate . flushNext ( 'leave' ) ;
371
+ $animate . flushNext ( 'enter' ) ;
372
+ $timeout . flush ( ) ;
373
+
374
+ $rootScope . $apply ( function ( ) {
375
+ $rootScope . tpl = 'template.html' ;
376
+ $rootScope . value = 100 ;
377
+ } ) ;
378
+
379
+ $animate . flushNext ( 'leave' ) ;
380
+ $animate . flushNext ( 'enter' ) ;
381
+ $timeout . flush ( ) ;
382
+
358
383
expect ( autoScrollSpy ) . toHaveBeenCalled ( ) ;
359
384
expect ( autoScrollSpy . callCount ) . toBe ( 3 ) ;
360
385
} ) ) ;
361
386
362
387
363
388
it ( 'should not call $anchorScroll if autoscroll attribute is not present' , inject (
364
389
compileAndLink ( '<div><ng:include src="tpl"></ng:include></div>' ) ,
365
- changeTplAndValueTo ( 'template.html' ) , function ( ) {
390
+ function ( $rootScope , $animate , $timeout ) {
391
+
392
+ $rootScope . $apply ( function ( ) {
393
+ $rootScope . tpl = 'template.html' ;
394
+ } ) ;
395
+
396
+ $animate . flushNext ( 'enter' ) ;
397
+ $timeout . flush ( ) ;
366
398
expect ( autoScrollSpy ) . not . toHaveBeenCalled ( ) ;
367
399
} ) ) ;
368
400
369
401
370
- it ( 'should not call $anchorScroll if autoscroll evaluates to false' , inject (
371
- compileAndLink ( '<div><ng:include src="tpl" autoscroll="value"></ng:include></div>' ) ,
372
- changeTplAndValueTo ( 'template.html' , false ) ,
373
- changeTplAndValueTo ( 'template.html' , undefined ) ,
374
- changeTplAndValueTo ( 'template.html' , null ) , function ( ) {
402
+ it ( 'should not call $anchorScroll if autoscroll evaluates to false' ,
403
+ inject ( function ( $rootScope , $compile , $animate , $timeout ) {
404
+
405
+ element = $compile ( '<div><ng:include src="tpl" autoscroll="value"></ng:include></div>' ) ( $rootScope ) ;
406
+
407
+ $rootScope . $apply ( function ( ) {
408
+ $rootScope . tpl = 'template.html' ;
409
+ $rootScope . value = false ;
410
+ } ) ;
411
+
412
+ $animate . flushNext ( 'enter' ) ;
413
+ $timeout . flush ( ) ;
414
+
415
+ $rootScope . $apply ( function ( ) {
416
+ $rootScope . tpl = 'template.html' ;
417
+ $rootScope . value = undefined ;
418
+ } ) ;
419
+
420
+ $rootScope . $apply ( function ( ) {
421
+ $rootScope . tpl = 'template.html' ;
422
+ $rootScope . value = null ;
423
+ } ) ;
424
+
375
425
expect ( autoScrollSpy ) . not . toHaveBeenCalled ( ) ;
376
426
} ) ) ;
427
+
428
+ it ( 'should only call $anchorScroll after the "enter" animation completes' , inject (
429
+ compileAndLink ( '<div><ng:include src="tpl" autoscroll></ng:include></div>' ) ,
430
+ function ( $rootScope , $animate , $timeout ) {
431
+ expect ( autoScrollSpy ) . not . toHaveBeenCalled ( ) ;
432
+
433
+ $rootScope . $apply ( "tpl = 'template.html'" ) ;
434
+ $animate . flushNext ( 'enter' ) ;
435
+ $timeout . flush ( ) ;
436
+
437
+ expect ( autoScrollSpy ) . toHaveBeenCalledOnce ( ) ;
438
+ } ) ) ;
377
439
} ) ;
378
440
} ) ;
379
441
0 commit comments