@@ -408,6 +408,74 @@ describe('<md-virtual-repeat>', function() {
408
408
expect ( getRepeated ( ) . length ) . toBe ( numItemRenderers ) ;
409
409
} ) ;
410
410
411
+ it ( 'should resize the scroller correctly when item length changes (vertical)' , function ( ) {
412
+ scope . items = createItems ( 200 ) ;
413
+ createRepeater ( ) ;
414
+ scope . $apply ( ) ;
415
+ $$rAF . flush ( ) ;
416
+ expect ( sizer [ 0 ] . offsetHeight ) . toBe ( 200 * ITEM_SIZE ) ;
417
+
418
+ // Scroll down half way
419
+ scroller [ 0 ] . scrollTop = 100 * ITEM_SIZE ;
420
+ scroller . triggerHandler ( 'scroll' ) ;
421
+ scope . $apply ( ) ;
422
+ $$rAF . flush ( ) ;
423
+
424
+ // Remove some items
425
+ scope . items = createItems ( 20 ) ;
426
+ scope . $apply ( ) ;
427
+ $$rAF . flush ( ) ;
428
+ expect ( scroller [ 0 ] . scrollTop ) . toBe ( 0 ) ;
429
+ expect ( sizer [ 0 ] . offsetHeight ) . toBe ( 20 * ITEM_SIZE ) ;
430
+
431
+ // Scroll down half way
432
+ scroller [ 0 ] . scrollTop = 10 * ITEM_SIZE ;
433
+ scroller . triggerHandler ( 'scroll' ) ;
434
+ scope . $apply ( ) ;
435
+ $$rAF . flush ( ) ;
436
+
437
+ // Add more items
438
+ scope . items = createItems ( 250 ) ;
439
+ scope . $apply ( ) ;
440
+ $$rAF . flush ( ) ;
441
+ expect ( scroller [ 0 ] . scrollTop ) . toBe ( 100 ) ;
442
+ expect ( sizer [ 0 ] . offsetHeight ) . toBe ( 250 * ITEM_SIZE ) ;
443
+ } ) ;
444
+
445
+ it ( 'should resize the scroller correctly when item length changes (horizontal)' , function ( ) {
446
+ container . attr ( { 'md-orient-horizontal' : '' } ) ;
447
+ scope . items = createItems ( 200 ) ;
448
+ createRepeater ( ) ;
449
+ scope . $apply ( ) ;
450
+ $$rAF . flush ( ) ;
451
+ expect ( sizer [ 0 ] . offsetWidth ) . toBe ( 200 * ITEM_SIZE ) ;
452
+
453
+ // Scroll right half way
454
+ scroller [ 0 ] . scrollLeft = 100 * ITEM_SIZE ;
455
+ scroller . triggerHandler ( 'scroll' ) ;
456
+ scope . $apply ( ) ;
457
+ $$rAF . flush ( ) ;
458
+
459
+ // Remove some items
460
+ scope . items = createItems ( 20 ) ;
461
+ scope . $apply ( ) ;
462
+ $$rAF . flush ( ) ;
463
+ expect ( scroller [ 0 ] . scrollLeft ) . toBe ( 0 ) ;
464
+ expect ( sizer [ 0 ] . offsetWidth ) . toBe ( 20 * ITEM_SIZE ) ;
465
+
466
+ // Scroll right half way
467
+ scroller [ 0 ] . scrollLeft = 10 * ITEM_SIZE ;
468
+ scroller . triggerHandler ( 'scroll' ) ;
469
+ scope . $apply ( ) ;
470
+ $$rAF . flush ( ) ;
471
+
472
+ // Add more items
473
+ scope . items = createItems ( 250 ) ;
474
+ scope . $apply ( ) ;
475
+ $$rAF . flush ( ) ;
476
+ expect ( sizer [ 0 ] . offsetWidth ) . toBe ( 250 * ITEM_SIZE ) ;
477
+ } ) ;
478
+
411
479
it ( 'should update topIndex when scrolling' , function ( ) {
412
480
container . attr ( { 'md-top-index' : 'topIndex' } ) ;
413
481
scope . items = createItems ( NUM_ITEMS ) ;
0 commit comments