Skip to content

Commit 36e52c4

Browse files
committed
2 tests for Paddings cache: removing second and pre-last items out-of-buffer
1 parent 69eef67 commit 36e52c4

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

test/PaddingCacheSpec.js

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ describe('uiScroll Paddings cache', function () {
5656
}
5757
}
5858

59-
function checkRow(viewport, row, content) {
59+
function checkRow(viewport, row, content, tail = false) {
6060
var children = viewport.children();
61-
if(row < 0) { // from the end
62-
row = children.length - 2 + row;
61+
if(tail) {
62+
row = children.length - 1 - row;
6363
}
6464
var rowElement = children[row];
6565
expect(rowElement.innerHTML).toBe(content);
@@ -98,7 +98,7 @@ describe('uiScroll Paddings cache', function () {
9898

9999
scrollBottom(viewport, MAX);
100100
expect(viewport.scrollTop()).toBe(itemsCount * itemHeight - viewportHeight - itemHeight);
101-
checkRow(viewport, -1, (itemsCount - 2) + ': item' + (itemsCount - 2));
101+
checkRow(viewport, 1, (itemsCount - 1) + ': item' + (itemsCount - 1), true);
102102
}
103103
);
104104
});
@@ -123,7 +123,31 @@ describe('uiScroll Paddings cache', function () {
123123

124124
scrollBottom(viewport, MAX);
125125
expect(viewport.scrollTop()).toBe(itemsCount * itemHeight - viewportHeight - itemHeight * 2);
126-
checkRow(viewport, -1, (itemsCount - 3) + ': item' + (itemsCount - 3));
126+
checkRow(viewport, 1, (itemsCount - 2) + ': item' + (itemsCount - 2), true);
127+
}
128+
);
129+
});
130+
131+
it('should delete pre-last row', function () {
132+
var datasource;
133+
inject(function(myResponsiveDatasource) {
134+
datasource = myResponsiveDatasource;
135+
});
136+
runTest(scrollSettings,
137+
function (viewport, scope) {
138+
139+
scrollBottom(viewport, MAX);
140+
scrollTop(viewport);
141+
142+
var initialBottomHeight = getBottomPaddingHeight(viewport);
143+
removeItem(datasource, datasource.max - 1);
144+
scope.adapter.applyUpdates(itemsCount - 1, []);
145+
expect(getBottomPaddingHeight(viewport)).toBe(initialBottomHeight - itemHeight);
146+
147+
scrollBottom(viewport, MAX);
148+
expect(viewport.scrollTop()).toBe(itemsCount * itemHeight - viewportHeight - itemHeight);
149+
checkRow(viewport, 1, (itemsCount - 1) + ': item' + itemsCount, true);
150+
checkRow(viewport, 2, (itemsCount - 2) + ': item' + (itemsCount - 2), true);
127151
}
128152
);
129153
});
@@ -174,6 +198,29 @@ describe('uiScroll Paddings cache', function () {
174198
);
175199
});
176200

201+
it('should delete second', function () {
202+
var datasource;
203+
inject(function(myResponsiveDatasource) {
204+
datasource = myResponsiveDatasource;
205+
});
206+
runTest(scrollSettings,
207+
function (viewport, scope) {
208+
209+
scrollBottom(viewport, MAX);
210+
211+
var initialTopHeight = getTopPaddingHeight(viewport);
212+
removeItem(datasource, datasource.min + 1);
213+
scope.adapter.applyUpdates(2, []);
214+
expect(getTopPaddingHeight(viewport)).toBe(initialTopHeight - itemHeight * 1);
215+
216+
scrollTop(viewport);
217+
expect(getTopPaddingHeight(viewport)).toBe(0);
218+
checkRow(viewport, 1, '1: item1');
219+
checkRow(viewport, 2, '2: item3');
220+
}
221+
);
222+
});
223+
177224
});
178225

179226
describe('removing inside the buffer\n', function () {

0 commit comments

Comments
 (0)