Skip to content

Commit 53fbd8c

Browse files
committed
refactor: login desktop and browser tests common code
1 parent 93e530f commit 53fbd8c

File tree

3 files changed

+90
-131
lines changed

3 files changed

+90
-131
lines changed

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

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ define(function (require, exports, module) {
4040
LoginBrowserExports,
4141
ProDialogsExports,
4242
originalOpen,
43-
originalFetch,
44-
SharedUtils,
43+
originalFetch;
44+
let SharedUtils,
4545
setupTrialState,
4646
setupExpiredTrial,
47-
verifyProBranding;
47+
verifyProBranding,
48+
verifyProfilePopupContent,
49+
VIEW_TRIAL_DAYS_LEFT,
50+
VIEW_PHOENIX_PRO,
51+
VIEW_PHOENIX_FREE;
4852

4953
beforeAll(async function () {
5054
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -78,9 +82,13 @@ define(function (require, exports, module) {
7882
3000
7983
);
8084
SharedUtils = LoginShared.getSharedUtils(testWindow);
85+
VIEW_TRIAL_DAYS_LEFT = SharedUtils.VIEW_TRIAL_DAYS_LEFT;
86+
VIEW_PHOENIX_PRO = SharedUtils.VIEW_PHOENIX_PRO;
87+
VIEW_PHOENIX_FREE = SharedUtils.VIEW_PHOENIX_FREE;
8188
setupTrialState = SharedUtils.setupTrialState;
8289
setupExpiredTrial = SharedUtils.setupExpiredTrial;
8390
verifyProBranding = SharedUtils.verifyProBranding;
91+
verifyProfilePopupContent = SharedUtils.verifyProfilePopupContent;
8492
}, 30000);
8593

8694
afterAll(async function () {
@@ -200,68 +208,6 @@ define(function (require, exports, module) {
200208
ProDialogsExports.setFetchFn(fetchMock);
201209
}
202210

203-
const VIEW_TRIAL_DAYS_LEFT = "VIEW_TRIAL_DAYS_LEFT";
204-
const VIEW_PHOENIX_PRO = "VIEW_PHOENIX_PRO";
205-
const VIEW_PHOENIX_FREE = "VIEW_PHOENIX_FREE";
206-
async function verifyProfilePopupContent(expectedView, testDescription) {
207-
await awaitsFor(
208-
function () {
209-
return testWindow.$('.profile-popup').length > 0;
210-
},
211-
`Profile popup to appear: ${testDescription}`,
212-
3000
213-
);
214-
215-
if (expectedView === VIEW_PHOENIX_PRO) {
216-
await awaitsFor(
217-
function () {
218-
const $popup = testWindow.$('.profile-popup');
219-
const $planName = $popup.find('.user-plan-name');
220-
const planText = $planName.text();
221-
return planText.includes("Phoenix Pro");
222-
},
223-
`Profile popup should say phoenix pro: ${testDescription}`, 5000
224-
);
225-
const $popup = testWindow.$('.profile-popup');
226-
const $planName = $popup.find('.user-plan-name');
227-
const planText = $planName.text();
228-
expect(planText).toContain("Phoenix Pro");
229-
expect(planText).not.toContain("days left");
230-
expect($popup.find(".fa-feather").length).toBe(1);
231-
} else if (expectedView === VIEW_TRIAL_DAYS_LEFT) {
232-
await awaitsFor(
233-
function () {
234-
const $popup = testWindow.$('.profile-popup');
235-
const $planName = $popup.find('.user-plan-name');
236-
const planText = $planName.text();
237-
return planText.includes("Phoenix Pro") && planText.includes("days left");
238-
},
239-
`Profile popup should say phoenix pro trial: ${testDescription}`, 5000
240-
);
241-
const $popup = testWindow.$('.profile-popup');
242-
const $planName = $popup.find('.user-plan-name');
243-
const planText = $planName.text();
244-
expect(planText).toContain("Phoenix Pro");
245-
expect(planText).toContain("days left");
246-
expect($popup.find(".fa-feather").length).toBe(1);
247-
} else {
248-
await awaitsFor(
249-
function () {
250-
const $popup = testWindow.$('.profile-popup');
251-
const $planName = $popup.find('.user-plan-name');
252-
const planText = $planName.text();
253-
return !planText.includes("Phoenix Pro");
254-
},
255-
`Profile popup should not say phoenix pro: ${testDescription}`, 5000
256-
);
257-
const $popup = testWindow.$('.profile-popup');
258-
const $planName = $popup.find('.user-plan-name');
259-
const planText = $planName.text();
260-
expect(planText).not.toContain("Phoenix Pro");
261-
expect($popup.find(".fa-feather").length).toBe(0);
262-
}
263-
}
264-
265211
async function cleanupTrialState() {
266212
const PromotionExports = testWindow._test_promo_login_exports;
267213
await PromotionExports._cleanTrialData();

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

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ define(function (require, exports, module) {
4848
ProDialogsExports,
4949
originalOpenURLInDefaultBrowser,
5050
originalCopyToClipboard,
51-
originalFetch,
52-
SharedUtils,
51+
originalFetch;
52+
53+
let SharedUtils,
5354
setupTrialState,
5455
setupExpiredTrial,
55-
verifyProBranding;
56+
verifyProBranding,
57+
verifyProfilePopupContent,
58+
VIEW_TRIAL_DAYS_LEFT,
59+
VIEW_PHOENIX_PRO,
60+
VIEW_PHOENIX_FREE;
5661

5762
beforeAll(async function () {
5863
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -86,9 +91,13 @@ define(function (require, exports, module) {
8691
3000
8792
);
8893
SharedUtils = LoginShared.getSharedUtils(testWindow);
94+
VIEW_TRIAL_DAYS_LEFT = SharedUtils.VIEW_TRIAL_DAYS_LEFT;
95+
VIEW_PHOENIX_PRO = SharedUtils.VIEW_PHOENIX_PRO;
96+
VIEW_PHOENIX_FREE = SharedUtils.VIEW_PHOENIX_FREE;
8997
setupTrialState = SharedUtils.setupTrialState;
9098
setupExpiredTrial = SharedUtils.setupExpiredTrial;
9199
verifyProBranding = SharedUtils.verifyProBranding;
100+
verifyProfilePopupContent = SharedUtils.verifyProfilePopupContent;
92101
}, 30000);
93102

94103
afterAll(async function () {
@@ -222,68 +231,6 @@ define(function (require, exports, module) {
222231
ProDialogsExports.setFetchFn(fetchMock);
223232
}
224233

225-
const VIEW_TRIAL_DAYS_LEFT = "VIEW_TRIAL_DAYS_LEFT";
226-
const VIEW_PHOENIX_PRO = "VIEW_PHOENIX_PRO";
227-
const VIEW_PHOENIX_FREE = "VIEW_PHOENIX_FREE";
228-
async function verifyProfilePopupContent(expectedView, testDescription) {
229-
await awaitsFor(
230-
function () {
231-
return testWindow.$('.profile-popup').length > 0;
232-
},
233-
`Profile popup to appear: ${testDescription}`,
234-
3000
235-
);
236-
237-
if (expectedView === VIEW_PHOENIX_PRO) {
238-
await awaitsFor(
239-
function () {
240-
const $popup = testWindow.$('.profile-popup');
241-
const $planName = $popup.find('.user-plan-name');
242-
const planText = $planName.text();
243-
return planText.includes("Phoenix Pro");
244-
},
245-
`Profile popup should say phoenix pro: ${testDescription}`, 5000
246-
);
247-
const $popup = testWindow.$('.profile-popup');
248-
const $planName = $popup.find('.user-plan-name');
249-
const planText = $planName.text();
250-
expect(planText).toContain("Phoenix Pro");
251-
expect(planText).not.toContain("days left");
252-
expect($popup.find(".fa-feather").length).toBe(1);
253-
} else if (expectedView === VIEW_TRIAL_DAYS_LEFT) {
254-
await awaitsFor(
255-
function () {
256-
const $popup = testWindow.$('.profile-popup');
257-
const $planName = $popup.find('.user-plan-name');
258-
const planText = $planName.text();
259-
return planText.includes("Phoenix Pro") && planText.includes("days left");
260-
},
261-
`Profile popup should say phoenix pro trial: ${testDescription}`, 5000
262-
);
263-
const $popup = testWindow.$('.profile-popup');
264-
const $planName = $popup.find('.user-plan-name');
265-
const planText = $planName.text();
266-
expect(planText).toContain("Phoenix Pro");
267-
expect(planText).toContain("days left");
268-
expect($popup.find(".fa-feather").length).toBe(1);
269-
} else {
270-
await awaitsFor(
271-
function () {
272-
const $popup = testWindow.$('.profile-popup');
273-
const $planName = $popup.find('.user-plan-name');
274-
const planText = $planName.text();
275-
return !planText.includes("Phoenix Pro");
276-
},
277-
`Profile popup should not say phoenix pro: ${testDescription}`, 5000
278-
);
279-
const $popup = testWindow.$('.profile-popup');
280-
const $planName = $popup.find('.user-plan-name');
281-
const planText = $planName.text();
282-
expect(planText).not.toContain("Phoenix Pro");
283-
expect($popup.find(".fa-feather").length).toBe(0);
284-
}
285-
}
286-
287234
async function cleanupTrialState() {
288235
const PromotionExports = testWindow._test_promo_login_exports;
289236
await PromotionExports._cleanTrialData();

test/spec/login-shared.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,76 @@ define(function (require, exports, module) {
5454
}
5555
}
5656

57+
const VIEW_TRIAL_DAYS_LEFT = "VIEW_TRIAL_DAYS_LEFT";
58+
const VIEW_PHOENIX_PRO = "VIEW_PHOENIX_PRO";
59+
const VIEW_PHOENIX_FREE = "VIEW_PHOENIX_FREE";
60+
async function verifyProfilePopupContent(expectedView, testDescription) {
61+
await awaitsFor(
62+
function () {
63+
return testWindow.$('.profile-popup').length > 0;
64+
},
65+
`Profile popup to appear: ${testDescription}`,
66+
3000
67+
);
68+
69+
if (expectedView === VIEW_PHOENIX_PRO) {
70+
await awaitsFor(
71+
function () {
72+
const $popup = testWindow.$('.profile-popup');
73+
const $planName = $popup.find('.user-plan-name');
74+
const planText = $planName.text();
75+
return planText.includes("Phoenix Pro");
76+
},
77+
`Profile popup should say phoenix pro: ${testDescription}`, 5000
78+
);
79+
const $popup = testWindow.$('.profile-popup');
80+
const $planName = $popup.find('.user-plan-name');
81+
const planText = $planName.text();
82+
expect(planText).toContain("Phoenix Pro");
83+
expect(planText).not.toContain("days left");
84+
expect($popup.find(".fa-feather").length).toBe(1);
85+
} else if (expectedView === VIEW_TRIAL_DAYS_LEFT) {
86+
await awaitsFor(
87+
function () {
88+
const $popup = testWindow.$('.profile-popup');
89+
const $planName = $popup.find('.user-plan-name');
90+
const planText = $planName.text();
91+
return planText.includes("Phoenix Pro") && planText.includes("days left");
92+
},
93+
`Profile popup should say phoenix pro trial: ${testDescription}`, 5000
94+
);
95+
const $popup = testWindow.$('.profile-popup');
96+
const $planName = $popup.find('.user-plan-name');
97+
const planText = $planName.text();
98+
expect(planText).toContain("Phoenix Pro");
99+
expect(planText).toContain("days left");
100+
expect($popup.find(".fa-feather").length).toBe(1);
101+
} else {
102+
await awaitsFor(
103+
function () {
104+
const $popup = testWindow.$('.profile-popup');
105+
const $planName = $popup.find('.user-plan-name');
106+
const planText = $planName.text();
107+
return !planText.includes("Phoenix Pro");
108+
},
109+
`Profile popup should not say phoenix pro: ${testDescription}`, 5000
110+
);
111+
const $popup = testWindow.$('.profile-popup');
112+
const $planName = $popup.find('.user-plan-name');
113+
const planText = $planName.text();
114+
expect(planText).not.toContain("Phoenix Pro");
115+
expect($popup.find(".fa-feather").length).toBe(0);
116+
}
117+
}
118+
57119
return {
58120
setupTrialState,
59121
setupExpiredTrial,
60-
verifyProBranding
122+
verifyProBranding,
123+
verifyProfilePopupContent,
124+
VIEW_TRIAL_DAYS_LEFT,
125+
VIEW_PHOENIX_PRO,
126+
VIEW_PHOENIX_FREE
61127
};
62128
}
63129

0 commit comments

Comments
 (0)