From da344daa4023556f8abbef6d8ad87a16362b5861 Mon Sep 17 00:00:00 2001
From: Jeff Cross
Date: Tue, 5 Nov 2013 23:53:00 -0800
Subject: fix(ngView): only run anchorScroll after animation is done
---
test/ngRoute/directive/ngViewSpec.js | 102 +++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
(limited to 'test')
diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js
index bfcb0929..1df19d6a 100644
--- a/test/ngRoute/directive/ngViewSpec.js
+++ b/test/ngRoute/directive/ngViewSpec.js
@@ -698,4 +698,106 @@ describe('ngView animations', function() {
}
});
});
+
+
+ describe('autoscroll', function () {
+ var autoScrollSpy;
+
+ function spyOnAnchorScroll() {
+ return function($provide, $routeProvider) {
+ autoScrollSpy = jasmine.createSpy('$anchorScroll');
+ $provide.value('$anchorScroll', autoScrollSpy);
+ $routeProvider.when('/foo', {
+ controller: angular.noop,
+ template: '
'
+ });
+ };
+ }
+
+ function spyOnAnimateEnter() {
+ return function($animate) {
+ spyOn($animate, 'enter').andCallThrough();
+ };
+ }
+
+ function compileAndLink(tpl) {
+ return function($compile, $rootScope, $location) {
+ element = $compile(tpl)($rootScope);
+ };
+ }
+
+ beforeEach(module(spyOnAnchorScroll(), 'mock.animate'));
+ beforeEach(inject(spyOnAnimateEnter()));
+
+ it('should call $anchorScroll if autoscroll attribute is present', inject(
+ compileAndLink('
'),
+ function($rootScope, $animate, $timeout, $location) {
+
+ $location.path('/foo');
+ $rootScope.$digest();
+ $animate.flushNext('enter');
+ $timeout.flush();
+
+ expect(autoScrollSpy).toHaveBeenCalledOnce();
+ }));
+
+
+ it('should call $anchorScroll if autoscroll evaluates to true', inject(
+ compileAndLink('
'),
+ function($rootScope, $animate, $timeout, $location) {
+
+ $rootScope.value = true;
+ $location.path('/foo');
+ $rootScope.$digest();
+ $animate.flushNext('enter');
+ $timeout.flush();
+
+ expect(autoScrollSpy).toHaveBeenCalledOnce();
+ }));
+
+
+ it('should not call $anchorScroll if autoscroll attribute is not present', inject(
+ compileAndLink('
'),
+ function($rootScope, $location, $animate, $timeout) {
+
+ $location.path('/foo');
+ $rootScope.$digest();
+ $animate.flushNext('enter');
+ $timeout.flush();
+
+ expect(autoScrollSpy).not.toHaveBeenCalled();
+ }));
+
+
+ it('should not call $anchorScroll if autoscroll evaluates to false', inject(
+ compileAndLink('
'),
+ function($rootScope, $location, $animate, $timeout) {
+
+ $rootScope.value = false;
+ $location.path('/foo');
+ $rootScope.$digest();
+ $animate.flushNext('enter');
+ $timeout.flush();
+
+ expect(autoScrollSpy).not.toHaveBeenCalled();
+ }));
+
+
+ it('should only call $anchorScroll after the "enter" animation completes', inject(
+ compileAndLink('
'),
+ function($rootScope, $location, $animate, $timeout) {
+ $location.path('/foo');
+
+ expect($animate.enter).not.toHaveBeenCalled();
+ $rootScope.$digest();
+
+ expect(autoScrollSpy).not.toHaveBeenCalled();
+
+ $animate.flushNext('enter');
+ $timeout.flush();
+
+ expect($animate.enter).toHaveBeenCalledOnce();
+ expect(autoScrollSpy).toHaveBeenCalledOnce();
+ }));
+ });
});
--
cgit v1.2.3