Skip to content

Commit 747d2da

Browse files
committed
WIP
1 parent cf5bf2a commit 747d2da

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,3 +1430,11 @@ export const GlobalWrites = {
14301430
SampleFindingDocuments: '[data-testid="sample-finding-documents"]',
14311431
SampleInsertingDocuments: '[data-testid="sample-inserting-documents"]',
14321432
};
1433+
1434+
export const AutoUpdateToast = '[data-testid="toast-compass-update"]';
1435+
export const AutoUpdateRestartButton =
1436+
'[data-testid="auto-update-restart-button"]';
1437+
export const AutoUpdateDownloadLink =
1438+
'[data-testid="auto-update-download-link"]';
1439+
export const AutoUpdateReleaseNotesLink =
1440+
'[data-testid="auto-update-release-notes-link"]';

packages/compass-e2e-tests/installers/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type Package = {
55
packageFilepath: string;
66
// TODO: once we can download the most recent release
77
//releaseFilepath: string;
8+
updatable: boolean;
89
installer: Installer;
910
};
1011

packages/compass-e2e-tests/smoke-test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import { hideBin } from 'yargs/helpers';
88
import https from 'https';
99
import { pick } from 'lodash';
1010
import { handler as writeBuildInfo } from 'hadron-build/commands/info';
11-
import type { InstalledAppInfo, Package, Installer } from './installers/types';
11+
import type { Package, Installer } from './installers/types';
1212
import { installMacDMG } from './installers/mac-dmg';
13-
import { execute } from './installers/helpers';
1413
import {
1514
assertBuildInfoIsOSX,
1615
assertBuildInfoIsRHEL,
1716
assertBuildInfoIsUbuntu,
1817
assertBuildInfoIsWindows,
1918
assertCommonBuildInfo,
2019
} from './helpers/buildinfo';
20+
import { testAutoUpdateFrom } from './smoketests/auto-update-from';
2121

2222
const argv = yargs(hideBin(process.argv))
2323
.scriptName('smoke-tests')
@@ -202,12 +202,13 @@ async function run() {
202202
}
203203

204204
if (match) {
205-
const pkg = {
205+
const pkg: Package = {
206206
// we need appName because it is the name of the executable inside the
207207
// package, regardless of what the package filename is named or where it
208208
// gets installed
209209
appName: buildInfo.productName,
210210
packageFilepath: path.join(compassDir, 'dist', match.filename),
211+
updatable: match.updatable,
211212
// TODO: releaseFilepath once we download the most recent released version too
212213
installer: match.installer,
213214
};
@@ -234,13 +235,18 @@ async function run() {
234235
// TODO: installing either the packaged file or the released file is better
235236
// done as part of tests so we can also clean up and install one after the
236237
// other, but that's for a separate PR.
238+
/*
237239
console.log('installing', pkg.packageFilepath);
238240
const installedInfo = await pkg.installer({
239241
appName: pkg.appName,
240242
filepath: pkg.packageFilepath,
241243
});
242244
console.log('testing', installedInfo.appPath);
243245
await testInstalledApp(pkg, installedInfo);
246+
*/
247+
await testAutoUpdateFrom(pkg);
248+
// TODO:
249+
//await testAutoUpdateTo(pkg);
244250
} else {
245251
throw new Error(`${context.package} not implemented`);
246252
}
@@ -278,6 +284,7 @@ async function downloadFile(url: string, targetFile: string): Promise<void> {
278284
});
279285
}
280286

287+
/*
281288
function testInstalledApp(
282289
pkg: Package,
283290
appInfo: InstalledAppInfo
@@ -302,6 +309,7 @@ function testInstalledApp(
302309
}
303310
);
304311
}
312+
*/
305313

306314
run()
307315
.then(function () {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { expect } from 'chai';
2+
import {
3+
init,
4+
cleanup,
5+
//screenshotIfFailed,
6+
Selectors,
7+
} from '../helpers/compass';
8+
9+
import type { Package } from '../installers/types';
10+
11+
export async function testAutoUpdateFrom(pkg: Package) {
12+
// install the app
13+
console.log(`installing ${pkg.packageFilepath}`);
14+
const { appPath, uninstall } = await pkg.installer({
15+
appName: pkg.appName,
16+
filepath: pkg.packageFilepath,
17+
});
18+
19+
console.log(appPath);
20+
21+
process.env.COMPASS_APP_NAME = pkg.appName;
22+
process.env.COMPASS_APP_PATH = appPath;
23+
24+
try {
25+
// TODO: start the autoupdate server
26+
try {
27+
// run the app and wait for it to auto-update
28+
const compass = await init('auto-update from', { firstRun: true });
29+
const { browser } = compass;
30+
31+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
32+
33+
if (pkg.updatable) {
34+
await browser.$(Selectors.AutoUpdateRestartButton).waitForDisplayed();
35+
} else {
36+
// When auto-update is not supported the toast contains a link to down
37+
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
38+
await browser.$(linkElement).waitForDisplayed();
39+
expect(await linkElement.getAttribute('href')).to.equal(
40+
'https://www.mongodb.com/try/download/compass'
41+
);
42+
}
43+
44+
await cleanup(compass);
45+
46+
if (pkg.updatable) {
47+
// run the app again and check that the version changed
48+
const compass = await init('auto-update from restart', {
49+
firstRun: false,
50+
});
51+
const { browser } = compass;
52+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
53+
await browser
54+
.$(Selectors.AutoUpdateReleaseNotesLink)
55+
.waitForDisplayed();
56+
}
57+
} finally {
58+
// TODO: stop the autoupdate server
59+
}
60+
} finally {
61+
delete process.env.COMPASS_APP_NAME;
62+
delete process.env.COMPASS_APP_PATH;
63+
64+
// remove the app
65+
await uninstall();
66+
}
67+
}

packages/compass/src/app/components/update-toasts.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const RestartCompassToastContent = ({
5353
<button
5454
className={cx(buttonStyles, darkmode && buttonDarkStyles)}
5555
onClick={onUpdateClicked}
56+
data-testid="auto-update-restart-button"
5657
>
5758
Restart
5859
</button>
@@ -83,6 +84,7 @@ export function onAutoupdateExternally({
8384
Compass features.
8485
</Body>
8586
<Link
87+
data-testid="auto-update-download-link"
8688
as="a"
8789
target="_blank"
8890
href={'https://www.mongodb.com/try/download/compass'}
@@ -137,6 +139,7 @@ export function onAutoupdateInstalled({ newVersion }: { newVersion: string }) {
137139
title: `Compass ${newVersion} installed successfully`,
138140
description: (
139141
<Link
142+
data-testid="auto-update-release-notes-link"
140143
as="a"
141144
target="_blank"
142145
href={`https://github.com/mongodb-js/compass/releases/tag/v${newVersion}`}

0 commit comments

Comments
 (0)