Skip to content

Commit 1c8b164

Browse files
committed
Merge branch 'paddings-cache' of github.com:angular-ui/ui-scroll into paddings-cache
# Conflicts: # test/PaddingCacheSpec.js
2 parents b9bdd98 + 36e52c4 commit 1c8b164

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

test/PaddingCacheSpec.js

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ describe('uiScroll Paddings cache', () => {
6868
}
6969
}
7070

71-
function checkRow(viewport, row, content) {
72-
const children = viewport.children();
73-
if(row < 0) { // from the end
74-
row = children.length - 2 + row;
71+
function checkRow(viewport, row, content, tail = false) {
72+
var children = viewport.children();
73+
if(tail) {
74+
row = children.length - 1 - row;
7575
}
7676
const rowElement = children[row];
7777
expect(rowElement.innerHTML).toBe(content);
@@ -110,7 +110,7 @@ describe('uiScroll Paddings cache', () => {
110110

111111
scrollBottom(viewport, MAX);
112112
expect(viewport.scrollTop()).toBe(itemsCount * itemHeight - viewportHeight - itemHeight);
113-
checkRow(viewport, -1, (itemsCount - 2) + ': item' + (itemsCount - 2));
113+
checkRow(viewport, 1, (itemsCount - 1) + ': item' + (itemsCount - 1), true);
114114
}
115115
);
116116
});
@@ -135,7 +135,31 @@ describe('uiScroll Paddings cache', () => {
135135

136136
scrollBottom(viewport, MAX);
137137
expect(viewport.scrollTop()).toBe(itemsCount * itemHeight - viewportHeight - itemHeight * 2);
138-
checkRow(viewport, -1, (itemsCount - 3) + ': item' + (itemsCount - 3));
138+
checkRow(viewport, 1, (itemsCount - 2) + ': item' + (itemsCount - 2), true);
139+
}
140+
);
141+
});
142+
143+
it('should delete pre-last row', function () {
144+
var datasource;
145+
inject(function(myResponsiveDatasource) {
146+
datasource = myResponsiveDatasource;
147+
});
148+
runTest(scrollSettings,
149+
function (viewport, scope) {
150+
151+
scrollBottom(viewport, MAX);
152+
scrollTop(viewport);
153+
154+
var initialBottomHeight = getBottomPaddingHeight(viewport);
155+
removeItem(datasource, datasource.max - 1);
156+
scope.adapter.applyUpdates(itemsCount - 1, []);
157+
expect(getBottomPaddingHeight(viewport)).toBe(initialBottomHeight - itemHeight);
158+
159+
scrollBottom(viewport, MAX);
160+
expect(viewport.scrollTop()).toBe(itemsCount * itemHeight - viewportHeight - itemHeight);
161+
checkRow(viewport, 1, (itemsCount - 1) + ': item' + itemsCount, true);
162+
checkRow(viewport, 2, (itemsCount - 2) + ': item' + (itemsCount - 2), true);
139163
}
140164
);
141165
});
@@ -186,6 +210,29 @@ describe('uiScroll Paddings cache', () => {
186210
);
187211
});
188212

213+
it('should delete second', function () {
214+
var datasource;
215+
inject(function(myResponsiveDatasource) {
216+
datasource = myResponsiveDatasource;
217+
});
218+
runTest(scrollSettings,
219+
function (viewport, scope) {
220+
221+
scrollBottom(viewport, MAX);
222+
223+
var initialTopHeight = getTopPaddingHeight(viewport);
224+
removeItem(datasource, datasource.min + 1);
225+
scope.adapter.applyUpdates(2, []);
226+
expect(getTopPaddingHeight(viewport)).toBe(initialTopHeight - itemHeight * 1);
227+
228+
scrollTop(viewport);
229+
expect(getTopPaddingHeight(viewport)).toBe(0);
230+
checkRow(viewport, 1, '1: item1');
231+
checkRow(viewport, 2, '2: item3');
232+
}
233+
);
234+
});
235+
189236
});
190237

191238
describe('removing inside the buffer\n', () => {

0 commit comments

Comments
 (0)