1
1
/*global describe, beforeEach, module, it, expect, runTest */
2
- describe ( 'uiScroll Paddings cache' , function ( ) {
2
+ describe ( 'uiScroll Paddings cache' , ( ) => {
3
3
'use strict' ;
4
4
5
5
beforeEach ( module ( 'ui.scroll' ) ) ;
6
6
beforeEach ( module ( 'ui.scroll.test.datasources' ) ) ;
7
7
8
- var itemsCount = 30 ;
9
- var itemHeight = 100 ;
10
- var viewportHeight = 500 ;
11
- var MAX = 3 ; // maximum scrolling interations to reach out the EOF/BOF
8
+ const itemsCount = 30 ;
9
+ const itemHeight = 100 ;
10
+ const viewportHeight = 500 ;
11
+ const MAX = 3 ; // maximum scrolling interations to reach out the EOF/BOF
12
12
13
- var scrollSettings = {
13
+ const scrollSettings = {
14
14
datasource : 'myResponsiveDatasource' ,
15
15
adapter : 'adapter' ,
16
16
itemHeight : itemHeight ,
17
17
viewportHeight : viewportHeight
18
18
} ;
19
19
20
20
function getBottomPaddingHeight ( viewport ) {
21
- var viewportChildren = viewport . children ( ) ;
22
- var bottomPadding = viewportChildren [ viewportChildren . length - 1 ] ;
21
+ const viewportChildren = viewport . children ( ) ;
22
+ const bottomPadding = viewportChildren [ viewportChildren . length - 1 ] ;
23
23
return parseInt ( angular . element ( bottomPadding ) . css ( 'height' ) , 10 ) ;
24
24
}
25
25
26
26
function getTopPaddingHeight ( viewport ) {
27
- var viewportChildren = viewport . children ( ) ;
28
- var topPadding = viewportChildren [ 0 ] ;
27
+ const viewportChildren = viewport . children ( ) ;
28
+ const topPadding = viewportChildren [ 0 ] ;
29
29
return parseInt ( angular . element ( topPadding ) . css ( 'height' ) , 10 ) ;
30
30
}
31
31
@@ -45,53 +45,65 @@ describe('uiScroll Paddings cache', function () {
45
45
46
46
function removeItem ( datasource , index ) {
47
47
if ( index >= datasource . min && index <= datasource . max ) {
48
- var indexRemoved = datasource . data . indexOf ( datasource . data [ index - datasource . min ] ) ;
49
- datasource . data . splice ( indexRemoved , 1 ) ;
50
- if ( index === datasource . min ) {
51
- datasource . min ++ ;
48
+ const indexRemoved = datasource . data . indexOf ( datasource . data [ index - datasource . min ] ) ;
49
+ if ( indexRemoved > - 1 ) {
50
+ datasource . data . splice ( indexRemoved , 1 ) ;
51
+ if ( index === datasource . min ) {
52
+ datasource . min ++ ;
53
+ }
54
+ else {
55
+ datasource . max -- ;
56
+ }
52
57
}
53
- else {
54
- datasource . max -- ;
58
+ }
59
+ }
60
+
61
+ function insertItems ( datasource , index , items = [ ] ) {
62
+ if ( index >= datasource . min && index <= datasource . max && items . length ) {
63
+ const index = datasource . data . indexOf ( datasource . data [ index - datasource . min ] ) ;
64
+ if ( index > - 1 ) {
65
+ datasource . data . splice ( index , 0 , items ) ;
66
+ datasource . max += items . length ;
55
67
}
56
68
}
57
69
}
58
70
59
71
function checkRow ( viewport , row , content ) {
60
- var children = viewport . children ( ) ;
72
+ const children = viewport . children ( ) ;
61
73
if ( row < 0 ) { // from the end
62
74
row = children . length - 2 + row ;
63
75
}
64
- var rowElement = children [ row ] ;
76
+ const rowElement = children [ row ] ;
65
77
expect ( rowElement . innerHTML ) . toBe ( content ) ;
66
78
}
67
79
68
- it ( 'should set up properly' , function ( ) {
69
- var datasource ;
80
+ it ( 'should set up properly' , ( ) => {
81
+ let datasource ;
70
82
inject ( function ( myResponsiveDatasource ) {
71
83
datasource = myResponsiveDatasource ;
72
84
} ) ;
73
85
runTest ( scrollSettings ,
74
- function ( ) {
86
+ ( ) => {
75
87
expect ( datasource . min ) . toBe ( 1 ) ;
76
88
expect ( datasource . max ) . toBe ( itemsCount ) ;
77
89
}
78
90
) ;
79
91
} ) ;
80
92
81
- describe ( 'removing outside the buffer via indexed-based applyUpdates\n' , function ( ) {
93
+ describe ( 'removing outside the buffer via indexed-based applyUpdates\n' , ( ) => {
82
94
83
- it ( 'should delete last row' , function ( ) {
84
- var datasource ;
95
+ it ( 'should delete last row' , ( ) => {
96
+ let datasource ;
85
97
inject ( function ( myResponsiveDatasource ) {
86
98
datasource = myResponsiveDatasource ;
87
99
} ) ;
88
100
runTest ( scrollSettings ,
89
- function ( viewport , scope ) {
101
+ ( viewport , scope ) => {
90
102
91
103
scrollBottom ( viewport , MAX ) ;
92
104
scrollTop ( viewport ) ;
93
105
94
- var initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
106
+ const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
95
107
removeItem ( datasource , datasource . max ) ;
96
108
scope . adapter . applyUpdates ( itemsCount , [ ] ) ;
97
109
expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( initialBottomHeight - itemHeight ) ;
@@ -103,18 +115,18 @@ describe('uiScroll Paddings cache', function () {
103
115
) ;
104
116
} ) ;
105
117
106
- it ( 'should delete last row and then the next after last' , function ( ) {
107
- var datasource ;
118
+ it ( 'should delete last row and then the next after last' , ( ) => {
119
+ let datasource ;
108
120
inject ( function ( myResponsiveDatasource ) {
109
121
datasource = myResponsiveDatasource ;
110
122
} ) ;
111
123
runTest ( scrollSettings ,
112
- function ( viewport , scope ) {
124
+ ( viewport , scope ) => {
113
125
114
126
scrollBottom ( viewport , MAX ) ;
115
127
scrollTop ( viewport ) ;
116
128
117
- var initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
129
+ const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
118
130
removeItem ( datasource , datasource . max ) ;
119
131
scope . adapter . applyUpdates ( itemsCount , [ ] ) ;
120
132
removeItem ( datasource , datasource . max ) ;
@@ -128,17 +140,17 @@ describe('uiScroll Paddings cache', function () {
128
140
) ;
129
141
} ) ;
130
142
131
- it ( 'should delete first row' , function ( ) {
132
- var datasource ;
143
+ it ( 'should delete first row' , ( ) => {
144
+ let datasource ;
133
145
inject ( function ( myResponsiveDatasource ) {
134
146
datasource = myResponsiveDatasource ;
135
147
} ) ;
136
148
runTest ( scrollSettings ,
137
- function ( viewport , scope ) {
149
+ ( viewport , scope ) => {
138
150
139
151
scrollBottom ( viewport , MAX ) ;
140
152
141
- var initialTopHeight = getTopPaddingHeight ( viewport ) ;
153
+ const initialTopHeight = getTopPaddingHeight ( viewport ) ;
142
154
removeItem ( datasource , datasource . min ) ;
143
155
scope . adapter . applyUpdates ( 1 , [ ] ) ;
144
156
expect ( getTopPaddingHeight ( viewport ) ) . toBe ( initialTopHeight - itemHeight ) ;
@@ -150,17 +162,17 @@ describe('uiScroll Paddings cache', function () {
150
162
) ;
151
163
} ) ;
152
164
153
- it ( 'should delete first row and then the next after first' , function ( ) {
154
- var datasource ;
165
+ it ( 'should delete first row and then the next after first' , ( ) => {
166
+ let datasource ;
155
167
inject ( function ( myResponsiveDatasource ) {
156
168
datasource = myResponsiveDatasource ;
157
169
} ) ;
158
170
runTest ( scrollSettings ,
159
- function ( viewport , scope ) {
171
+ ( viewport , scope ) => {
160
172
161
173
scrollBottom ( viewport , MAX ) ;
162
174
163
- var initialTopHeight = getTopPaddingHeight ( viewport ) ;
175
+ const initialTopHeight = getTopPaddingHeight ( viewport ) ;
164
176
removeItem ( datasource , datasource . min ) ;
165
177
scope . adapter . applyUpdates ( 1 , [ ] ) ;
166
178
removeItem ( datasource , datasource . min ) ;
@@ -176,15 +188,15 @@ describe('uiScroll Paddings cache', function () {
176
188
177
189
} ) ;
178
190
179
- describe ( 'removing inside the buffer\n' , function ( ) {
191
+ describe ( 'removing inside the buffer\n' , ( ) => {
180
192
181
- it ( 'should delete second row via index-based applyUpdates' , function ( ) {
182
- var datasource ;
193
+ it ( 'should delete second row via index-based applyUpdates' , ( ) => {
194
+ let datasource ;
183
195
inject ( function ( myResponsiveDatasource ) {
184
196
datasource = myResponsiveDatasource ;
185
197
} ) ;
186
198
runTest ( scrollSettings ,
187
- function ( viewport , scope ) {
199
+ ( viewport , scope ) => {
188
200
189
201
removeItem ( datasource , datasource . min + 1 ) ;
190
202
scope . adapter . applyUpdates ( 2 , [ ] ) ;
@@ -202,20 +214,16 @@ describe('uiScroll Paddings cache', function () {
202
214
) ;
203
215
} ) ;
204
216
205
- it ( 'should delete second row via function-based applyUpdates' , function ( ) {
206
- var datasource ;
217
+ it ( 'should delete second row via function-based applyUpdates' , ( ) => {
218
+ let datasource ;
207
219
inject ( function ( myResponsiveDatasource ) {
208
220
datasource = myResponsiveDatasource ;
209
221
} ) ;
210
222
runTest ( scrollSettings ,
211
- function ( viewport , scope ) {
223
+ ( viewport , scope ) => {
212
224
213
225
removeItem ( datasource , datasource . min + 1 ) ;
214
- scope . adapter . applyUpdates ( function ( item ) {
215
- if ( item === 'item2' ) {
216
- return [ ] ;
217
- }
218
- } ) ;
226
+ scope . adapter . applyUpdates ( item => item === 'item2' ? [ ] : null ) ;
219
227
220
228
checkRow ( viewport , 1 , '1: item1' ) ;
221
229
checkRow ( viewport , 2 , '2: item3' ) ;
0 commit comments