Skip to content

Commit fea1d47

Browse files
committed
refactor: login desktop and browser tests common code
1 parent 41ca5bf commit fea1d47

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

test/spec/login-browser-integ-test.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ define(function (require, exports, module) {
8787
"Profile button to be available",
8888
3000
8989
);
90-
LoginShared.setup(testWindow, LoginServiceExports);
90+
LoginShared.setup(testWindow, LoginServiceExports, setupProUserMock, performFullLoginFlow);
9191
VIEW_TRIAL_DAYS_LEFT = LoginShared.VIEW_TRIAL_DAYS_LEFT;
9292
VIEW_PHOENIX_PRO = LoginShared.VIEW_PHOENIX_PRO;
9393
VIEW_PHOENIX_FREE = LoginShared.VIEW_PHOENIX_FREE;
@@ -290,18 +290,7 @@ define(function (require, exports, module) {
290290
await cleanupTrialState();
291291
});
292292

293-
it("should complete login and logout flow", async function () {
294-
// Setup basic user mock
295-
setupProUserMock(false);
296-
297-
// Perform full login flow
298-
await performFullLoginFlow();
299-
expect(LoginServiceExports.LoginService.isLoggedIn()).toBe(true);
300-
301-
// Perform full logout flow
302-
await performFullLogoutFlow();
303-
expect(LoginServiceExports.LoginService.isLoggedIn()).toBe(false);
304-
});
293+
LoginShared.setupSharedTests();
305294

306295
it("should update profile icon after login", async function () {
307296
// Setup basic user mock

test/spec/login-desktop-integ-test.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ define(function (require, exports, module) {
9595
"Profile button to be available",
9696
3000
9797
);
98-
LoginShared.setup(testWindow, LoginServiceExports);
98+
LoginShared.setup(testWindow, LoginServiceExports, setupProUserMock, performFullLoginFlow);
9999
VIEW_TRIAL_DAYS_LEFT = LoginShared.VIEW_TRIAL_DAYS_LEFT;
100100
VIEW_PHOENIX_PRO = LoginShared.VIEW_PHOENIX_PRO;
101101
VIEW_PHOENIX_FREE = LoginShared.VIEW_PHOENIX_FREE;
@@ -306,19 +306,7 @@ define(function (require, exports, module) {
306306
await cleanupTrialState();
307307
});
308308

309-
it("should complete login and logout flow", async function () {
310-
// Setup basic user mock
311-
setupProUserMock(false);
312-
313-
// Perform full login flow
314-
await performFullLoginFlow();
315-
expect(LoginServiceExports.LoginService.isLoggedIn()).toBe(true);
316-
317-
// Perform full logout flow
318-
await performFullLogoutFlow();
319-
expect(LoginServiceExports.LoginService.isLoggedIn()).toBe(false);
320-
verifyProfileIconBlanked();
321-
});
309+
LoginShared.setupSharedTests();
322310

323311
it("should open browser and copy validation code", async function () {
324312
// Setup basic user mock

test/spec/login-shared.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
/*global expect, awaitsFor*/
2+
/*global expect, it, awaitsFor*/
33

44
define(function (require, exports, module) {
5-
let testWindow, LoginServiceExports;
5+
let testWindow, LoginServiceExports, setupProUserMock, performFullLoginFlow;
66

77
async function setupTrialState(daysRemaining) {
88
const PromotionExports = testWindow._test_promo_login_exports;
@@ -169,9 +169,28 @@ define(function (require, exports, module) {
169169
verifyProfileIconBlanked();
170170
}
171171

172-
function setup(_testWindow, _LoginServiceExports) {
172+
function setup(_testWindow, _LoginServiceExports, _setupProUserMock, _performFullLoginFlow) {
173173
testWindow = _testWindow;
174174
LoginServiceExports = _LoginServiceExports;
175+
setupProUserMock = _setupProUserMock;
176+
performFullLoginFlow = _performFullLoginFlow;
177+
}
178+
179+
function setupSharedTests() {
180+
181+
it("should complete login and logout flow", async function () {
182+
// Setup basic user mock
183+
setupProUserMock(false);
184+
185+
// Perform full login flow
186+
await performFullLoginFlow();
187+
expect(LoginServiceExports.LoginService.isLoggedIn()).toBe(true);
188+
189+
// Perform full logout flow
190+
await performFullLogoutFlow();
191+
expect(LoginServiceExports.LoginService.isLoggedIn()).toBe(false);
192+
verifyProfileIconBlanked();
193+
});
175194
}
176195

177196
exports.setup = setup;
@@ -188,4 +207,7 @@ define(function (require, exports, module) {
188207
exports.VIEW_PHOENIX_FREE = VIEW_PHOENIX_FREE;
189208
exports.SIGNIN_POPUP = SIGNIN_POPUP;
190209
exports.PROFILE_POPUP = PROFILE_POPUP;
210+
211+
// test runner
212+
exports.setupSharedTests = setupSharedTests;
191213
});

0 commit comments

Comments
 (0)