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