Skip to content

Commit bfca50d

Browse files
committed
refactor: login desktop and browser tests common code
1 parent e6aabc3 commit bfca50d

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,19 @@ define(function (require, exports, module) {
4141
ProDialogsExports,
4242
originalOpen,
4343
originalFetch;
44+
4445
let SharedUtils,
4546
setupTrialState,
4647
setupExpiredTrial,
4748
verifyProBranding,
4849
verifyProfilePopupContent,
50+
cleanupTrialState,
51+
popupToAppear,
4952
VIEW_TRIAL_DAYS_LEFT,
5053
VIEW_PHOENIX_PRO,
51-
VIEW_PHOENIX_FREE;
54+
VIEW_PHOENIX_FREE,
55+
SIGNIN_POPUP,
56+
PROFILE_POPUP;
5257

5358
beforeAll(async function () {
5459
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -85,10 +90,14 @@ define(function (require, exports, module) {
8590
VIEW_TRIAL_DAYS_LEFT = SharedUtils.VIEW_TRIAL_DAYS_LEFT;
8691
VIEW_PHOENIX_PRO = SharedUtils.VIEW_PHOENIX_PRO;
8792
VIEW_PHOENIX_FREE = SharedUtils.VIEW_PHOENIX_FREE;
93+
SIGNIN_POPUP = SharedUtils.SIGNIN_POPUP;
94+
PROFILE_POPUP = SharedUtils.PROFILE_POPUP;
8895
setupTrialState = SharedUtils.setupTrialState;
8996
setupExpiredTrial = SharedUtils.setupExpiredTrial;
9097
verifyProBranding = SharedUtils.verifyProBranding;
9198
verifyProfilePopupContent = SharedUtils.verifyProfilePopupContent;
99+
cleanupTrialState = SharedUtils.cleanupTrialState;
100+
popupToAppear = SharedUtils.popupToAppear;
92101
}, 30000);
93102

94103
afterAll(async function () {
@@ -208,25 +217,6 @@ define(function (require, exports, module) {
208217
ProDialogsExports.setFetchFn(fetchMock);
209218
}
210219

211-
async function cleanupTrialState() {
212-
const PromotionExports = testWindow._test_promo_login_exports;
213-
await PromotionExports._cleanTrialData();
214-
}
215-
216-
const SIGNIN_POPUP = "SIGNIN_POPUP";
217-
const PROFILE_POPUP = "PROFILE_POPUP";
218-
async function popupToAppear(popupType = SIGNIN_POPUP) {
219-
const statusText = popupType === SIGNIN_POPUP ?
220-
"Sign In popup to appear" : "Profile popup to appear";
221-
await awaitsFor(
222-
function () {
223-
const selector = popupType === SIGNIN_POPUP ? ".login-profile-popup" : ".user-profile-popup";
224-
return testWindow.$('.modal').length > 0 || testWindow.$(selector).length > 0;
225-
},
226-
statusText, 3000
227-
);
228-
}
229-
230220
async function performFullLoginFlow() {
231221
// Mock window.open like the original test
232222
let capturedURL = null;

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ define(function (require, exports, module) {
5555
setupExpiredTrial,
5656
verifyProBranding,
5757
verifyProfilePopupContent,
58+
cleanupTrialState,
59+
popupToAppear,
5860
VIEW_TRIAL_DAYS_LEFT,
5961
VIEW_PHOENIX_PRO,
60-
VIEW_PHOENIX_FREE;
62+
VIEW_PHOENIX_FREE,
63+
SIGNIN_POPUP,
64+
PROFILE_POPUP;
6165

6266
beforeAll(async function () {
6367
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -94,10 +98,14 @@ define(function (require, exports, module) {
9498
VIEW_TRIAL_DAYS_LEFT = SharedUtils.VIEW_TRIAL_DAYS_LEFT;
9599
VIEW_PHOENIX_PRO = SharedUtils.VIEW_PHOENIX_PRO;
96100
VIEW_PHOENIX_FREE = SharedUtils.VIEW_PHOENIX_FREE;
101+
SIGNIN_POPUP = SharedUtils.SIGNIN_POPUP;
102+
PROFILE_POPUP = SharedUtils.PROFILE_POPUP;
97103
setupTrialState = SharedUtils.setupTrialState;
98104
setupExpiredTrial = SharedUtils.setupExpiredTrial;
99105
verifyProBranding = SharedUtils.verifyProBranding;
100106
verifyProfilePopupContent = SharedUtils.verifyProfilePopupContent;
107+
cleanupTrialState = SharedUtils.cleanupTrialState;
108+
popupToAppear = SharedUtils.popupToAppear;
101109
}, 30000);
102110

103111
afterAll(async function () {
@@ -231,25 +239,6 @@ define(function (require, exports, module) {
231239
ProDialogsExports.setFetchFn(fetchMock);
232240
}
233241

234-
async function cleanupTrialState() {
235-
const PromotionExports = testWindow._test_promo_login_exports;
236-
await PromotionExports._cleanTrialData();
237-
}
238-
239-
const SIGNIN_POPUP = "SIGNIN_POPUP";
240-
const PROFILE_POPUP = "PROFILE_POPUP";
241-
async function popupToAppear(popupType = SIGNIN_POPUP) {
242-
const statusText = popupType === SIGNIN_POPUP ?
243-
"Sign In popup to appear" : "Profile popup to appear";
244-
await awaitsFor(
245-
function () {
246-
const selector = popupType === SIGNIN_POPUP ? ".login-profile-popup" : ".user-profile-popup";
247-
return testWindow.$('.modal').length > 0 || testWindow.$(selector).length > 0;
248-
},
249-
statusText, 3000
250-
);
251-
}
252-
253242
async function performFullLoginFlow() {
254243
// Mock desktop app functions for login flow
255244
testWindow.Phoenix.app.openURLInDefaultBrowser = function(url) {

test/spec/login-shared.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,37 @@ define(function (require, exports, module) {
116116
}
117117
}
118118

119+
async function cleanupTrialState() {
120+
const PromotionExports = testWindow._test_promo_login_exports;
121+
await PromotionExports._cleanTrialData();
122+
}
123+
124+
const SIGNIN_POPUP = "SIGNIN_POPUP";
125+
const PROFILE_POPUP = "PROFILE_POPUP";
126+
async function popupToAppear(popupType = SIGNIN_POPUP) {
127+
const statusText = popupType === SIGNIN_POPUP ?
128+
"Sign In popup to appear" : "Profile popup to appear";
129+
await awaitsFor(
130+
function () {
131+
const selector = popupType === SIGNIN_POPUP ? ".login-profile-popup" : ".user-profile-popup";
132+
return testWindow.$('.modal').length > 0 || testWindow.$(selector).length > 0;
133+
},
134+
statusText, 3000
135+
);
136+
}
137+
119138
return {
120139
setupTrialState,
121140
setupExpiredTrial,
122141
verifyProBranding,
123142
verifyProfilePopupContent,
143+
cleanupTrialState,
144+
popupToAppear,
124145
VIEW_TRIAL_DAYS_LEFT,
125146
VIEW_PHOENIX_PRO,
126-
VIEW_PHOENIX_FREE
147+
VIEW_PHOENIX_FREE,
148+
SIGNIN_POPUP,
149+
PROFILE_POPUP
127150
};
128151
}
129152

0 commit comments

Comments
 (0)