1
1
/*global describe, beforeEach, module, inject, it, expect, runTest */
2
- describe ( 'uiScroll main /max indicies' , function ( ) {
2
+ describe ( 'uiScroll user min /max indicies. ' , ( ) => {
3
3
'use strict' ;
4
4
5
5
beforeEach ( module ( 'ui.scroll' ) ) ;
6
6
beforeEach ( module ( 'ui.scroll.test.datasources' ) ) ;
7
7
8
- describe ( 'user min and max indexes' , function ( ) {
9
- var viewportHeight = 120 ;
10
- var itemHeight = 20 ;
11
- var bufferSize = 3 ;
12
- var userMinIndex = - 99 ; // for 100 items
13
- var userMaxIndex = 100 ;
14
-
15
- var scrollSettings = {
16
- datasource : 'myInfiniteDatasource' ,
17
- viewportHeight : viewportHeight ,
18
- itemHeight : itemHeight ,
19
- bufferSize : bufferSize
20
- } ;
21
-
22
- it ( 'should calculate bottom padding element\'s height after user max index is set' , function ( ) {
23
- var setMaxIndex ;
8
+ var viewportHeight = 120 ;
9
+ var itemHeight = 20 ;
10
+ var bufferSize = 3 ;
11
+ var userMinIndex = - 99 ; // for 100 items
12
+ var userMaxIndex = 100 ;
13
+
14
+ var scrollSettings = {
15
+ datasource : 'myInfiniteDatasource' ,
16
+ viewportHeight : viewportHeight ,
17
+ itemHeight : itemHeight ,
18
+ bufferSize : bufferSize ,
19
+ adapter : 'adapter'
20
+ } ;
21
+
22
+ describe ( 'Setting\n' , ( ) => {
23
+
24
+ it ( 'should calculate bottom padding element\'s height after user max index is set' , ( ) => {
25
+ let setMaxIndex ;
24
26
inject ( function ( myInfiniteDatasource ) {
25
- setMaxIndex = function ( ) {
26
- myInfiniteDatasource . maxIndex = userMaxIndex ;
27
- } ;
27
+ setMaxIndex = ( ) => myInfiniteDatasource . maxIndex = userMaxIndex ;
28
28
} ) ;
29
29
runTest ( scrollSettings ,
30
- function ( viewport ) {
31
- var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
30
+ ( viewport ) => {
31
+ const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
32
32
expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
33
33
34
34
setMaxIndex ( ) ;
35
35
36
- var virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
36
+ const virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
37
37
expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
38
38
expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
39
39
}
40
40
) ;
41
41
} ) ;
42
42
43
- it ( 'should calculate top padding element\'s height after user min index is set' , function ( ) {
44
- var setMinIndex ;
43
+ it ( 'should calculate top padding element\'s height after user min index is set' , ( ) => {
44
+ let setMinIndex ;
45
45
inject ( function ( myInfiniteDatasource ) {
46
- setMinIndex = function ( ) {
47
- myInfiniteDatasource . minIndex = userMinIndex ;
48
- } ;
46
+ setMinIndex = ( ) => myInfiniteDatasource . minIndex = userMinIndex ;
49
47
} ) ;
50
48
runTest ( scrollSettings ,
51
- function ( viewport ) {
52
- var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
49
+ ( viewport ) => {
50
+ const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
53
51
expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
54
52
55
53
setMinIndex ( ) ;
56
54
57
- var virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
55
+ const virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
58
56
expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
59
57
expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * ( ( - 1 ) * userMinIndex + 1 ) ) ;
60
58
}
61
59
) ;
62
60
} ) ;
63
61
64
- it ( 'should work with maxIndex pre-set on datasource' , function ( ) {
62
+ } ) ;
63
+
64
+ describe ( 'Pre-setting\n' , ( ) => {
65
+
66
+ it ( 'should work with maxIndex pre-set on datasource' , ( ) => {
65
67
inject ( function ( myInfiniteDatasource ) {
66
68
myInfiniteDatasource . maxIndex = userMaxIndex ;
67
69
} ) ;
68
70
runTest ( scrollSettings ,
69
- function ( viewport ) {
70
- var bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
71
- var virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
71
+ ( viewport ) => {
72
+ const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
73
+ const virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
72
74
expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
73
75
expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
74
76
}
75
77
) ;
76
78
} ) ;
77
79
78
- it ( 'should work with minIndex pre-set on datasource' , function ( ) {
80
+ it ( 'should work with minIndex pre-set on datasource' , ( ) => {
79
81
inject ( function ( myInfiniteDatasource ) {
80
82
myInfiniteDatasource . minIndex = userMinIndex ;
81
83
} ) ;
82
84
runTest ( scrollSettings ,
83
- function ( viewport ) {
84
- var topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
85
- var virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
85
+ ( viewport ) => {
86
+ const topPaddingElement = angular . element ( viewport . children ( ) [ 0 ] ) ;
87
+ const virtualItemsAmount = ( - 1 ) * userMinIndex - bufferSize + 1 ;
86
88
expect ( topPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
87
89
expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * ( ( - 1 ) * userMinIndex + 1 ) ) ;
88
90
}
@@ -91,4 +93,38 @@ describe('uiScroll main/max indicies', function() {
91
93
92
94
} ) ;
93
95
96
+ describe ( 'Reload\n' , ( ) => {
97
+
98
+ it ( 'should persist user maxIndex after reload' , ( ) => {
99
+ inject ( function ( myInfiniteDatasource ) {
100
+ myInfiniteDatasource . maxIndex = userMaxIndex ;
101
+ } ) ;
102
+ runTest ( scrollSettings ,
103
+ ( viewport , scope ) => {
104
+ scope . adapter . reload ( ) ;
105
+ const bottomPaddingElement = angular . element ( viewport . children ( ) [ viewport . children ( ) . length - 1 ] ) ;
106
+ const virtualItemsAmount = userMaxIndex - ( viewportHeight / itemHeight ) - bufferSize ;
107
+ expect ( bottomPaddingElement . height ( ) ) . toBe ( itemHeight * virtualItemsAmount ) ;
108
+ expect ( viewport . scrollTop ( ) ) . toBe ( itemHeight * bufferSize ) ;
109
+ }
110
+ ) ;
111
+ } ) ;
112
+
113
+ // it('should persist user minIndex after reload', () => {
114
+ // inject(function(myInfiniteDatasource) {
115
+ // myInfiniteDatasource.minIndex = userMinIndex;
116
+ // });
117
+ // runTest(scrollSettings,
118
+ // (viewport, scope) => {
119
+ // scope.adapter.reload();
120
+ // const topPaddingElement = angular.element(viewport.children()[0]);
121
+ // const virtualItemsAmount = (-1) * userMinIndex - bufferSize + 1;
122
+ // expect(topPaddingElement.height()).toBe(itemHeight * virtualItemsAmount);
123
+ // expect(viewport.scrollTop()).toBe(itemHeight * ((-1) * userMinIndex + 1));
124
+ // }
125
+ // );
126
+ // });
127
+
128
+ } ) ;
129
+
94
130
} ) ;
0 commit comments