Skip to content

Commit 58288c3

Browse files
committed
paddings test suite refactoring
1 parent ae163b8 commit 58288c3

File tree

1 file changed

+30
-87
lines changed

1 file changed

+30
-87
lines changed

test/BasicTestsSpec.js

Lines changed: 30 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,10 @@ describe('uiScroll', function () {
520520
});
521521
});
522522

523-
describe('paddings recalculation', function () {
523+
describe('calculation of the paddings', function () {
524524

525-
var viewportHeight = 60;
526-
var itemHeight = 10;
525+
var viewportHeight = 120;
526+
var itemHeight = 20;
527527
var bufferSize = 3;
528528

529529
var scrollSettings = {
@@ -533,134 +533,77 @@ describe('uiScroll', function () {
533533
bufferSize: bufferSize
534534
};
535535

536-
it('should calculate top padding element\'s height', function () {
536+
it('should calculate top padding element\'s height during scroll down', function () {
537537
runTest(scrollSettings,
538538
function (viewport, scope, $timeout) {
539539
var topPaddingElement = angular.element(viewport.children()[0]);
540540

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);
548544
viewport.trigger('scroll');
549545
$timeout.flush();
550-
551546
expect(topPaddingElement.height()).toBe(itemHeight * bufferSize * (i + 1));
552547
}
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-
563548
}
564549
);
565550
});
566551

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 () {
568553
runTest(scrollSettings,
569554
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+
600557
// 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);
606560
viewport.trigger('scroll');
607561
$timeout.flush();
562+
expect(bottomPaddingElement.height()).toBe(itemHeight * bufferSize * (i + 1));
608563
}
609564

610565
}
611566
);
612567
});
613568

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 () {
615570
runTest(scrollSettings,
616571
function (viewport, scope, $timeout) {
572+
var topPaddingElement = angular.element(viewport.children()[0]);
617573
var bottomPaddingElement = angular.element(viewport.children()[viewport.children().length - 1]);
618574

619575
var scrollDelta = itemHeight * bufferSize;
620-
var limit = 6; // must be > 2 !
621-
var i;
576+
var i, scrollIteration = 7;
622577

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++) {
631580
viewport.scrollTop(viewport.scrollTop() + scrollDelta);
632581
viewport.trigger('scroll');
582+
$timeout.flush();
583+
expect(topPaddingElement.height()).toBe(itemHeight * bufferSize * (i + 1));
584+
expect(bottomPaddingElement.height()).toBe(0);
633585
}
634586

635-
$timeout.flush();
636-
637-
// unstable delta passing
638-
viewport.scrollTop(viewport.scrollTop());
639-
640587
// scroll up + expectation
641-
for(i = 0; i < limit; i++) {
588+
for(i = 0; i < scrollIteration; i++) {
642589
viewport.scrollTop(viewport.scrollTop() - scrollDelta);
643590
viewport.trigger('scroll');
644591
$timeout.flush();
645-
592+
expect(topPaddingElement.height()).toBe(itemHeight * bufferSize * (scrollIteration - i - 1));
646593
expect(bottomPaddingElement.height()).toBe(itemHeight * bufferSize * (i + 1));
647-
//console.log(bottomPaddingElement.height() + ' =?= ' + itemHeight * bufferSize * (i + 1));
648594
}
649595

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));
658603
}
659-
660604
}
661605
);
662606
});
663-
664607
});
665608

666609
describe('topVisible property: deep access and sync', function () {

0 commit comments

Comments
 (0)