Skip to content

Commit 28eb894

Browse files
authored
chore(e2e): consolidate shared initial preferences configuration in init command; use preferences to disable guide cues (#7530)
* chore(e2e): consolidate shared initial preferences configuration in init command; use preferences to disable guide cues * fix(e2e): await the invoke when checking for ipc channel being ready * chore(e2e): set zoomLevel to 0 (1 is not default) * fix(e2e): only validate whether preference was set if it exists
1 parent 1747c2d commit 28eb894

File tree

7 files changed

+173
-116
lines changed

7 files changed

+173
-116
lines changed

packages/compass-components/src/components/guide-cue/guide-cue.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ export const GuideCue = <T extends HTMLElement>({
256256
};
257257
}, [isCueOpen, cueData, onNext, setOpen]);
258258

259-
const isCueDisabled =
260-
context.disabled || process.env.DISABLE_GUIDE_CUES === 'true';
259+
const isCueDisabled = context.disabled;
261260

262261
return (
263262
<>

packages/compass-e2e-tests/helpers/commands/close-welcome-modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export async function closeWelcomeModal(
2222
// does something like location.reload() immediately it definitely won't show
2323
// the welcome modal a second time. It is kinda irrelevant which setting we
2424
// use, but it must be an uncontrolled one
25-
await browser.setFeature('zoomLevel', 1);
25+
await browser.setFeature('zoomLevel', 0);
2626
}

packages/compass-e2e-tests/helpers/commands/preferences.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,39 @@ import type {
66
import { isTestingWeb } from '../test-runner-context';
77
import { inspect } from 'util';
88

9-
function _waitUntilPreferencesAccessAvailable(
9+
async function _waitUntilPreferencesAccessAvailable(
1010
browser: CompassBrowser
1111
): Promise<void> {
12+
const waitUntilOptions = {
13+
timeoutMsg: 'Preferences are not available',
14+
interval: 3000,
15+
};
16+
1217
if (!isTestingWeb()) {
13-
return browser.waitUntil(() => {
14-
return browser.execute(() => {
18+
await browser.waitUntil(() => {
19+
return browser.execute(async () => {
1520
try {
1621
// eslint-disable-next-line @typescript-eslint/no-require-imports
17-
require('electron').ipcRenderer.invoke(
18-
'compass:save-preferences', // this will throw if handler is not registered yet
22+
await require('electron').ipcRenderer.invoke(
23+
'compass:save-preferences', // this will reject if handler is not registered yet
1924
{}
2025
);
2126
return true;
2227
} catch {
2328
return false;
2429
}
2530
});
26-
});
27-
}
28-
return browser.waitUntil(
29-
() => {
31+
}, waitUntilOptions);
32+
} else {
33+
await browser.waitUntil(() => {
3034
return browser.execute(() => {
3135
const kSandboxPreferencesAccess = Symbol.for(
3236
'@compass-web-sandbox-preferences-access'
3337
);
3438
return kSandboxPreferencesAccess in globalThis;
3539
});
36-
},
37-
{ timeoutMsg: 'Preferences are not available' }
38-
);
40+
}, waitUntilOptions);
41+
}
3942
}
4043

4144
function _setFeatureWeb<K extends keyof UserPreferences>(
@@ -57,18 +60,19 @@ function _setFeatureWeb<K extends keyof UserPreferences>(
5760
);
5861
}
5962

60-
function _setFeatureDesktop<K extends keyof UserPreferences>(
63+
async function _setFeatureDesktop<K extends keyof UserPreferences>(
6164
browser: CompassBrowser,
6265
name: K,
6366
value: UserPreferences[K]
6467
): Promise<AllPreferences> {
65-
return browser.execute(
66-
(_name, _value) => {
68+
return await browser.execute(
69+
async (_name, _value) => {
6770
// eslint-disable-next-line @typescript-eslint/no-require-imports
68-
return require('electron').ipcRenderer.invoke(
71+
const newPreferences = await require('electron').ipcRenderer.invoke(
6972
'compass:save-preferences',
7073
{ [_name]: _value === null ? undefined : _value }
7174
);
75+
return newPreferences;
7276
},
7377
name,
7478
value
@@ -94,15 +98,20 @@ export async function setFeature<K extends keyof UserPreferences>(
9498
let latestValue: UserPreferences[K];
9599
try {
96100
await _waitUntilPreferencesAccessAvailable(browser);
101+
const currentPreferences = await getFeatures(browser);
102+
// We can be running tests against compass version where the preference
103+
// doesn't exist yet (older compass build in smoke tests for example), in
104+
// that case setting preference does nothing, so we will skip the validation
105+
const doesPreferenceExists = name in currentPreferences;
97106
await browser.waitUntil(
98107
async () => {
99108
const newPreferences = await (isTestingWeb()
100109
? _setFeatureWeb
101110
: _setFeatureDesktop)(browser, name, value);
102111
latestValue = newPreferences[name];
103-
return isEqual(latestValue, value);
112+
return doesPreferenceExists ? isEqual(latestValue, value) : true;
104113
},
105-
{ interval: 500 }
114+
{ interval: 1000 }
106115
);
107116
} catch (err) {
108117
const expected = inspect(value);
@@ -135,9 +144,14 @@ export async function getFeature<K extends keyof AllPreferences>(
135144
browser: CompassBrowser,
136145
name: K
137146
): Promise<AllPreferences[K]> {
147+
return (await getFeatures(browser))[name];
148+
}
149+
150+
export async function getFeatures(
151+
browser: CompassBrowser
152+
): Promise<AllPreferences> {
138153
await _waitUntilPreferencesAccessAvailable(browser);
139-
const allPreferences = await (isTestingWeb()
140-
? _getFeaturesWeb
141-
: _getFeaturesDesktop)(browser);
142-
return allPreferences[name];
154+
return await (isTestingWeb() ? _getFeaturesWeb : _getFeaturesDesktop)(
155+
browser
156+
);
143157
}

packages/compass-e2e-tests/helpers/compass.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,6 @@ async function startCompassElectron(
655655
process.env.HADRON_PRODUCT_NAME_OVERRIDE = 'MongoDB Compass WebdriverIO';
656656
}
657657

658-
// Guide cues might affect too many tests in a way where the auto showing of the cue prevents
659-
// clicks from working on elements. Dealing with this case-by-case is way too much work, so
660-
// we disable the cues completely for the e2e tests
661-
process.env.DISABLE_GUIDE_CUES = 'true';
662-
663-
// Making sure end-of-life connection modal is not shown, simplify any test connecting to such a server
664-
process.env.COMPASS_DISABLE_END_OF_LIFE_CONNECTION_MODAL = 'true';
665-
666658
// TODO(COMPASS-9977) Turn off virtual scrolling in e2e tests until we can fix
667659
// browser.scrollToVirtualItem() to work with it
668660
process.env.COMPASS_DISABLE_VIRTUAL_TABLE_RENDERING = 'true';
@@ -1084,6 +1076,26 @@ function augmentError(error: Error, stack: string) {
10841076
error.stack = `${error.stack ?? ''}\nvia ${strippedLines.join('\n')}`;
10851077
}
10861078

1079+
async function setSharedConfigOnStart(browser: CompassBrowser) {
1080+
// Guide cues might affect too many tests in a way where the auto showing of
1081+
// the cue prevents clicks from working on elements. Dealing with this
1082+
// case-by-case is way too much work, so we disable the cues completely for
1083+
// the e2e tests
1084+
await browser.setFeature('enableGuideCues', false);
1085+
1086+
// Making sure end-of-life connection modal is not shown, simplify any test
1087+
// connecting to such a server
1088+
await browser.setFeature('showEndOfLifeConnectionModal', false);
1089+
1090+
// Nice-to-have for desktop tests: if devtools are enabled, you don't need to
1091+
// spend time enabling them manually in settings
1092+
await browser.setFeature('enableDevTools', true, () => {
1093+
// Do not validate that the value was set: some tests might pre-configure
1094+
// Compass in a way where changing this config is not allowed
1095+
return true;
1096+
});
1097+
}
1098+
10871099
export async function init(
10881100
name?: string,
10891101
opts: StartCompassOptions = {}
@@ -1100,8 +1112,7 @@ export async function init(
11001112

11011113
const { browser } = compass;
11021114

1103-
// For browser.executeAsync(). Trying to see if it will work for browser.execute() too.
1104-
await browser.setTimeout({ script: 5_000 });
1115+
await setSharedConfigOnStart(browser);
11051116

11061117
if (TEST_COMPASS_WEB) {
11071118
// larger window for more consistent results

packages/compass-preferences-model/src/preferences-schema.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export type InternalUserPreferences = {
134134
isMaximized?: boolean;
135135
isFullScreen?: boolean;
136136
};
137+
enableGuideCues: boolean;
137138
};
138139

139140
// UserPreferences contains all preferences stored to disk.
@@ -450,11 +451,7 @@ export const storedUserPreferencesProps: Required<{
450451
cli: false,
451452
global: false,
452453
description: null,
453-
validator: z
454-
.boolean()
455-
.default(
456-
process.env.COMPASS_DISABLE_END_OF_LIFE_CONNECTION_MODAL !== 'true'
457-
),
454+
validator: z.boolean().default(true),
458455
type: 'boolean',
459456
},
460457
/**
@@ -488,6 +485,17 @@ export const storedUserPreferencesProps: Required<{
488485
.optional(),
489486
type: 'object',
490487
},
488+
/**
489+
* Whether or not guide cues are enabled in the application
490+
*/
491+
enableGuideCues: {
492+
ui: false,
493+
cli: false,
494+
global: false,
495+
description: null,
496+
validator: z.boolean().default(true),
497+
type: 'boolean',
498+
},
491499
/**
492500
* Enable/disable the AI services. This is currently set
493501
* in the atlas-service initialization where we make a request to the
@@ -721,7 +729,7 @@ export const storedUserPreferencesProps: Required<{
721729
long: `Enable the Chromium Developer Tools that can be used to debug Electron's process.`,
722730
},
723731
deriveValue: deriveFeatureRestrictingOptionsState('enableDevTools'),
724-
validator: z.boolean().default(process.env.APP_ENV === 'webdriverio'),
732+
validator: z.boolean().default(false),
725733
type: 'boolean',
726734
},
727735
/**

0 commit comments

Comments
 (0)