Skip to content

Commit 46ed42c

Browse files
committed
refactor: login desktop and browser tests common code
1 parent 9612e50 commit 46ed42c

File tree

3 files changed

+54
-83
lines changed

3 files changed

+54
-83
lines changed

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

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ define(function (require, exports, module) {
4242
originalOpen,
4343
originalFetch,
4444
SharedUtils,
45-
setupTrialState;
45+
setupTrialState,
46+
setupExpiredTrial,
47+
verifyProBranding;
4648

4749
beforeAll(async function () {
4850
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -77,6 +79,8 @@ define(function (require, exports, module) {
7779
);
7880
SharedUtils = LoginShared.getSharedUtils(testWindow);
7981
setupTrialState = SharedUtils.setupTrialState;
82+
setupExpiredTrial = SharedUtils.setupExpiredTrial;
83+
verifyProBranding = SharedUtils.verifyProBranding;
8084
}, 30000);
8185

8286
afterAll(async function () {
@@ -102,18 +106,6 @@ define(function (require, exports, module) {
102106
// Note: We can't easily reset login state, so tests should handle this
103107
});
104108

105-
async function setupExpiredTrial() {
106-
const PromotionExports = testWindow._test_promo_login_exports;
107-
const mockNow = Date.now();
108-
await PromotionExports._setTrialData({
109-
proVersion: "3.1.0",
110-
endDate: mockNow - PromotionExports.TRIAL_CONSTANTS.MS_PER_DAY
111-
});
112-
// Trigger entitlements changed event to update branding
113-
const LoginService = PromotionExports.LoginService;
114-
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED);
115-
}
116-
117109
function setupProUserMock(hasActiveSubscription = true) {
118110
let userSignedOut = false;
119111

@@ -208,34 +200,6 @@ define(function (require, exports, module) {
208200
ProDialogsExports.setFetchFn(fetchMock);
209201
}
210202

211-
async function verifyProBranding(shouldShowPro, testDescription) {
212-
const $brandingLink = testWindow.$("#phcode-io-main-nav");
213-
console.log(`llgT: Browser verifying branding for ${testDescription}, shouldShowPro: ${shouldShowPro}`);
214-
console.log(`llgT: Browser branding link classes: ${$brandingLink.attr('class')}`);
215-
console.log(`llgT: Browser branding link text: '${$brandingLink.text()}'`);
216-
217-
if (shouldShowPro) {
218-
await awaitsFor(
219-
function () {
220-
return testWindow.$("#phcode-io-main-nav").hasClass("phoenix-pro");
221-
},
222-
`Verify Pro branding to appear: ${testDescription}`, 5000
223-
);
224-
expect($brandingLink.hasClass("phoenix-pro")).toBe(true);
225-
expect($brandingLink.text()).toContain("Phoenix Pro");
226-
expect($brandingLink.find(".fa-feather").length).toBe(1);
227-
} else {
228-
await awaitsFor(
229-
function () {
230-
return !testWindow.$("#phcode-io-main-nav").hasClass("phoenix-pro");
231-
},
232-
`Verify Pro branding to go away: ${testDescription}`, 5000
233-
);
234-
expect($brandingLink.hasClass("phoenix-pro")).toBe(false);
235-
expect($brandingLink.text()).toBe("phcode.io");
236-
}
237-
}
238-
239203
const VIEW_TRIAL_DAYS_LEFT = "VIEW_TRIAL_DAYS_LEFT";
240204
const VIEW_PHOENIX_PRO = "VIEW_PHOENIX_PRO";
241205
const VIEW_PHOENIX_FREE = "VIEW_PHOENIX_FREE";

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

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ define(function (require, exports, module) {
5050
originalCopyToClipboard,
5151
originalFetch,
5252
SharedUtils,
53-
setupTrialState;
53+
setupTrialState,
54+
setupExpiredTrial,
55+
verifyProBranding;
5456

5557
beforeAll(async function () {
5658
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -85,6 +87,8 @@ define(function (require, exports, module) {
8587
);
8688
SharedUtils = LoginShared.getSharedUtils(testWindow);
8789
setupTrialState = SharedUtils.setupTrialState;
90+
setupExpiredTrial = SharedUtils.setupExpiredTrial;
91+
verifyProBranding = SharedUtils.verifyProBranding;
8892
}, 30000);
8993

9094
afterAll(async function () {
@@ -112,18 +116,6 @@ define(function (require, exports, module) {
112116
// Note: We can't easily reset login state, so tests should handle this
113117
});
114118

115-
async function setupExpiredTrial() {
116-
const PromotionExports = testWindow._test_promo_login_exports;
117-
const mockNow = Date.now();
118-
await PromotionExports._setTrialData({
119-
proVersion: "3.1.0",
120-
endDate: mockNow - PromotionExports.TRIAL_CONSTANTS.MS_PER_DAY
121-
});
122-
// Trigger entitlements changed event to update branding
123-
const LoginService = PromotionExports.LoginService;
124-
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED);
125-
}
126-
127119
function setupProUserMock(hasActiveSubscription = true) {
128120
let userSignedOut = false;
129121

@@ -230,34 +222,6 @@ define(function (require, exports, module) {
230222
ProDialogsExports.setFetchFn(fetchMock);
231223
}
232224

233-
async function verifyProBranding(shouldShowPro, testDescription) {
234-
const $brandingLink = testWindow.$("#phcode-io-main-nav");
235-
console.log(`llgT: Desktop verifying branding for ${testDescription}, shouldShowPro: ${shouldShowPro}`);
236-
console.log(`llgT: Desktop branding link classes: ${$brandingLink.attr('class')}`);
237-
console.log(`llgT: Desktop branding link text: '${$brandingLink.text()}'`);
238-
239-
if (shouldShowPro) {
240-
await awaitsFor(
241-
function () {
242-
return testWindow.$("#phcode-io-main-nav").hasClass("phoenix-pro");
243-
},
244-
`Verify Pro branding to appear: ${testDescription}`, 5000
245-
);
246-
expect($brandingLink.hasClass("phoenix-pro")).toBe(true);
247-
expect($brandingLink.text()).toContain("Phoenix Pro");
248-
expect($brandingLink.find(".fa-feather").length).toBe(1);
249-
} else {
250-
await awaitsFor(
251-
function () {
252-
return !testWindow.$("#phcode-io-main-nav").hasClass("phoenix-pro");
253-
},
254-
`Verify Pro branding to go away: ${testDescription}`, 5000
255-
);
256-
expect($brandingLink.hasClass("phoenix-pro")).toBe(false);
257-
expect($brandingLink.text()).toBe("phcode.io");
258-
}
259-
}
260-
261225
const VIEW_TRIAL_DAYS_LEFT = "VIEW_TRIAL_DAYS_LEFT";
262226
const VIEW_PHOENIX_PRO = "VIEW_PHOENIX_PRO";
263227
const VIEW_PHOENIX_FREE = "VIEW_PHOENIX_FREE";

test/spec/login-shared.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
/*global expect, awaitsFor*/
3+
14
define(function (require, exports, module) {
25

36
function getSharedUtils(testWindow) {
@@ -13,8 +16,48 @@ define(function (require, exports, module) {
1316
const LoginService = PromotionExports.LoginService;
1417
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED);
1518
}
19+
20+
async function setupExpiredTrial() {
21+
const PromotionExports = testWindow._test_promo_login_exports;
22+
const mockNow = Date.now();
23+
await PromotionExports._setTrialData({
24+
proVersion: "3.1.0",
25+
endDate: mockNow - PromotionExports.TRIAL_CONSTANTS.MS_PER_DAY
26+
});
27+
// Trigger entitlements changed event to update branding
28+
const LoginService = PromotionExports.LoginService;
29+
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED);
30+
}
31+
32+
async function verifyProBranding(shouldShowPro, testDescription) {
33+
const $brandingLink = testWindow.$("#phcode-io-main-nav");
34+
35+
if (shouldShowPro) {
36+
await awaitsFor(
37+
function () {
38+
return testWindow.$("#phcode-io-main-nav").hasClass("phoenix-pro");
39+
},
40+
`Verify Pro branding to appear: ${testDescription}`, 5000
41+
);
42+
expect($brandingLink.hasClass("phoenix-pro")).toBe(true);
43+
expect($brandingLink.text()).toContain("Phoenix Pro");
44+
expect($brandingLink.find(".fa-feather").length).toBe(1);
45+
} else {
46+
await awaitsFor(
47+
function () {
48+
return !testWindow.$("#phcode-io-main-nav").hasClass("phoenix-pro");
49+
},
50+
`Verify Pro branding to go away: ${testDescription}`, 5000
51+
);
52+
expect($brandingLink.hasClass("phoenix-pro")).toBe(false);
53+
expect($brandingLink.text()).toBe("phcode.io");
54+
}
55+
}
56+
1657
return {
17-
setupTrialState
58+
setupTrialState,
59+
setupExpiredTrial,
60+
verifyProBranding
1861
};
1962
}
2063

0 commit comments

Comments
 (0)