Skip to content

Commit fde44a6

Browse files
committed
one more (more complete) test for the new get signature
1 parent eeb8593 commit fde44a6

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

test/BasicTestsSpec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,36 @@ describe('uiScroll', function () {
4242
});
4343
});
4444

45+
describe('datasource with 3 elements and buffersize 3 (new get signature)', function() {
46+
var scrollSettings = { datasource: 'myNewOnePageDatasource', bufferSize: 3 };
47+
48+
it('should call get on the datasource 3 times ', function () {
49+
var spy;
50+
inject(function (myNewOnePageDatasource) {
51+
spy = spyOn(myNewOnePageDatasource, 'actualGet').and.callThrough();
52+
runTest(scrollSettings,
53+
function () {
54+
expect(spy.calls.all().length).toBe(3);
55+
expect(spy.calls.all()[0].args[0].index).toBe(1); // gets 3 rows (no eof)
56+
expect(spy.calls.all()[0].args[0].count).toBe(3);
57+
expect('append' in spy.calls.all()[0].args[0]).toBe(true);
58+
expect(spy.calls.all()[0].args[0].append).toBeUndefined();
59+
expect('prepend' in spy.calls.all()[0].args[0]).toBe(false);
60+
expect(spy.calls.all()[1].args[0].index).toBe(4); // gets 0 rows (and eof)
61+
expect(spy.calls.all()[1].args[0].count).toBe(3);
62+
expect('append' in spy.calls.all()[1].args[0]).toBe(true);
63+
expect(spy.calls.all()[1].args[0].append).toBe('three');
64+
expect('prepend' in spy.calls.all()[1].args[0]).toBe(false);
65+
expect(spy.calls.all()[2].args[0].index).toBe(-2); // gets 0 rows (and bof)
66+
expect(spy.calls.all()[2].args[0].count).toBe(3);
67+
expect('append' in spy.calls.all()[2].args[0]).toBe(false);
68+
expect('prepend' in spy.calls.all()[2].args[0]).toBe(true);
69+
expect(spy.calls.all()[2].args[0].prepend).toBe('one');
70+
});
71+
});
72+
});
73+
});
74+
4575
describe('datasource with only 3 elements (negative index)', function () {
4676
var scrollSettings = { datasource: 'anotherDatasource' };
4777
it('should create 3 divs with data (+ 2 padding divs)', function () {

test/datasources.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ angular.module('ui.scroll.test.datasources', [])
4343
}
4444
])
4545

46+
.factory('myNewOnePageDatasource', [
47+
'$log', '$timeout', '$rootScope', function () {
48+
49+
// another layer of indirection introduced by the actualGet
50+
// is a workaround for the jasmine issue #1007 https://github.com/jasmine/jasmine/issues/1007
51+
result = {
52+
get: function (descriptor, success) {
53+
result.actualGet(descriptor, success);
54+
},
55+
actualGet: function (descriptor, success) {
56+
if (descriptor.index === 1) {
57+
success(['one', 'two', 'three']);
58+
} else {
59+
success([]);
60+
}
61+
}
62+
};
63+
64+
return result;
65+
66+
}
67+
])
68+
4669
.factory('myObjectDatasource', [
4770
'$log', '$timeout', '$rootScope', function () {
4871
return {

0 commit comments

Comments
 (0)