1
- describe ( 'uiScroll' , function ( ) {
1
+ describe ( 'uiScroll' , ( ) => {
2
2
'use strict' ;
3
3
4
4
let datasource ;
5
5
beforeEach ( module ( 'ui.scroll' ) ) ;
6
6
beforeEach ( module ( 'ui.scroll.test.datasources' ) ) ;
7
7
8
- const injectDatasource = ( datasourceToken ) =>
8
+ const injectDatasource = datasourceToken =>
9
9
beforeEach (
10
- inject ( [ datasourceToken , function ( _datasource ) {
11
- datasource = _datasource ;
12
- } ] )
10
+ inject ( [ datasourceToken , _datasource =>
11
+ datasource = _datasource
12
+ ] )
13
13
) ;
14
14
15
- describe ( 'buffer cleanup' , function ( ) {
16
- var getSettings = function ( ) {
17
- return {
18
- datasource : 'myEdgeDatasource' ,
19
- adapter : 'adapter' ,
20
- viewportHeight : 60 ,
21
- itemHeight : 20 ,
22
- padding : 0.3 ,
23
- startIndex : 3 ,
24
- bufferSize : 3
25
- } ;
15
+ describe ( 'buffer cleanup' , ( ) => {
16
+ const settings = {
17
+ datasource : 'myEdgeDatasource' , // items range is [-5..6]
18
+ adapter : 'adapter' ,
19
+ viewportHeight : 60 ,
20
+ itemHeight : 20 ,
21
+ padding : 0.3 ,
22
+ startIndex : 3 ,
23
+ bufferSize : 3
26
24
} ;
27
25
28
26
injectDatasource ( 'myEdgeDatasource' ) ;
29
27
30
- var cleanBuffer = function ( scope , applyUpdateOptions ) {
31
- var get = datasource . get ;
32
- var removedItems = [ ] ;
28
+ const cleanBuffer = ( scope , applyUpdateOptions ) => {
29
+ const get = datasource . get ;
30
+ const removedItems = [ ] ;
33
31
// sync the datasource
34
- datasource . get = function ( index , count , success ) {
35
- var removedIndex = removedItems . indexOf ( 'item' + index ) ;
36
- if ( removedIndex !== - 1 ) {
37
- // todo consider mutable-top case
38
- index += removedItems . length ; // - removedIndex;
32
+ datasource . get = ( index , count , success ) => {
33
+ if ( removedItems . indexOf ( 'item' + index ) !== - 1 ) {
34
+ index += removedItems . length ;
39
35
}
40
36
get ( index , count , success ) ;
41
37
} ;
42
38
// clean up the buffer
43
- scope . adapter . applyUpdates ( function ( item ) {
39
+ scope . adapter . applyUpdates ( item => {
44
40
removedItems . push ( item ) ;
45
41
return [ ] ;
46
42
} , applyUpdateOptions ) ;
47
43
} ;
48
44
49
- var shouldWorkWhenEOF = function ( viewport , scope , options ) {
45
+ const shouldWorkWhenEOF = ( viewport , scope , options ) => {
50
46
expect ( scope . adapter . isBOF ( ) ) . toBe ( false ) ;
51
47
expect ( scope . adapter . isEOF ( ) ) . toBe ( true ) ;
52
48
expect ( scope . adapter . bufferFirst ) . toBe ( 'item0' ) ;
@@ -66,19 +62,19 @@ describe('uiScroll', function () {
66
62
expect ( scope . adapter . bufferLength ) . toBe ( 5 ) ;
67
63
} ;
68
64
69
- it ( 'should be consistent on forward direction when eof with immutabeTop' , function ( ) {
70
- runTest ( getSettings ( ) , function ( viewport , scope ) {
71
- shouldWorkWhenEOF ( viewport , scope , { immutableTop : true } ) ;
72
- } ) ;
73
- } ) ;
65
+ it ( 'should be consistent on forward direction when eof with immutabeTop' , ( ) =>
66
+ runTest ( settings , ( viewport , scope ) =>
67
+ shouldWorkWhenEOF ( viewport , scope , { immutableTop : true } )
68
+ )
69
+ ) ;
74
70
75
- it ( 'should be consistent on forward direction when eof without immutabeTop' , function ( ) {
76
- runTest ( getSettings ( ) , function ( viewport , scope ) {
77
- shouldWorkWhenEOF ( viewport , scope ) ;
78
- } ) ;
79
- } ) ;
71
+ it ( 'should be consistent on forward direction when eof without immutabeTop' , ( ) =>
72
+ runTest ( settings , ( viewport , scope ) =>
73
+ shouldWorkWhenEOF ( viewport , scope )
74
+ )
75
+ ) ;
80
76
81
- var shouldWorkWhenNotEOF = function ( viewport , scope , options ) {
77
+ const shouldWorkWhenNotEOF = ( viewport , scope , options ) => {
82
78
expect ( scope . adapter . isBOF ( ) ) . toBe ( false ) ;
83
79
expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
84
80
expect ( scope . adapter . bufferFirst ) . toBe ( 'item-4' ) ;
@@ -97,29 +93,32 @@ describe('uiScroll', function () {
97
93
expect ( scope . adapter . bufferLength ) . toBe ( 4 ) ;
98
94
} ;
99
95
100
- it ( 'should be consistent on forward direction when not eof with immutabeTop' , function ( ) {
101
- var scrollSettings = getSettings ( ) ;
102
- scrollSettings . startIndex = - 1 ;
103
- scrollSettings . viewportHeight = 40 ;
104
- runTest ( scrollSettings , function ( viewport , scope ) {
105
- shouldWorkWhenNotEOF ( viewport , scope , { immutableTop : true } ) ;
106
- } ) ;
107
- } ) ;
108
-
109
- it ( 'should be consistent on forward direction when not eof without immutabeTop' , function ( ) {
110
- var scrollSettings = getSettings ( ) ;
111
- scrollSettings . startIndex = - 1 ;
112
- scrollSettings . viewportHeight = 40 ;
113
- runTest ( scrollSettings , function ( viewport , scope ) {
114
- shouldWorkWhenNotEOF ( viewport , scope ) ;
115
- } ) ;
116
- } ) ;
117
-
118
- it ( 'should be consistent on backward direction when bof with immutableTop' , function ( ) {
119
- var scrollSettings = getSettings ( ) ;
120
- scrollSettings . startIndex = - 3 ;
121
- scrollSettings . padding = 0.5 ;
122
- runTest ( scrollSettings , function ( viewport , scope ) {
96
+ it ( 'should be consistent on forward direction when not eof with immutabeTop' , ( ) =>
97
+ runTest ( {
98
+ ...settings ,
99
+ startIndex : - 1 ,
100
+ viewportHeight : 40
101
+ } , ( viewport , scope ) =>
102
+ shouldWorkWhenNotEOF ( viewport , scope , { immutableTop : true } )
103
+ )
104
+ ) ;
105
+
106
+ it ( 'should be consistent on forward direction when not eof without immutabeTop' , ( ) =>
107
+ runTest ( {
108
+ ...settings ,
109
+ startIndex : - 1 ,
110
+ viewportHeight : 40
111
+ } , ( viewport , scope ) =>
112
+ shouldWorkWhenNotEOF ( viewport , scope )
113
+ )
114
+ ) ;
115
+
116
+ it ( 'should be consistent on backward direction when bof with immutableTop' , ( ) =>
117
+ runTest ( {
118
+ ...settings ,
119
+ startIndex : - 3 ,
120
+ padding : 0.5
121
+ } , ( viewport , scope ) => {
123
122
expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
124
123
expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
125
124
expect ( scope . adapter . bufferFirst ) . toBe ( 'item-5' ) ;
@@ -137,14 +136,15 @@ describe('uiScroll', function () {
137
136
expect ( Helper . getRow ( viewport , 4 ) ) . toBe ( '-2: item5' ) ;
138
137
expect ( Helper . getRow ( viewport , 5 ) ) . toBe ( '-1: item6' ) ;
139
138
expect ( scope . adapter . bufferLength ) . toBe ( 5 ) ;
140
- } ) ;
141
- } ) ;
142
-
143
- it ( 'should be consistent on backward direction when bof without immutableTop' , function ( ) {
144
- var scrollSettings = getSettings ( ) ;
145
- scrollSettings . startIndex = - 3 ;
146
- scrollSettings . padding = 0.5 ;
147
- runTest ( scrollSettings , function ( viewport , scope ) {
139
+ } )
140
+ ) ;
141
+
142
+ it ( 'should be consistent on backward direction when bof without immutableTop' , ( ) =>
143
+ runTest ( {
144
+ ...settings ,
145
+ startIndex : - 3 ,
146
+ padding : 0.5
147
+ } , ( viewport , scope ) => {
148
148
expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
149
149
expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
150
150
expect ( scope . adapter . bufferFirst ) . toBe ( 'item-5' ) ;
@@ -162,10 +162,10 @@ describe('uiScroll', function () {
162
162
expect ( Helper . getRow ( viewport , 4 ) ) . toBe ( '5: item5' ) ;
163
163
expect ( Helper . getRow ( viewport , 5 ) ) . toBe ( '6: item6' ) ;
164
164
expect ( scope . adapter . bufferLength ) . toBe ( 5 ) ;
165
- } ) ;
166
- } ) ;
165
+ } )
166
+ ) ;
167
167
168
- var shouldWorkWhenNotBOF = function ( viewport , scope , options ) {
168
+ const shouldWorkWhenNotBOF = ( viewport , scope , options ) => {
169
169
expect ( scope . adapter . isBOF ( ) ) . toBe ( false ) ;
170
170
expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
171
171
expect ( scope . adapter . bufferFirst ) . toBe ( 'item-4' ) ;
@@ -185,24 +185,25 @@ describe('uiScroll', function () {
185
185
expect ( scope . adapter . bufferLength ) . toBe ( 5 ) ;
186
186
} ;
187
187
188
- it ( 'should be consistent on backward direction when not bof with immutableTop' , function ( ) {
189
- var scrollSettings = getSettings ( ) ;
190
- scrollSettings . startIndex = - 1 ;
191
- scrollSettings . padding = 0.3 ;
192
- runTest ( scrollSettings , function ( viewport , scope ) {
193
- shouldWorkWhenNotBOF ( viewport , scope , { immutableTop : true } ) ;
194
- } ) ;
195
- } ) ;
196
-
197
- it ( 'should be consistent on backward direction when not bof without immutableTop' , function ( ) {
198
- var scrollSettings = getSettings ( ) ;
199
- scrollSettings . startIndex = - 1 ;
200
- scrollSettings . padding = 0.3 ;
201
- runTest ( scrollSettings , function ( viewport , scope ) {
202
- shouldWorkWhenNotBOF ( viewport , scope ) ;
203
- } ) ;
204
- } ) ;
188
+ it ( 'should be consistent on backward direction when not bof with immutableTop' , ( ) =>
189
+ runTest ( {
190
+ ...settings ,
191
+ startIndex : - 1 ,
192
+ padding : 0.3
193
+ } , ( viewport , scope ) =>
194
+ shouldWorkWhenNotBOF ( viewport , scope , { immutableTop : true } )
195
+ )
196
+ ) ;
205
197
198
+ it ( 'should be consistent on backward direction when not bof without immutableTop' , ( ) =>
199
+ runTest ( {
200
+ ...settings ,
201
+ startIndex : - 1 ,
202
+ padding : 0.3
203
+ } , ( viewport , scope ) =>
204
+ shouldWorkWhenNotBOF ( viewport , scope )
205
+ )
206
+ ) ;
206
207
} ) ;
207
208
208
209
} ) ;
0 commit comments