@@ -346,6 +346,90 @@ describe('Router.run', function () {
346
346
} ) ;
347
347
} ) ;
348
348
349
+ describe ( 'ignoreScrollBehavior' , function ( ) {
350
+ var routes = (
351
+ < Route handler = { Nested } >
352
+ < Route handler = { Foo } ignoreScrollBehavior >
353
+ < Route handler = { Foo } path = '/feed' />
354
+ < Route handler = { Foo } path = '/discover' />
355
+ </ Route >
356
+ < Route path = '/search' handler = { Foo } ignoreScrollBehavior />
357
+ < Route path = '/about' handler = { Foo } />
358
+ </ Route >
359
+ ) ;
360
+
361
+ var div , didUpdateScroll ;
362
+ beforeEach ( function ( done ) {
363
+ TestLocation . history = [ '/feed' ] ;
364
+
365
+ div = document . createElement ( 'div' ) ;
366
+ document . body . appendChild ( div ) ;
367
+
368
+ var MockScrollBehavior = {
369
+ updateScrollPosition ( ) {
370
+ didUpdateScroll = true ;
371
+ }
372
+ } ;
373
+
374
+ Router . create ( {
375
+ routes : routes ,
376
+ location : TestLocation ,
377
+ scrollBehavior : MockScrollBehavior
378
+ } ) . run ( function ( Handler ) {
379
+ React . render ( < Handler /> , div , function ( ) {
380
+ done ( ) ;
381
+ } ) ;
382
+ } ) ;
383
+ } ) ;
384
+
385
+ afterEach ( function ( ) {
386
+ div . parentNode . removeChild ( div ) ;
387
+ didUpdateScroll = false ;
388
+ } ) ;
389
+
390
+ it ( 'calls updateScroll the first time' , function ( ) {
391
+ expect ( didUpdateScroll ) . toBe ( true ) ;
392
+ } ) ;
393
+
394
+ describe ( 'decides whether to update scroll on transition' , function ( ) {
395
+ beforeEach ( function ( ) {
396
+ didUpdateScroll = false ;
397
+ } ) ;
398
+
399
+ afterEach ( function ( ) {
400
+ TestLocation . pop ( ) ;
401
+ } ) ;
402
+
403
+ it ( 'calls updateScroll when no ancestors ignore scroll' , function ( ) {
404
+ TestLocation . push ( '/about' ) ;
405
+ expect ( didUpdateScroll ) . toBe ( true ) ;
406
+ } ) ;
407
+
408
+ it ( 'calls updateScroll when no ancestors ignore scroll although source and target do' , function ( ) {
409
+ TestLocation . push ( '/search' ) ;
410
+ expect ( didUpdateScroll ) . toBe ( true ) ;
411
+ } ) ;
412
+
413
+ it ( 'calls updateScroll when source is same as target and does not ignore scroll' , function ( ) {
414
+ TestLocation . push ( '/about?page=2' ) ;
415
+ expect ( didUpdateScroll ) . toBe ( true ) ;
416
+ } ) ;
417
+
418
+ it ( 'does not call updateScroll when common ancestor ignores scroll' , function ( ) {
419
+ TestLocation . push ( '/discover' ) ;
420
+ expect ( didUpdateScroll ) . toBe ( false ) ;
421
+ } ) ;
422
+
423
+ it ( 'does not call updateScroll when source is same as target and ignores scroll' , function ( ) {
424
+ TestLocation . push ( '/search' ) ;
425
+ didUpdateScroll = false ;
426
+
427
+ TestLocation . push ( '/search?q=test' ) ;
428
+ expect ( didUpdateScroll ) . toBe ( false ) ;
429
+ } ) ;
430
+ } ) ;
431
+ } ) ;
432
+
349
433
describe ( 'makePath' , function ( ) {
350
434
var router ;
351
435
beforeEach ( function ( ) {
0 commit comments