Skip to content

Commit 9612e50

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

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
define(function (require, exports, module) {
2424

2525
const SpecRunnerUtils = require("spec/SpecRunnerUtils");
26+
const LoginShared = require("./login-shared");
2627

2728
describe("integration: login/logout browser app tests", function () {
2829

@@ -39,7 +40,9 @@ define(function (require, exports, module) {
3940
LoginBrowserExports,
4041
ProDialogsExports,
4142
originalOpen,
42-
originalFetch;
43+
originalFetch,
44+
SharedUtils,
45+
setupTrialState;
4346

4447
beforeAll(async function () {
4548
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -72,6 +75,8 @@ define(function (require, exports, module) {
7275
"Profile button to be available",
7376
3000
7477
);
78+
SharedUtils = LoginShared.getSharedUtils(testWindow);
79+
setupTrialState = SharedUtils.setupTrialState;
7580
}, 30000);
7681

7782
afterAll(async function () {
@@ -97,19 +102,6 @@ define(function (require, exports, module) {
97102
// Note: We can't easily reset login state, so tests should handle this
98103
});
99104

100-
// Helper functions for promotion testing (browser-specific)
101-
async function setupTrialState(daysRemaining) {
102-
const PromotionExports = testWindow._test_promo_login_exports;
103-
const mockNow = Date.now();
104-
await PromotionExports._setTrialData({
105-
proVersion: "3.1.0",
106-
endDate: mockNow + (daysRemaining * PromotionExports.TRIAL_CONSTANTS.MS_PER_DAY)
107-
});
108-
// Trigger entitlements changed event to update branding
109-
const LoginService = PromotionExports.LoginService;
110-
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED);
111-
}
112-
113105
async function setupExpiredTrial() {
114106
const PromotionExports = testWindow._test_promo_login_exports;
115107
const mockNow = Date.now();

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
define(function (require, exports, module) {
2424

2525
const SpecRunnerUtils = require("spec/SpecRunnerUtils");
26+
const LoginShared = require("./login-shared");
2627

2728
describe("integration: login/logout desktop app tests", function () {
2829

@@ -47,7 +48,9 @@ define(function (require, exports, module) {
4748
ProDialogsExports,
4849
originalOpenURLInDefaultBrowser,
4950
originalCopyToClipboard,
50-
originalFetch;
51+
originalFetch,
52+
SharedUtils,
53+
setupTrialState;
5154

5255
beforeAll(async function () {
5356
testWindow = await SpecRunnerUtils.createTestWindowAndRun();
@@ -80,6 +83,8 @@ define(function (require, exports, module) {
8083
"Profile button to be available",
8184
3000
8285
);
86+
SharedUtils = LoginShared.getSharedUtils(testWindow);
87+
setupTrialState = SharedUtils.setupTrialState;
8388
}, 30000);
8489

8590
afterAll(async function () {
@@ -107,19 +112,6 @@ define(function (require, exports, module) {
107112
// Note: We can't easily reset login state, so tests should handle this
108113
});
109114

110-
// Helper functions for desktop login testing
111-
async function setupTrialState(daysRemaining) {
112-
const PromotionExports = testWindow._test_promo_login_exports;
113-
const mockNow = Date.now();
114-
await PromotionExports._setTrialData({
115-
proVersion: "3.1.0",
116-
endDate: mockNow + (daysRemaining * PromotionExports.TRIAL_CONSTANTS.MS_PER_DAY)
117-
});
118-
// Trigger entitlements changed event to update branding
119-
const LoginService = PromotionExports.LoginService;
120-
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED);
121-
}
122-
123115
async function setupExpiredTrial() {
124116
const PromotionExports = testWindow._test_promo_login_exports;
125117
const mockNow = Date.now();

test/spec/login-shared.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
define(function (require, exports, module) {
2+
3+
function getSharedUtils(testWindow) {
4+
// Helper functions for promotion testing (browser-specific)
5+
async function setupTrialState(daysRemaining) {
6+
const PromotionExports = testWindow._test_promo_login_exports;
7+
const mockNow = Date.now();
8+
await PromotionExports._setTrialData({
9+
proVersion: "3.1.0",
10+
endDate: mockNow + (daysRemaining * PromotionExports.TRIAL_CONSTANTS.MS_PER_DAY)
11+
});
12+
// Trigger entitlements changed event to update branding
13+
const LoginService = PromotionExports.LoginService;
14+
LoginService.trigger(LoginService.EVENT_ENTITLEMENTS_CHANGED);
15+
}
16+
return {
17+
setupTrialState
18+
};
19+
}
20+
21+
exports.getSharedUtils = getSharedUtils;
22+
});

0 commit comments

Comments
 (0)