@@ -9,7 +9,7 @@ describe('uiScroll main/max indicies', function() {
9
9
var viewportHeight = 120 ;
10
10
var itemHeight = 20 ;
11
11
var bufferSize = 3 ;
12
- var userMinIndex = - 100 ;
12
+ var userMinIndex = - 99 ; // for 100 items
13
13
var userMaxIndex = 100 ;
14
14
15
15
var scrollSettings = {
@@ -18,44 +18,75 @@ describe('uiScroll main/max indicies', function() {
18
18
itemHeight : itemHeight ,
19
19
bufferSize : bufferSize
20
20
} ;
21
- it ( 'should calculate bottom padding element\'s height after user max index is set' , function ( ) {
22
21
22
+ it ( 'should calculate bottom padding element\'s height after user max index is set' , function ( ) {
23
23
var setMaxIndex ;
24
24
inject ( function ( myInfiniteDatasource ) {
25
25
setMaxIndex = function ( ) {
26
26
myInfiniteDatasource . maxIndex = userMaxIndex ;
27
27
} ;
28
28
} ) ;
29
-
30
29
runTest ( scrollSettings ,
31
30
function ( viewport ) {
32
31
var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
32
+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
33
33
34
34
setMaxIndex ( ) ;
35
35
36
36
var virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
37
37
expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
38
+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
38
39
}
39
40
) ;
40
41
} ) ;
41
42
42
43
it ( 'should calculate top padding element\'s height after user min index is set' , function ( ) {
43
-
44
44
var setMinIndex ;
45
45
inject ( function ( myInfiniteDatasource ) {
46
46
setMinIndex = function ( ) {
47
47
myInfiniteDatasource . minIndex = userMinIndex ;
48
48
} ;
49
49
} ) ;
50
-
51
50
runTest ( scrollSettings ,
52
51
function ( viewport ) {
53
52
var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
53
+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
54
54
55
55
setMinIndex ( ) ;
56
56
57
57
var virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
58
58
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 ) ) ;
59
90
}
60
91
) ;
61
92
} ) ;
0 commit comments