@@ -9,7 +9,7 @@ describe('uiScroll main/max indicies', function() {
99 var viewportHeight = 120 ;
1010 var itemHeight = 20 ;
1111 var bufferSize = 3 ;
12- var userMinIndex = - 100 ;
12+ var userMinIndex = - 99 ; // for 100 items
1313 var userMaxIndex = 100 ;
1414
1515 var scrollSettings = {
@@ -18,44 +18,75 @@ describe('uiScroll main/max indicies', function() {
1818 itemHeight : itemHeight ,
1919 bufferSize : bufferSize
2020 } ;
21- it ( 'should calculate bottom padding element\'s height after user max index is set' , function ( ) {
2221
22+ it ( 'should calculate bottom padding element\'s height after user max index is set' , function ( ) {
2323 var setMaxIndex ;
2424 inject ( function ( myInfiniteDatasource ) {
2525 setMaxIndex = function ( ) {
2626 myInfiniteDatasource . maxIndex = userMaxIndex ;
2727 } ;
2828 } ) ;
29-
3029 runTest ( scrollSettings ,
3130 function ( viewport ) {
3231 var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
32+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
3333
3434 setMaxIndex ( ) ;
3535
3636 var virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
3737 expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
38+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
3839 }
3940 ) ;
4041 } ) ;
4142
4243 it ( 'should calculate top padding element\'s height after user min index is set' , function ( ) {
43-
4444 var setMinIndex ;
4545 inject ( function ( myInfiniteDatasource ) {
4646 setMinIndex = function ( ) {
4747 myInfiniteDatasource . minIndex = userMinIndex ;
4848 } ;
4949 } ) ;
50-
5150 runTest ( scrollSettings ,
5251 function ( viewport ) {
5352 var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
53+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
5454
5555 setMinIndex ( ) ;
5656
5757 var virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
5858 expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
59+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * ( ( - 1 ) * userMinIndex + 1 ) ) ;
60+ }
61+ ) ;
62+ } ) ;
63+
64+ it ( 'should work with maxIndex pre-set on datasource' , function ( ) {
65+ var setMinIndex ;
66+ inject ( function ( myInfiniteDatasource ) {
67+ myInfiniteDatasource . maxIndex = userMaxIndex ;
68+ } ) ;
69+ runTest ( scrollSettings ,
70+ function ( viewport ) {
71+ var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
72+ var virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
73+ expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
74+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
75+ }
76+ ) ;
77+ } ) ;
78+
79+ it ( 'should work with minIndex pre-set on datasource' , function ( ) {
80+ var setMinIndex ;
81+ inject ( function ( myInfiniteDatasource ) {
82+ myInfiniteDatasource . minIndex = userMinIndex ;
83+ } ) ;
84+ runTest ( scrollSettings ,
85+ function ( viewport ) {
86+ var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
87+ var virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
88+ expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
89+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * ( ( - 1 ) * userMinIndex + 1 ) ) ;
5990 }
6091 ) ;
6192 } ) ;
0 commit comments