@@ -520,10 +520,10 @@ describe('uiScroll', function () {
520
520
} ) ;
521
521
} ) ;
522
522
523
- describe ( 'paddings recalculation ' , function ( ) {
523
+ describe ( 'calculation of the paddings ' , function ( ) {
524
524
525
- var viewportHeight = 60 ;
526
- var itemHeight = 10 ;
525
+ var viewportHeight = 120 ;
526
+ var itemHeight = 20 ;
527
527
var bufferSize = 3 ;
528
528
529
529
var scrollSettings = {
@@ -533,134 +533,77 @@ describe('uiScroll', function () {
533
533
bufferSize : bufferSize
534
534
} ;
535
535
536
- it ( 'should calculate top padding element\'s height' , function ( ) {
536
+ it ( 'should calculate top padding element\'s height during scroll down ' , function ( ) {
537
537
runTest ( scrollSettings ,
538
538
function ( viewport , scope , $timeout ) {
539
539
var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
540
540
541
- var scrollDelta = itemHeight * bufferSize ;
542
- var limit = 6 ; // must be > 2 !
543
- var i ;
544
-
545
- // scroll down (double speed) + expectation
546
- for ( i = 0 ; i < limit ; i ++ ) {
547
- viewport . scrollTop ( viewport . scrollTop ( ) + 2 * scrollDelta ) ;
541
+ // scroll down + expectation
542
+ for ( var i = 0 ; i < 6 ; i ++ ) {
543
+ viewport . scrollTop ( 5000 ) ;
548
544
viewport . trigger ( 'scroll' ) ;
549
545
$timeout . flush ( ) ;
550
-
551
546
expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
552
547
}
553
-
554
- // scroll up (normal speed) + expectation
555
- for ( i = limit - 1 ; i >= 0 ; i -- ) {
556
- expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
557
-
558
- viewport . scrollTop ( viewport . scrollTop ( ) - scrollDelta ) ;
559
- viewport . trigger ( 'scroll' ) ;
560
- $timeout . flush ( ) ;
561
- }
562
-
563
548
}
564
549
) ;
565
550
} ) ;
566
551
567
- it ( 'should calculate top padding element\'s height with new rows pre-built ' , function ( ) {
552
+ it ( 'should calculate bottom padding element\'s height during scroll up ' , function ( ) {
568
553
runTest ( scrollSettings ,
569
554
function ( viewport , scope , $timeout ) {
570
- var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
571
-
572
- var scrollDelta = itemHeight * bufferSize ;
573
- var limit = 6 ; // must be > 2 !
574
- var i ;
575
-
576
- // scroll down, new rows building
577
- for ( i = 0 ; i < limit ; i ++ ) {
578
- viewport . scrollTop ( viewport . scrollTop ( ) + scrollDelta ) ;
579
- viewport . trigger ( 'scroll' ) ;
580
- }
581
-
582
- // scroll up, return to the top
583
- for ( i = 0 ; i < limit ; i ++ ) {
584
- viewport . scrollTop ( viewport . scrollTop ( ) - scrollDelta ) ;
585
- viewport . trigger ( 'scroll' ) ;
586
- }
587
-
588
- $timeout . flush ( ) ;
589
-
590
- // scroll down + expectation
591
- for ( i = 0 ; i < limit ; i ++ ) {
592
- viewport . scrollTop ( viewport . scrollTop ( ) + scrollDelta ) ;
593
- viewport . trigger ( 'scroll' ) ;
594
- $timeout . flush ( ) ;
595
-
596
- expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
597
- //console.log(topPaddingElement.height() + ' =?= ' + itemHeight * bufferSize * (i + 1));
598
- }
599
-
555
+ var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
556
+
600
557
// scroll up + expectation
601
- for ( i = limit - 1 ; i >= 0 ; i -- ) {
602
- expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
603
- //console.log(topPaddingElement.height() + ' =?= ' + itemHeight * bufferSize * (i + 1));
604
-
605
- viewport . scrollTop ( viewport . scrollTop ( ) - scrollDelta ) ;
558
+ for ( var i = 0 ; i < 6 ; i ++ ) {
559
+ viewport . scrollTop ( - 5000 ) ;
606
560
viewport . trigger ( 'scroll' ) ;
607
561
$timeout . flush ( ) ;
562
+ expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
608
563
}
609
564
610
565
}
611
566
) ;
612
567
} ) ;
613
568
614
- it ( 'should calculate bottom padding element\'s height with new rows pre-built ' , function ( ) {
569
+ it ( 'should calculate both padding elements heights during scroll down and up ' , function ( ) {
615
570
runTest ( scrollSettings ,
616
571
function ( viewport , scope , $timeout ) {
572
+ var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
617
573
var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
618
574
619
575
var scrollDelta = itemHeight * bufferSize ;
620
- var limit = 6 ; // must be > 2 !
621
- var i ;
576
+ var i , scrollIteration = 7 ;
622
577
623
- // scroll up, new rows building
624
- for ( i = 0 ; i < limit ; i ++ ) {
625
- viewport . scrollTop ( viewport . scrollTop ( ) - scrollDelta ) ;
626
- viewport . trigger ( 'scroll' ) ;
627
- }
628
-
629
- // scroll down, return to the bottom
630
- for ( i = 0 ; i < limit ; i ++ ) {
578
+ // scroll down + expectation
579
+ for ( i = 0 ; i < scrollIteration ; i ++ ) {
631
580
viewport . scrollTop ( viewport . scrollTop ( ) + scrollDelta ) ;
632
581
viewport . trigger ( 'scroll' ) ;
582
+ $timeout . flush ( ) ;
583
+ expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
584
+ expect ( bottomPaddingElement . height ( ) ) . toBe ( 0 ) ;
633
585
}
634
586
635
- $timeout . flush ( ) ;
636
-
637
- // unstable delta passing
638
- viewport . scrollTop ( viewport . scrollTop ( ) ) ;
639
-
640
587
// scroll up + expectation
641
- for ( i = 0 ; i < limit ; i ++ ) {
588
+ for ( i = 0 ; i < scrollIteration ; i ++ ) {
642
589
viewport . scrollTop ( viewport . scrollTop ( ) - scrollDelta ) ;
643
590
viewport . trigger ( 'scroll' ) ;
644
591
$timeout . flush ( ) ;
645
-
592
+ expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( scrollIteration - i - 1 ) ) ;
646
593
expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
647
- //console.log(bottomPaddingElement.height() + ' =?= ' + itemHeight * bufferSize * (i + 1));
648
594
}
649
595
650
- // scroll down + expectation
651
- for ( i = limit - 1 ; i >= 0 ; i -- ) {
652
- expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
653
- //console.log(bottomPaddingElement.height() + ' =?= ' + itemHeight * bufferSize * (i + 1));
654
-
655
- viewport . scrollTop ( viewport . scrollTop ( ) + scrollDelta ) ;
656
- viewport . trigger ( 'scroll' ) ;
657
- $timeout . flush ( ) ;
596
+ // further scroll up + expectation
597
+ for ( i = scrollIteration ; i < 2 * scrollIteration ; i ++ ) {
598
+ viewport . scrollTop ( viewport . scrollTop ( ) - scrollDelta ) ;
599
+ viewport . trigger ( 'scroll' ) ;
600
+ $timeout . flush ( ) ;
601
+ expect ( topPaddingElement . height ( ) ) . toBe ( 0 ) ;
602
+ expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * bufferSize * ( i + 1 ) ) ;
658
603
}
659
-
660
604
}
661
605
) ;
662
606
} ) ;
663
-
664
607
} ) ;
665
608
666
609
describe ( 'topVisible property: deep access and sync' , function ( ) {
0 commit comments