Skip to content

Commit

Permalink
Add E2E tests for quitOnClose setting
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Pickering <adam.pickering@suse.com>
  • Loading branch information
adamkpickering committed Feb 7, 2023
1 parent 63d27ae commit daba531
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
35 changes: 35 additions & 0 deletions e2e/quit-on-close.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test, expect, _electron, } from '@playwright/test';

import { createDefaultSettings, packageLogs, startRancherDesktop } from './utils/TestUtils';

/**
* Using test.describe.serial make the test execute step by step, as described on each `test()` order
* Playwright executes test in parallel by default and it will not work for our app backend loading process.
* */
test.describe.serial('quitOnClose setting', () => {
test.afterAll(async() => {
await packageLogs(__filename);
});

test('should quit when quitOnClose is true and window is closed', async() => {
createDefaultSettings({ window: { quitOnClose: true } });
const {app, page} = await startRancherDesktop(__filename);
const browserWindowHandle = await app.browserWindow(page);
browserWindowHandle.evaluate((browserWindow: Electron.BrowserWindow) => browserWindow.close());
// Rancher Desktop should be closed by this point. This means that
// app.close() will throw an error, which we consider to be success
// for this test.
await expect(app.close()).rejects.toThrow();
});

test('should not quit when quitOnClose is false and window is closed', async() => {
createDefaultSettings({ window: { quitOnClose: false } });
const {app, page} = await startRancherDesktop(__filename);
const browserWindowHandle = await app.browserWindow(page);
browserWindowHandle.evaluate((browserWindow: Electron.BrowserWindow) => browserWindow.close());
// Rancher Desktop should not be closed, because quitOnClose is false.
// So, calling app.close() should succeed, which we consider to be success
// for this test.
await expect(app.close()).resolves.not.toThrow();
});
});
27 changes: 26 additions & 1 deletion e2e/utils/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs';
import os from 'os';
import path from 'path';

import { expect } from '@playwright/test';
import { expect, _electron, ElectronApplication, Page } from '@playwright/test';
import _ from 'lodash';

import { defaultSettings, Settings } from '@pkg/config/settings';
Expand Down Expand Up @@ -136,3 +136,28 @@ export async function kubectl(...args: string[] ): Promise<string> {
export async function helm(...args: string[] ): Promise<string> {
return await tool('helm', '--kube-context', 'rancher-desktop', ...args);
}

/**
* Run Rancher Desktop; return promise that resolves to commonly-used
* playwright objects when it has started.
* @param testPath The path to the test file.
*/
export async function startRancherDesktop(testPath: string): Promise<{app: ElectronApplication, page: Page}> {
const electronApp = await _electron.launch({
args: [
path.join(__dirname, '../'),
'--disable-gpu',
'--whitelisted-ips=',
// See pkg/rancher-desktop/utils/commandLine.ts before changing the next item as the final option.
'--disable-dev-shm-usage',
'--no-modal-dialogs',
],
env: {
...process.env,
RD_LOGS_DIR: reportAsset(testPath, 'log'),
RD_MOCK_BACKEND: '1',
},
});
const page = await electronApp.firstWindow();
return {app: electronApp, page: page};
}

0 comments on commit daba531

Please sign in to comment.