feat($ionicScrollDelegate): rememberScrollPosition, scrollToRememberedPosition

/**
 * @ngdoc method
 * @name $ionicScrollDelegate#rememberScrollPosition
 * @description
 *
 * When this scroll area is destroyed, its last scroll position will be
 * saved using the given id.
 *
 * @param {string} id The identifier for this saved scroll position.
 */

/**
 * @ngdoc method
 * @name $ionicScrollDelegate#scrollToRememberedPosition
 * @description
 *
 * If a scroll position was remembered using the given id, loads the
 * remembered scroll position and scrolls there.
 *
 * @param {string} id The identifier for this saved scroll position.
 * @param {boolean=} shouldAnimate Whether to animate the scroll.
 */
This commit is contained in:
Andy Joslin
2014-03-17 08:39:23 -06:00
parent cc0a4ef775
commit 5a0efecef6
8 changed files with 159 additions and 98 deletions

View File

@@ -11,6 +11,13 @@ describe('Ionic ScrollDelegate Service', function() {
compile = $compile;
}));
it('should just return rootScope if no scrollCtrl', inject(function($rootScope) {
expect(function() {
$ionicScrollDelegate($rootScope);
}).not.toThrow();
expect($ionicScrollDelegate($rootScope).getScrollView()).toBeFalsy();
}));
it('Should get scroll view', function() {
var scope = rootScope.$new();
var el = compile('<ion-content></ion-content>')(scope);
@@ -137,6 +144,50 @@ describe('Ionic ScrollDelegate Service', function() {
expect(sv.resize).toHaveBeenCalled();
expect(sv.scrollTo.mostRecentCall.args).toEqual([2, 3, animate]);
});
it('should throw error on rememberScroll if no id', function() {
var scope = rootScope.$new();
var el = compile('<ion-content></ion-content>');
var del = $ionicScrollDelegate(scope);
expect(del.rememberScrollPosition).toThrow();
});
it('scrollToRememberedPosition should scroll if exists', function() {
var scope = rootScope.$new();
var el = compile('<ion-content></ion-content>')(scope);
var del = $ionicScrollDelegate(scope);
var sv = del.getScrollView();
scope.$apply();
$ionicScrollDelegate._rememberedScrollValues['1'] = {
left: 3,
top: 4
};
del.scrollToRememberedPosition('1', animate);
spyOn(sv, 'scrollTo');
timeout.flush();
expect(sv.scrollTo).toHaveBeenCalledWith(3, 4, animate);
});
it('should save on destroy for rememberScrollPosition', function() {
var scope = rootScope.$new();
var el = compile('<ion-content></ion-content>')(scope);
var del = $ionicScrollDelegate(scope);
var sv = del.getScrollView();
scope.$apply();
$ionicScrollDelegate._rememberedScrollValues['1'] = {
left: -1,
top: -1
};
del.rememberScrollPosition('1', animate);
spyOn(sv, 'getValues').andCallFake(function() {
return { foo: 'bar' };
});
scope.$destroy();
expect(sv.getValues).toHaveBeenCalled();
expect($ionicScrollDelegate._rememberedScrollValues['1']).toEqual({
foo: 'bar'
});
});
});
}
});