Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 290b13e

Browse files
gkalpakpetebacondarwin
authored andcommitted
WIP: fix up for Firefox
1 parent aa1cc54 commit 290b13e

File tree

1 file changed

+60
-63
lines changed

1 file changed

+60
-63
lines changed

test/ng/anchorScrollSpec.js

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe('$anchorScroll', function() {
1919
'</' + nodeName + '>',
2020
jqElm = jqLite(tmpl),
2121
elm = jqElm[0];
22+
// Inline elements cause Firefox to report an unexpected value for
23+
// `getBoundingClientRect().top` on some platforms (depending on the default font and
24+
// line-height). Using inline-block elements prevents this.
25+
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1014738
26+
elm.style.display = 'inline-block';
2227

2328
elmSpy[identifier] = spyOn(elm, 'scrollIntoView');
2429
jqLite($window.document.body).append(jqElm);
@@ -47,39 +52,6 @@ describe('$anchorScroll', function() {
4752
};
4853
}
4954

50-
function expectScrollingTo(identifierCountMap) {
51-
var map = {};
52-
if (isString(identifierCountMap)) {
53-
map[identifierCountMap] = 1;
54-
} else if (isArray(identifierCountMap)) {
55-
forEach(identifierCountMap, function(identifier) {
56-
map[identifier] = 1;
57-
});
58-
} else {
59-
map = identifierCountMap;
60-
}
61-
62-
return function($window) {
63-
forEach(elmSpy, function(spy, id) {
64-
var count = map[id] || 0;
65-
expect(spy.callCount).toBe(count);
66-
});
67-
expect($window.scrollTo).not.toHaveBeenCalled();
68-
};
69-
}
70-
71-
function expectScrollingToTop($window) {
72-
forEach(elmSpy, function(spy, id) {
73-
expect(spy).not.toHaveBeenCalled();
74-
});
75-
76-
expect($window.scrollTo).toHaveBeenCalledWith(0, 0);
77-
}
78-
79-
function expectNoScrolling() {
80-
return expectScrollingTo(NaN);
81-
}
82-
8355
function createMockDocument(initialReadyState) {
8456
var mockedDoc = {};
8557
docSpies = {};
@@ -117,6 +89,59 @@ describe('$anchorScroll', function() {
11789
return mockedDoc;
11890
}
11991

92+
function createMockWindow(initialReadyState) {
93+
return function() {
94+
module(function($provide) {
95+
elmSpy = {};
96+
windowSpies = {};
97+
98+
$provide.value('$window', {
99+
scrollTo: (windowSpies.scrollTo = jasmine.createSpy('$window.scrollTo')),
100+
scrollBy: (windowSpies.scrollBy = jasmine.createSpy('$window.scrollBy')),
101+
document: createMockDocument(initialReadyState),
102+
navigator: {},
103+
pageYOffset: 0,
104+
getComputedStyle: function(elem) {
105+
return getComputedStyle(elem);
106+
}
107+
});
108+
});
109+
};
110+
}
111+
112+
function expectNoScrolling() {
113+
return expectScrollingTo(NaN);
114+
}
115+
116+
function expectScrollingTo(identifierCountMap) {
117+
var map = {};
118+
if (isString(identifierCountMap)) {
119+
map[identifierCountMap] = 1;
120+
} else if (isArray(identifierCountMap)) {
121+
forEach(identifierCountMap, function(identifier) {
122+
map[identifier] = 1;
123+
});
124+
} else {
125+
map = identifierCountMap;
126+
}
127+
128+
return function($window) {
129+
forEach(elmSpy, function(spy, id) {
130+
var count = map[id] || 0;
131+
expect(spy.callCount).toBe(count);
132+
});
133+
expect($window.scrollTo).not.toHaveBeenCalled();
134+
};
135+
}
136+
137+
function expectScrollingToTop($window) {
138+
forEach(elmSpy, function(spy, id) {
139+
expect(spy).not.toHaveBeenCalled();
140+
});
141+
142+
expect($window.scrollTo).toHaveBeenCalledWith(0, 0);
143+
}
144+
120145
function resetAllSpies() {
121146
function resetSpy(spy) {
122147
spy.reset();
@@ -140,28 +165,9 @@ describe('$anchorScroll', function() {
140165
}
141166

142167

143-
function createMockWindow(initialReadyState) {
144-
return function() {
145-
module(function($provide) {
146-
elmSpy = {};
147-
windowSpies = {};
148-
149-
$provide.value('$window', {
150-
scrollTo: (windowSpies.scrollTo = jasmine.createSpy('$window.scrollTo')),
151-
scrollBy: (windowSpies.scrollBy = jasmine.createSpy('$window.scrollBy')),
152-
document: createMockDocument(initialReadyState),
153-
navigator: {},
154-
pageYOffset: 0,
155-
getComputedStyle: function(elem) {
156-
return getComputedStyle(elem);
157-
}
158-
});
159-
});
160-
};
161-
}
162-
163-
afterEach(inject(function($browser) {
168+
afterEach(inject(function($browser, $document) {
164169
expect($browser.deferredFns.length).toBe(0);
170+
dealoc($document);
165171
}));
166172

167173

@@ -311,10 +317,6 @@ describe('$anchorScroll', function() {
311317

312318
beforeEach(createMockWindow());
313319

314-
afterEach(inject(function($document) {
315-
dealoc($document);
316-
}));
317-
318320

319321
it('should scroll to element when hash change in hashbang mode', function() {
320322
module(initLocation({html5Mode: false, historyApi: true}));
@@ -444,10 +446,6 @@ describe('$anchorScroll', function() {
444446
beforeEach(createMockWindow());
445447
beforeEach(inject(setupBodyForOffsetTesting()));
446448

447-
afterEach(inject(function($document) {
448-
dealoc($document);
449-
}));
450-
451449

452450
describe('when set as a fixed number', function() {
453451

@@ -591,4 +589,3 @@ describe('$anchorScroll', function() {
591589
});
592590
});
593591
});
594-

0 commit comments

Comments
 (0)