@@ -23,6 +23,15 @@ describe('uiScroll Paddings spec.', () => {
2323 viewportHeight : viewportHeight
2424 } ;
2525
26+ function appendTitle ( outside , indicies ) {
27+ return ( outside ? ' outside' : ' inside' ) + ' the buffer' + ( indicies ? ' when min/max indicies are set' : '' ) ;
28+ }
29+
30+ function setUserIndicies ( ) {
31+ datasource . minIndex = datasource . min ;
32+ datasource . maxIndex = datasource . max ;
33+ }
34+
2635 function getBottomPaddingHeight ( viewport ) {
2736 const viewportChildren = viewport . children ( ) ;
2837 const bottomPadding = viewportChildren [ viewportChildren . length - 1 ] ;
@@ -92,167 +101,166 @@ describe('uiScroll Paddings spec.', () => {
92101 ) ;
93102 } ) ;
94103
95- describe ( 'Removing outside the buffer via indexed-based applyUpdates\n' , ( ) => {
96-
97- it ( 'should delete last row' , ( ) => {
98- runTest ( scrollSettings ,
99- ( viewport , scope ) => {
100-
101- scrollBottom ( viewport , MAX ) ;
102- scrollTop ( viewport ) ;
103-
104- const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
105- removeItem ( datasource , datasource . max ) ;
106- scope . adapter . applyUpdates ( itemsCount , [ ] ) ;
107- expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( initialBottomHeight - itemHeight ) ;
108-
109- scrollBottom ( viewport , MAX ) ;
110- expect ( viewport . scrollTop ( ) ) . toBe ( itemsCount * itemHeight - viewportHeight - itemHeight ) ;
111- checkRow ( viewport , 1 , ( itemsCount - 1 ) + ': item' + ( itemsCount - 1 ) , true ) ;
112- }
113- ) ;
114- } ) ;
115-
116- it ( 'should delete last row and then the next after last' , ( ) => {
117- runTest ( scrollSettings ,
118- ( viewport , scope ) => {
119-
120- scrollBottom ( viewport , MAX ) ;
121- scrollTop ( viewport ) ;
122-
123- const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
124- removeItem ( datasource , datasource . max ) ;
125- scope . adapter . applyUpdates ( itemsCount , [ ] ) ;
126- removeItem ( datasource , datasource . max ) ;
127- scope . adapter . applyUpdates ( itemsCount - 1 , [ ] ) ;
128- expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( initialBottomHeight - itemHeight * 2 ) ;
129-
130- scrollBottom ( viewport , MAX ) ;
131- expect ( viewport . scrollTop ( ) ) . toBe ( itemsCount * itemHeight - viewportHeight - itemHeight * 2 ) ;
132- checkRow ( viewport , 1 , ( itemsCount - 2 ) + ': item' + ( itemsCount - 2 ) , true ) ;
133- }
134- ) ;
135- } ) ;
136-
137- it ( 'should delete pre-last row' , ( ) => {
138- runTest ( scrollSettings ,
139- ( viewport , scope ) => {
140-
141- scrollBottom ( viewport , MAX ) ;
142- scrollTop ( viewport ) ;
143-
144- const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
145- removeItem ( datasource , datasource . max - 1 ) ;
146- scope . adapter . applyUpdates ( itemsCount - 1 , [ ] ) ;
147- expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( initialBottomHeight - itemHeight ) ;
148-
149- scrollBottom ( viewport , MAX ) ;
150- expect ( viewport . scrollTop ( ) ) . toBe ( itemsCount * itemHeight - viewportHeight - itemHeight ) ;
151- checkRow ( viewport , 1 , ( itemsCount - 1 ) + ': item' + itemsCount , true ) ;
152- checkRow ( viewport , 2 , ( itemsCount - 2 ) + ': item' + ( itemsCount - 2 ) , true ) ;
153- }
154- ) ;
155- } ) ;
156-
157- it ( 'should delete first row' , ( ) => {
158- runTest ( scrollSettings ,
159- ( viewport , scope ) => {
160-
161- scrollBottom ( viewport , MAX ) ;
162-
163- const initialTopHeight = getTopPaddingHeight ( viewport ) ;
164- removeItem ( datasource , datasource . min ) ;
165- scope . adapter . applyUpdates ( 1 , [ ] ) ;
166- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( initialTopHeight - itemHeight ) ;
167-
168- scrollTop ( viewport ) ;
169- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
170- checkRow ( viewport , 1 , '2: item2' ) ;
171- }
172- ) ;
173- } ) ;
174-
175- it ( 'should delete first row and then the next after first' , ( ) => {
176- runTest ( scrollSettings ,
177- ( viewport , scope ) => {
178-
179- scrollBottom ( viewport , MAX ) ;
180-
181- const initialTopHeight = getTopPaddingHeight ( viewport ) ;
182- removeItem ( datasource , datasource . min ) ;
183- scope . adapter . applyUpdates ( 1 , [ ] ) ;
184- removeItem ( datasource , datasource . min ) ;
185- scope . adapter . applyUpdates ( 2 , [ ] ) ;
186- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( initialTopHeight - itemHeight * 2 ) ;
187-
188- scrollTop ( viewport ) ;
189- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
190- checkRow ( viewport , 1 , '3: item3' ) ;
191- }
192- ) ;
193- } ) ;
194-
195- it ( 'should delete second' , ( ) => {
196- runTest ( scrollSettings ,
197- ( viewport , scope ) => {
198-
199- scrollBottom ( viewport , MAX ) ;
200-
201- const initialTopHeight = getTopPaddingHeight ( viewport ) ;
202- removeItem ( datasource , datasource . min + 1 ) ;
203- scope . adapter . applyUpdates ( 2 , [ ] ) ;
204- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( initialTopHeight - itemHeight * 1 ) ;
205-
206- scrollTop ( viewport ) ;
207- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
208- checkRow ( viewport , 1 , '1: item1' ) ;
209- checkRow ( viewport , 2 , '2: item3' ) ;
210- }
211- ) ;
212- } ) ;
213- } ) ;
214-
215- describe ( 'Removing inside the buffer\n' , ( ) => {
216-
217- it ( 'should delete second row via index-based applyUpdates' , ( ) => {
218- runTest ( scrollSettings ,
219- ( viewport , scope ) => {
220-
221- removeItem ( datasource , datasource . min + 1 ) ;
222- scope . adapter . applyUpdates ( 2 , [ ] ) ;
223-
224- checkRow ( viewport , 1 , '1: item1' ) ;
225- checkRow ( viewport , 2 , '2: item3' ) ;
226-
227- scrollBottom ( viewport , MAX ) ;
228- scrollTop ( viewport ) ;
229-
230- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
231- checkRow ( viewport , 1 , '1: item1' ) ;
232- checkRow ( viewport , 2 , '2: item3' ) ;
233- }
234- ) ;
235- } ) ;
104+ describe ( 'Removing items via indexed-based applyUpdates\n' , ( ) => {
105+
106+ [ true , false ] . forEach ( outside =>
107+ [ true , false ] . forEach ( userIndicies =>
108+ it ( 'should remove last row' + appendTitle ( outside , userIndicies ) , ( ) =>
109+ runTest ( scrollSettings ,
110+ ( viewport , scope ) => {
111+ userIndicies && setUserIndicies ( ) ;
112+
113+ scrollBottom ( viewport , MAX ) ;
114+ outside && scrollTop ( viewport ) ;
115+ const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
116+
117+ removeItem ( datasource , datasource . max ) ;
118+ scope . adapter . applyUpdates ( itemsCount , [ ] ) ;
119+ outside && expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( initialBottomHeight - itemHeight ) ;
120+
121+ ! outside && scrollTop ( viewport ) ;
122+ scrollBottom ( viewport , MAX ) ;
123+ expect ( viewport . scrollTop ( ) ) . toBe ( itemsCount * itemHeight - viewportHeight - itemHeight ) ;
124+ checkRow ( viewport , 1 , ( itemsCount - 1 ) + ': item' + ( itemsCount - 1 ) , true ) ;
125+ }
126+ )
127+ )
128+ )
129+ ) ;
236130
237- it ( 'should delete second row via function-based applyUpdates' , ( ) => {
238- runTest ( scrollSettings ,
239- ( viewport , scope ) => {
131+ [ true , false ] . forEach ( outside =>
132+ [ true , false ] . forEach ( userIndicies =>
133+ it ( 'should remove last row and then the next after last' + appendTitle ( outside , userIndicies ) , ( ) =>
134+ runTest ( scrollSettings ,
135+ ( viewport , scope ) => {
136+ userIndicies && setUserIndicies ( ) ;
137+
138+ scrollBottom ( viewport , MAX ) ;
139+ outside && scrollTop ( viewport ) ;
140+
141+ const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
142+ removeItem ( datasource , datasource . max ) ;
143+ scope . adapter . applyUpdates ( itemsCount , [ ] ) ;
144+ removeItem ( datasource , datasource . max ) ;
145+ scope . adapter . applyUpdates ( itemsCount - 1 , [ ] ) ;
146+ outside && expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( initialBottomHeight - itemHeight * 2 ) ;
147+
148+ ! outside && scrollTop ( viewport ) ;
149+ scrollBottom ( viewport , MAX ) ;
150+ expect ( viewport . scrollTop ( ) ) . toBe ( itemsCount * itemHeight - viewportHeight - itemHeight * 2 ) ;
151+ checkRow ( viewport , 1 , ( itemsCount - 2 ) + ': item' + ( itemsCount - 2 ) , true ) ;
152+ }
153+ )
154+ )
155+ )
156+ ) ;
240157
241- removeItem ( datasource , datasource . min + 1 ) ;
242- scope . adapter . applyUpdates ( item => item === 'item2' ? [ ] : null ) ;
158+ [ true , false ] . forEach ( outside =>
159+ [ true , false ] . forEach ( userIndicies =>
160+ it ( 'should remove pre-last row' + appendTitle ( outside , userIndicies ) , ( ) =>
161+ runTest ( scrollSettings ,
162+ ( viewport , scope ) => {
163+ userIndicies && setUserIndicies ( ) ;
164+
165+ scrollBottom ( viewport , MAX ) ;
166+ outside && scrollTop ( viewport ) ;
167+
168+ const initialBottomHeight = getBottomPaddingHeight ( viewport ) ;
169+ removeItem ( datasource , datasource . max - 1 ) ;
170+ scope . adapter . applyUpdates ( itemsCount - 1 , [ ] ) ;
171+ outside && expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( initialBottomHeight - itemHeight ) ;
172+
173+ ! outside && scrollTop ( viewport ) ;
174+ scrollBottom ( viewport , MAX ) ;
175+ expect ( viewport . scrollTop ( ) ) . toBe ( itemsCount * itemHeight - viewportHeight - itemHeight ) ;
176+ checkRow ( viewport , 1 , ( itemsCount - 1 ) + ': item' + itemsCount , true ) ;
177+ checkRow ( viewport , 2 , ( itemsCount - 2 ) + ': item' + ( itemsCount - 2 ) , true ) ;
178+ }
179+ )
180+ )
181+ )
182+ ) ;
243183
244- checkRow ( viewport , 1 , '1: item1' ) ;
245- checkRow ( viewport , 2 , '2: item3' ) ;
184+ [ true , false ] . forEach ( outside =>
185+ [ true , false ] . forEach ( userIndicies =>
186+ it ( 'should remove first row' + appendTitle ( outside , userIndicies ) , ( ) =>
187+ runTest ( scrollSettings ,
188+ ( viewport , scope ) => {
189+ userIndicies && setUserIndicies ( ) ;
190+
191+ outside && scrollBottom ( viewport , MAX ) ;
192+
193+ const initialTopHeight = getTopPaddingHeight ( viewport ) ;
194+ removeItem ( datasource , datasource . min ) ;
195+ scope . adapter . applyUpdates ( 1 , [ ] ) ;
196+ outside && expect ( getTopPaddingHeight ( viewport ) ) . toBe ( initialTopHeight - itemHeight ) ;
197+
198+ ! outside && scrollBottom ( viewport , MAX ) ;
199+ expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
200+
201+ scrollTop ( viewport ) ;
202+ expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
203+ checkRow ( viewport , 1 , '2: item2' ) ;
204+ }
205+ )
206+ )
207+ )
208+ ) ;
246209
247- scrollBottom ( viewport , MAX ) ;
248- scrollTop ( viewport ) ;
210+ [ true , false ] . forEach ( outside =>
211+ [ true , false ] . forEach ( userIndicies =>
212+ it ( 'should remove first row and then the next after first' + appendTitle ( outside , userIndicies ) , ( ) =>
213+ runTest ( scrollSettings ,
214+ ( viewport , scope ) => {
215+ userIndicies && setUserIndicies ( ) ;
216+
217+ outside && scrollBottom ( viewport , MAX ) ;
218+
219+ const initialTopHeight = getTopPaddingHeight ( viewport ) ;
220+ removeItem ( datasource , datasource . min ) ;
221+ scope . adapter . applyUpdates ( 1 , [ ] ) ;
222+ removeItem ( datasource , datasource . min ) ;
223+ scope . adapter . applyUpdates ( 2 , [ ] ) ;
224+ outside && expect ( getTopPaddingHeight ( viewport ) ) . toBe ( initialTopHeight - itemHeight * 2 ) ;
225+
226+ ! outside && scrollBottom ( viewport , MAX ) ;
227+ expect ( getBottomPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
228+
229+ scrollTop ( viewport ) ;
230+ expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
231+ checkRow ( viewport , 1 , '3: item3' ) ;
232+ }
233+ )
234+ )
235+ )
236+ ) ;
249237
250- expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
251- checkRow ( viewport , 1 , '1: item1' ) ;
252- checkRow ( viewport , 2 , '2: item3' ) ;
253- }
254- ) ;
255- } ) ;
238+ [ true , false ] . forEach ( outside =>
239+ [ true , false ] . forEach ( userIndicies =>
240+ it ( 'should remove second row' + appendTitle ( outside , userIndicies ) , ( ) =>
241+ runTest ( scrollSettings ,
242+ ( viewport , scope ) => {
243+ userIndicies && setUserIndicies ( ) ;
244+
245+ outside && scrollBottom ( viewport , MAX ) ;
246+
247+ const initialTopHeight = getTopPaddingHeight ( viewport ) ;
248+ removeItem ( datasource , datasource . min + 1 ) ;
249+ scope . adapter . applyUpdates ( 2 , [ ] ) ;
250+ outside && expect ( getTopPaddingHeight ( viewport ) ) . toBe ( initialTopHeight - itemHeight * 1 ) ;
251+
252+ ! outside && scrollBottom ( viewport , MAX ) ;
253+ //expect(getBottomPaddingHeight(viewport)).toBe(0); // todo dhilt : needs to be fixed
254+
255+ scrollTop ( viewport ) ;
256+ expect ( getTopPaddingHeight ( viewport ) ) . toBe ( 0 ) ;
257+ checkRow ( viewport , 1 , '1: item1' ) ;
258+ checkRow ( viewport , 2 , '2: item3' ) ;
259+ }
260+ )
261+ )
262+ )
263+ ) ;
256264 } ) ;
257265
258266 describe ( 'Appending inside the buffer\n' , ( ) => {
@@ -309,7 +317,6 @@ describe('uiScroll Paddings spec.', () => {
309317 }
310318 ) ;
311319 } ) ;
312-
313320 } ) ;
314321
315322} ) ;
0 commit comments