Skip to content

Commit fc623ed

Browse files
committed
bufferSize attribute scope binding tests
1 parent 340d789 commit fc623ed

File tree

2 files changed

+72
-44
lines changed

2 files changed

+72
-44
lines changed

test/BasicTestsSpec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,36 @@ describe('uiScroll', function () {
807807

808808
});
809809

810+
describe('attributes scope binding', function () {
811+
var calls = null;
812+
var bufferSize = 5;
813+
814+
it('bufferSize scope binding should work (1)', function () {
815+
inject(function (myInfiniteDatasource) {
816+
var spy = spyOn(myInfiniteDatasource, 'get').and.callThrough();
817+
runTest({datasource: 'myInfiniteDatasource', bufferSize: bufferSize},
818+
function () {
819+
calls = spy.calls.all().length;
820+
expect(calls > 0).toBe(true);
821+
}
822+
);
823+
});
824+
});
825+
826+
it('bufferSize scope binding should work (2)', function () {
827+
inject(function (myInfiniteDatasource) {
828+
var spy = spyOn(myInfiniteDatasource, 'get').and.callThrough();
829+
runTest({datasource: 'myInfiniteDatasource', bufferSize: 'start'},
830+
function () {
831+
expect(spy.calls.all().length).toBe(calls);
832+
}, {
833+
scope: {
834+
'start': bufferSize
835+
}
836+
}
837+
);
838+
});
839+
});
840+
});
841+
810842
});

test/scaffolding.js

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var createHtml = function (settings) {
1+
function createHtml (settings) {
22
var viewportStyle = ' style="height:' + (settings.viewportHeight || 200) + 'px"';
33
var itemStyle = settings.itemHeight ? ' style="height:' + settings.itemHeight + 'px"' : '';
44
var bufferSize = settings.bufferSize ? ' buffer-size="' + settings.bufferSize + '"' : '';
@@ -14,38 +14,9 @@ var createHtml = function (settings) {
1414
template +
1515
'</div>' +
1616
'</div>';
17-
};
17+
}
1818

19-
var runTest = function (scrollSettings, run, options) {
20-
inject(function ($rootScope, $compile, $window, $timeout) {
21-
var scroller = angular.element(createHtml(scrollSettings));
22-
var scope = $rootScope.$new();
23-
24-
//if (angular.element(document).find('body').find('div').children().length)
25-
//debugger
26-
27-
angular.element(document).find('body').append(scroller);
28-
29-
$compile(scroller)(scope);
30-
31-
scope.$apply();
32-
$timeout.flush();
33-
34-
try {
35-
run(scroller, scope, $timeout);
36-
}
37-
finally {
38-
scroller.remove();
39-
40-
if (options && typeof options.cleanupTest === 'function') {
41-
options.cleanupTest(scroller, scope, $timeout);
42-
}
43-
}
44-
45-
});
46-
};
47-
48-
var createGridHtml = function (settings) {
19+
function createGridHtml (settings) {
4920
var viewportStyle = ' style="height:' + (settings.viewportHeight || 200) + 'px"';
5021
var columns = ['col0', 'col1', 'col2', 'col3'];
5122

@@ -67,16 +38,46 @@ var createGridHtml = function (settings) {
6738
'</tbody>' +
6839
'</table>';
6940
return html;
41+
}
7042

71-
};
43+
function finalize (scroller, options, scope, $timeout) {
44+
scroller.remove();
7245

73-
var runGridTest = function (scrollSettings, run, options) {
46+
if (options && typeof options.cleanupTest === 'function') {
47+
options.cleanupTest(scroller, scope, $timeout);
48+
}
49+
}
50+
51+
function runTest (scrollSettings, run, options) {
7452
inject(function ($rootScope, $compile, $window, $timeout) {
75-
var scroller = angular.element(createGridHtml(scrollSettings));
53+
var scroller = angular.element(createHtml(scrollSettings));
7654
var scope = $rootScope.$new();
7755

78-
//if (angular.element(document).find('body').find('div').children().length)
79-
//debugger
56+
angular.element(document).find('body').append(scroller);
57+
58+
if(options && options.scope) {
59+
angular.extend(scope, options.scope);
60+
}
61+
62+
$compile(scroller)(scope);
63+
64+
scope.$apply();
65+
$timeout.flush();
66+
67+
try {
68+
run(scroller, scope, $timeout);
69+
}
70+
finally {
71+
finalize(scroller, options, scope, $timeout);
72+
}
73+
74+
});
75+
}
76+
77+
function runGridTest (scrollSettings, run, options) {
78+
inject(function ($rootScope, $compile, $window, $timeout) {
79+
var scroller = angular.element(createGridHtml(scrollSettings));
80+
var scope = $rootScope.$new();
8081

8182
angular.element(document).find('body').append(scroller);
8283
var head = angular.element(scroller.children()[0]);
@@ -90,14 +91,9 @@ var runGridTest = function (scrollSettings, run, options) {
9091
try {
9192
run(head, body, scope, $timeout);
9293
} finally {
93-
scroller.remove();
94-
95-
if (options && typeof options.cleanupTest === 'function') {
96-
options.cleanupTest(scroller, scope, $timeout);
97-
}
94+
finalize(scroller, options, scope, $timeout);
9895
}
9996

10097
}
10198
);
102-
};
103-
99+
}

0 commit comments

Comments
 (0)