fix($anchorScroll): don't scroll to top when initializing and location hash is empty

Closes #8848
Closes #9393
This commit is contained in:
Igor Minar
2014-10-02 09:41:47 -07:00
parent df1a00b11a
commit d5445c601f
2 changed files with 21 additions and 1 deletions

View File

@@ -106,6 +106,12 @@ describe('$anchorScroll', function() {
describe('watcher', function() {
function initAnchorScroll() {
return function($rootScope, $anchorScroll) {
$rootScope.$digest();
};
}
function initLocation(config) {
return function($provide, $locationProvider) {
$provide.value('$sniffer', {history: config.historyApi});
@@ -135,6 +141,7 @@ describe('$anchorScroll', function() {
it('should scroll to element when hash change in hashbang mode', function() {
module(initLocation({html5Mode: false, historyApi: true}));
inject(
initAnchorScroll(),
addElements('id=some'),
changeHashTo('some'),
expectScrollingTo('id=some')
@@ -145,6 +152,7 @@ describe('$anchorScroll', function() {
it('should scroll to element when hash change in html5 mode with no history api', function() {
module(initLocation({html5Mode: true, historyApi: false}));
inject(
initAnchorScroll(),
addElements('id=some'),
changeHashTo('some'),
expectScrollingTo('id=some')
@@ -152,9 +160,17 @@ describe('$anchorScroll', function() {
});
it('should not scroll to the top if $anchorScroll is initializing and location hash is empty',
inject(
initAnchorScroll(),
expectNoScrolling())
);
it('should not scroll when element does not exist', function() {
module(initLocation({html5Mode: false, historyApi: false}));
inject(
initAnchorScroll(),
addElements('id=some'),
changeHashTo('other'),
expectNoScrolling()
@@ -165,6 +181,7 @@ describe('$anchorScroll', function() {
it('should scroll when html5 mode with history api', function() {
module(initLocation({html5Mode: true, historyApi: true}));
inject(
initAnchorScroll(),
addElements('id=some'),
changeHashTo('some'),
expectScrollingTo('id=some')