Skip to content

Commit a312083

Browse files
committed
Paddings spec refactoring: generalize datasource injection
1 parent 1c8b164 commit a312083

File tree

1 file changed

+19
-51
lines changed

1 file changed

+19
-51
lines changed

test/PaddingCacheSpec.js renamed to test/PaddingsSpec.js

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
/*global describe, beforeEach, module, it, expect, runTest */
2-
describe('uiScroll Paddings cache', () => {
2+
describe('uiScroll Paddings spec.', () => {
33
'use strict';
44

5+
let datasource;
56
beforeEach(module('ui.scroll'));
67
beforeEach(module('ui.scroll.test.datasources'));
8+
beforeEach(
9+
inject(function(myResponsiveDatasource) {
10+
datasource = myResponsiveDatasource;
11+
})
12+
);
713

814
const itemsCount = 30;
915
const itemHeight = 100;
@@ -60,9 +66,9 @@ describe('uiScroll Paddings cache', () => {
6066

6167
function insertItems(datasource, index, items = []) {
6268
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);
69+
const indexToInsert = datasource.data.indexOf(datasource.data[index - datasource.min]);
70+
if(indexToInsert > -1) {
71+
datasource.data.splice(indexToInsert, 0, items);
6672
datasource.max += items.length;
6773
}
6874
}
@@ -77,11 +83,7 @@ describe('uiScroll Paddings cache', () => {
7783
expect(rowElement.innerHTML).toBe(content);
7884
}
7985

80-
it('should set up properly', () => {
81-
let datasource;
82-
inject(function(myResponsiveDatasource) {
83-
datasource = myResponsiveDatasource;
84-
});
86+
it('\nshould set up properly', () => {
8587
runTest(scrollSettings,
8688
() => {
8789
expect(datasource.min).toBe(1);
@@ -90,13 +92,9 @@ describe('uiScroll Paddings cache', () => {
9092
);
9193
});
9294

93-
describe('removing outside the buffer via indexed-based applyUpdates\n', () => {
95+
describe('Removing outside the buffer via indexed-based applyUpdates\n', () => {
9496

9597
it('should delete last row', () => {
96-
let datasource;
97-
inject(function(myResponsiveDatasource) {
98-
datasource = myResponsiveDatasource;
99-
});
10098
runTest(scrollSettings,
10199
(viewport, scope) => {
102100

@@ -116,10 +114,6 @@ describe('uiScroll Paddings cache', () => {
116114
});
117115

118116
it('should delete last row and then the next after last', () => {
119-
let datasource;
120-
inject(function(myResponsiveDatasource) {
121-
datasource = myResponsiveDatasource;
122-
});
123117
runTest(scrollSettings,
124118
(viewport, scope) => {
125119

@@ -140,18 +134,14 @@ describe('uiScroll Paddings cache', () => {
140134
);
141135
});
142136

143-
it('should delete pre-last row', function () {
144-
var datasource;
145-
inject(function(myResponsiveDatasource) {
146-
datasource = myResponsiveDatasource;
147-
});
137+
it('should delete pre-last row', () => {
148138
runTest(scrollSettings,
149-
function (viewport, scope) {
139+
(viewport, scope) => {
150140

151141
scrollBottom(viewport, MAX);
152142
scrollTop(viewport);
153143

154-
var initialBottomHeight = getBottomPaddingHeight(viewport);
144+
const initialBottomHeight = getBottomPaddingHeight(viewport);
155145
removeItem(datasource, datasource.max - 1);
156146
scope.adapter.applyUpdates(itemsCount - 1, []);
157147
expect(getBottomPaddingHeight(viewport)).toBe(initialBottomHeight - itemHeight);
@@ -165,10 +155,6 @@ describe('uiScroll Paddings cache', () => {
165155
});
166156

167157
it('should delete first row', () => {
168-
let datasource;
169-
inject(function(myResponsiveDatasource) {
170-
datasource = myResponsiveDatasource;
171-
});
172158
runTest(scrollSettings,
173159
(viewport, scope) => {
174160

@@ -187,10 +173,6 @@ describe('uiScroll Paddings cache', () => {
187173
});
188174

189175
it('should delete first row and then the next after first', () => {
190-
let datasource;
191-
inject(function(myResponsiveDatasource) {
192-
datasource = myResponsiveDatasource;
193-
});
194176
runTest(scrollSettings,
195177
(viewport, scope) => {
196178

@@ -210,17 +192,13 @@ describe('uiScroll Paddings cache', () => {
210192
);
211193
});
212194

213-
it('should delete second', function () {
214-
var datasource;
215-
inject(function(myResponsiveDatasource) {
216-
datasource = myResponsiveDatasource;
217-
});
195+
it('should delete second', () => {
218196
runTest(scrollSettings,
219-
function (viewport, scope) {
197+
(viewport, scope) => {
220198

221199
scrollBottom(viewport, MAX);
222200

223-
var initialTopHeight = getTopPaddingHeight(viewport);
201+
const initialTopHeight = getTopPaddingHeight(viewport);
224202
removeItem(datasource, datasource.min + 1);
225203
scope.adapter.applyUpdates(2, []);
226204
expect(getTopPaddingHeight(viewport)).toBe(initialTopHeight - itemHeight * 1);
@@ -232,16 +210,11 @@ describe('uiScroll Paddings cache', () => {
232210
}
233211
);
234212
});
235-
236213
});
237214

238-
describe('removing inside the buffer\n', () => {
215+
describe('Removing inside the buffer\n', () => {
239216

240217
it('should delete second row via index-based applyUpdates', () => {
241-
let datasource;
242-
inject(function(myResponsiveDatasource) {
243-
datasource = myResponsiveDatasource;
244-
});
245218
runTest(scrollSettings,
246219
(viewport, scope) => {
247220

@@ -262,10 +235,6 @@ describe('uiScroll Paddings cache', () => {
262235
});
263236

264237
it('should delete second row via function-based applyUpdates', () => {
265-
let datasource;
266-
inject(function(myResponsiveDatasource) {
267-
datasource = myResponsiveDatasource;
268-
});
269238
runTest(scrollSettings,
270239
(viewport, scope) => {
271240

@@ -284,7 +253,6 @@ describe('uiScroll Paddings cache', () => {
284253
}
285254
);
286255
});
287-
288256
});
289257

290258
});

0 commit comments

Comments
 (0)