Skip to content

Commit 099997c

Browse files
committed
topVisible tests
1 parent bbabb9b commit 099997c

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

test/BasicTestsSpec.js

+96
Original file line numberDiff line numberDiff line change
@@ -713,4 +713,100 @@ describe('uiScroll', function () {
713713

714714
});
715715

716+
describe('topVisible property: deep access and sync', function () {
717+
718+
it('should get topVisible as an adapter property', function () {
719+
runTest({datasource: 'myMultipageDatasource', adapter: 'adapterContainer.innerContainer.adapter'},
720+
function (viewport, scope) {
721+
expect(!!scope.adapterContainer && !!scope.adapterContainer.innerContainer && !!scope.adapterContainer.innerContainer.adapter).toBe(true);
722+
expect(angular.isString(scope.adapterContainer.innerContainer.adapter.topVisible)).toBe(true);
723+
}
724+
);
725+
});
726+
727+
it('should get topVisible as a scope property', function () {
728+
runTest({datasource: 'myMultipageDatasource', topVisible: 'scopeContainer.innerContainer.topVisible'},
729+
function (viewport, scope) {
730+
expect(!!scope.scopeContainer && !!scope.scopeContainer.innerContainer).toBe(true);
731+
expect(angular.isString(scope.scopeContainer.innerContainer.topVisible)).toBe(true);
732+
}
733+
);
734+
});
735+
736+
it('should sync scope-topVisible with adapter-topVisible', function () {
737+
runTest({
738+
datasource: 'myMultipageDatasource',
739+
itemHeight: 40,
740+
bufferSize: 3,
741+
adapter: 'container1.adapter',
742+
topVisible: 'container2.topVisible'
743+
},
744+
function (viewport, scope, $timeout) {
745+
var topVisibleChangeCount = 0;
746+
747+
scope.$watch('container1.adapter.topVisible', function(newValue) {
748+
topVisibleChangeCount++;
749+
750+
expect(scope.container1.adapter.topVisible).toBe(newValue);
751+
expect(scope.container2.topVisible).toBe(newValue);
752+
753+
if(topVisibleChangeCount === 1) {
754+
expect(newValue).toBe('item3');
755+
}
756+
else if(topVisibleChangeCount === 2) {
757+
expect(newValue).toBe('item8');
758+
}
759+
});
760+
761+
viewport.scrollTop(100); // 100 : 40 = 2.5 --> item3
762+
viewport.trigger('scroll');
763+
$timeout.flush();
764+
765+
viewport.scrollTop(300); // 300 : 40 = 7.5 --> item8
766+
viewport.trigger('scroll');
767+
$timeout.flush();
768+
769+
expect(topVisibleChangeCount).toBe(2);
770+
}
771+
);
772+
});
773+
774+
it('should sync scope-topVisible with adapter-topVisible in case of single fetch', function () {
775+
runTest({
776+
datasource: 'myOneBigPageDatasource',
777+
itemHeight: 40,
778+
bufferSize: 3,
779+
adapter: 'container1.adapter',
780+
topVisible: 'container2.topVisible'
781+
},
782+
function (viewport, scope) {
783+
var topVisibleChangeCount = 0;
784+
785+
scope.$watch('container1.adapter.topVisible', function(newValue) {
786+
topVisibleChangeCount++;
787+
788+
expect(scope.container1.adapter.topVisible).toBe(newValue);
789+
expect(scope.container2.topVisible).toBe(newValue);
790+
791+
if(topVisibleChangeCount === 1) {
792+
expect(newValue).toBe('item3');
793+
}
794+
else if(topVisibleChangeCount === 2) {
795+
expect(newValue).toBe('item8');
796+
}
797+
});
798+
799+
viewport.scrollTop(100); // 100 : 40 = 2.5 --> item3
800+
viewport.trigger('scroll');
801+
802+
viewport.scrollTop(300); // 300 : 40 = 7.5 --> item8
803+
viewport.trigger('scroll');
804+
805+
expect(topVisibleChangeCount).toBe(2);
806+
}
807+
);
808+
});
809+
810+
});
811+
716812
});

test/datasources.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ angular.module('ui.scroll.test.datasources', [])
1515

1616
// another layer of indirection introduced by the actualGet
1717
// is a workaround for the jasmine issue #1007 https://github.com/jasmine/jasmine/issues/1007
18-
result = {
18+
var result = {
1919
get: function (descriptor, success) {
2020
result.actualGet(descriptor, success);
2121
},
@@ -43,12 +43,30 @@ angular.module('ui.scroll.test.datasources', [])
4343
}
4444
])
4545

46+
.factory('myOneBigPageDatasource', [
47+
'$log', '$timeout', '$rootScope', function () {
48+
return {
49+
get: function (index, count, success) {
50+
if (index === 1) {
51+
var resultList = [];
52+
for(var i = 1; i < 100; i++) {
53+
resultList.push('item' + i);
54+
}
55+
success(resultList);
56+
} else {
57+
success([]);
58+
}
59+
}
60+
};
61+
}
62+
])
63+
4664
.factory('myNewOnePageDatasource', [
4765
'$log', '$timeout', '$rootScope', function () {
4866

4967
// another layer of indirection introduced by the actualGet
5068
// is a workaround for the jasmine issue #1007 https://github.com/jasmine/jasmine/issues/1007
51-
result = {
69+
var result = {
5270
get: function (descriptor, success) {
5371
result.actualGet(descriptor, success);
5472
},

test/scaffolding.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ var createHtml = function (settings) {
33
var itemStyle = settings.itemHeight ? ' style="height:' + settings.itemHeight + 'px"' : '';
44
var bufferSize = settings.bufferSize ? ' buffer-size="' + settings.bufferSize + '"' : '';
55
var isLoading = settings.isLoading ? ' is-loading="' + settings.isLoading + '"' : '';
6+
var topVisible = settings.topVisible ? ' top-visible="' + settings.topVisible + '"' : '';
67
var adapter = settings.adapter ? ' adapter="' + settings.adapter + '"' : '';
78
var template = settings.template ? settings.template : '{{$index}}: {{item}}';
89
return '<div ui-scroll-viewport' + viewportStyle + '>' +
910
'<div ui-scroll="item in ' + settings.datasource + '"' +
1011
adapter +
11-
itemStyle + bufferSize + isLoading + '>' +
12+
itemStyle + bufferSize + isLoading + topVisible + '>' +
1213
template +
1314
'</div>' +
1415
'</div>';

0 commit comments

Comments
 (0)