fix(scroll): anchor scroll should scroll to IDs that are multiple levels beneath the scroll view. Closes #1804

This commit is contained in:
Perry Govier
2014-07-21 14:58:29 -05:00
parent 5b50e120a1
commit 3d0a46efe8
2 changed files with 48 additions and 5 deletions

View File

@@ -292,7 +292,12 @@ describe('$ionicScroll Controller', function() {
}));
it('.anchorScroll with el matching hash should scroll to it', inject(function($location, $document) {
$document[0].getElementById = jasmine.createSpy('byId').andCallFake(function() {
return { offsetLeft: 8, offsetTop: 9 };
return {
offsetLeft: 8,
offsetTop: 9,
attributes:[],
offsetParent:{}
};
});
spyOn($location, 'hash').andCallFake(function() {
return 'foo';
@@ -305,6 +310,37 @@ describe('$ionicScroll Controller', function() {
});
});
it('should work', function() {
var ele = {
offsetLeft: 8,
offsetTop: 9,
attributes:[],
offsetParent:{
offsetLeft: 10,
offsetTop: 11,
attributes:[],
offsetParent:{}
}
};
module('ionic', function($provide) {
$provide.value('$document', [ { getElementById: function(){ return ele; } } ]);
});
inject(function($controller, $rootScope, $location, $timeout) {
var scrollCtrl = $controller('$ionicScroll', {
$scope: $rootScope.$new(),
$element: jqLite('<div><div></div></div>'),
scrollViewOptions: { el: jqLite('<div><div></div></div>')[0] }
});
spyOn($location, 'hash').andCallFake(function() {
return 'bar';
});
spyOn(scrollCtrl.scrollView, 'scrollTo')
scrollCtrl.anchorScroll()
$timeout.flush();
expect(scrollCtrl.scrollView.scrollTo.mostRecentCall.args).toEqual([18, 20, false]);
});
});
it('should not activatePullToRefresh if setRefresher is not called', function() {
setup();
timeout.flush();