Skip to content

Commit 888645e

Browse files
authored
[Auth] Fix popup opening location (#5281)
* Fix popup opening location * Formatting
1 parent a69220b commit 888645e

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

packages-exp/auth-exp/src/platform_browser/util/popup.test.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ describe('platform_browser/util/popup', () => {
5151

5252
beforeEach(async () => {
5353
windowOpenStub = sinon.stub(window, 'open');
54-
popupStub = sinon.stub(({
54+
popupStub = sinon.stub({
5555
focus: () => {},
5656
close: () => {}
57-
} as unknown) as Window);
57+
} as unknown as Window);
5858
windowOpenStub.returns(popupStub);
5959
auth = await testAuth();
6060
});
@@ -105,19 +105,23 @@ describe('platform_browser/util/popup', () => {
105105
expect(windowOptions()).to.include('scrollbars=yes');
106106
});
107107

108+
it('centers the popup in the screen', () => {
109+
sinon.stub(window.screen, 'availHeight').value(1000);
110+
sinon.stub(window.screen, 'availWidth').value(1000);
111+
_open(auth);
112+
expect(windowOptions()).to.include('top=200');
113+
expect(windowOptions()).to.include('left=250');
114+
});
115+
108116
it('errors if the popup is blocked', () => {
109117
setUA('');
110118
windowOpenStub.returns(undefined);
111119
expect(() => _open(auth)).to.throw(FirebaseError, 'auth/popup-blocked');
112120
});
113121

114122
it('builds the proper options string', () => {
115-
const screen = window.screen;
116-
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
117-
(window as any).sreen = {
118-
availHeight: 1000,
119-
availWidth: 2000
120-
};
123+
sinon.stub(window.screen, 'availHeight').value(1000);
124+
sinon.stub(window.screen, 'availWidth').value(2000);
121125

122126
setUA('');
123127
_open(auth);
@@ -137,8 +141,8 @@ describe('platform_browser/util/popup', () => {
137141
toolbar: 'no',
138142
width: '500',
139143
height: '600',
140-
top: '0',
141-
left: '0'
144+
top: '200',
145+
left: '750'
142146
});
143147

144148
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

packages-exp/auth-exp/src/platform_browser/util/popup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export function _open(
6060
width = DEFAULT_WIDTH,
6161
height = DEFAULT_HEIGHT
6262
): AuthPopup {
63-
const top = Math.min((window.screen.availHeight - height) / 2, 0).toString();
64-
const left = Math.min((window.screen.availWidth - width) / 2, 0).toString();
63+
const top = Math.max((window.screen.availHeight - height) / 2, 0).toString();
64+
const left = Math.max((window.screen.availWidth - width) / 2, 0).toString();
6565
let target = '';
6666

6767
const options: { [key: string]: string } = {

0 commit comments

Comments
 (0)