summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gui/e2e/main.spec.ts62
-rw-r--r--gui/e2e/utils.ts30
2 files changed, 63 insertions, 29 deletions
diff --git a/gui/e2e/main.spec.ts b/gui/e2e/main.spec.ts
index 8114b492f1..444ced7c23 100644
--- a/gui/e2e/main.spec.ts
+++ b/gui/e2e/main.spec.ts
@@ -1,16 +1,17 @@
import { expect, test } from '@playwright/test';
-import { ElectronAppInfo } from 'electron-playwright-helpers';
import { Page } from 'playwright';
+import { ElectronApplication } from 'playwright-core';
+import { ILocation, ITunnelEndpoint, TunnelState } from '../src/shared/daemon-rpc-types';
import { startApp } from './utils';
let appWindow: Page;
-let appInfo: ElectronAppInfo;
+let electronApp: ElectronApplication;
test.beforeAll(async () => {
const startAppResponse = await startApp();
- appInfo = startAppResponse.appInfo;
appWindow = startAppResponse.appWindow;
+ electronApp = startAppResponse.electronApp;
});
test.afterAll(async () => {
@@ -24,24 +25,73 @@ test('Validate title', async () => {
});
test('Validate status and header', async () => {
+ await electronApp.evaluate(({ ipcMain, webContents }) => {
+ const mockLocationResponse = {
+ city: 'Uddevalla',
+ country: 'Norway',
+ latitude: 62,
+ longitude: 17,
+ mullvadExitIp: false,
+ };
+ ipcMain.removeHandler('location-get');
+ ipcMain.handle('location-get', () => {
+ return Promise.resolve({
+ type: 'success',
+ value: mockLocationResponse,
+ });
+ });
+ webContents.getAllWebContents()[0].send('tunnel-', { state: 'disconnected' } as TunnelState);
+ });
+
+ await appWindow.screenshot({ path: 'e2e/screenshots/unsecured.png' });
const statusSpan = appWindow.locator('span[role="status"]');
const header = appWindow.locator('header');
-
await expect(statusSpan).toContainText('UNSECURED CONNECTION');
let headerColor = await header.evaluate((el) => {
return window.getComputedStyle(el).getPropertyValue('background-color');
});
expect(headerColor).toBe('rgb(227, 64, 57)');
- await appWindow.screenshot({ path: `e2e/screenshots/${appInfo.platform}/unsecured.png` });
await appWindow.locator('text=Secure my connection').click();
+ await electronApp.evaluate(({ ipcMain, webContents }) => {
+ const mockLocation: ILocation = {
+ city: 'Uddevalla',
+ country: 'Norway',
+ latitude: 62,
+ longitude: 17,
+ mullvadExitIp: true,
+ };
+ const mockEndpoint: ITunnelEndpoint = {
+ address: 'wg10:80',
+ protocol: 'tcp',
+ quantumResistant: false,
+ tunnelType: 'wireguard',
+ };
+
+ ipcMain.removeHandler('location-get');
+ ipcMain.handle('location-get', () => {
+ return Promise.resolve({
+ type: 'success',
+ value: mockLocation,
+ });
+ });
+
+ webContents.getAllWebContents()[0].send('tunnel-', {
+ state: 'connected',
+ details: {
+ endpoint: mockEndpoint,
+ location: mockLocation,
+ },
+ } as TunnelState);
+ });
+
await expect(statusSpan).toContainText('SECURE CONNECTION');
headerColor = await header.evaluate((el) => {
return window.getComputedStyle(el).getPropertyValue('background-color');
});
expect(headerColor).toBe('rgb(68, 173, 77)');
- await appWindow.screenshot({ path: `e2e/screenshots/${appInfo.platform}/secure.png` });
+ await appWindow.screenshot({ path: 'e2e/screenshots/secure.png' });
await appWindow.locator('text=Disconnect').click();
await expect(statusSpan).toContainText('UNSECURED CONNECTION');
diff --git a/gui/e2e/utils.ts b/gui/e2e/utils.ts
index a588efeee9..78e2229b36 100644
--- a/gui/e2e/utils.ts
+++ b/gui/e2e/utils.ts
@@ -1,45 +1,29 @@
-import { ElectronAppInfo, findLatestBuild, parseElectronApp } from 'electron-playwright-helpers';
import { Page } from 'playwright';
import { _electron as electron, ElectronApplication } from 'playwright-core';
interface StartAppResponse {
electronApp: ElectronApplication;
appWindow: Page;
- appInfo: ElectronAppInfo;
}
const startApp = async (): Promise<StartAppResponse> => {
- // find the latest build in the out directory
- const latestBuild = findLatestBuild('../dist');
- // parse the directory and find paths and other info
- const appInfo = parseElectronApp(latestBuild);
process.env.CI = 'e2e';
const electronApp = await electron.launch({
- args: [appInfo.main],
- executablePath: appInfo.executable,
+ args: ['.'],
});
const appWindow = await electronApp.firstWindow();
- process.env.CI = 'e2e';
-
- electronApp.on('window', (page) => {
- const filename = page.url()?.split('/').pop();
- console.log(`Window opened: ${filename}`);
-
- // capture errors
- page.on('pageerror', (error) => {
- console.error(error);
- });
+ appWindow.on('pageerror', (error) => {
+ console.log(error);
+ });
- // capture console messages
- page.on('console', (msg) => {
- console.log(msg.text());
- });
+ appWindow.on('console', (msg) => {
+ console.log(msg.text());
});
- return { electronApp, appInfo, appWindow };
+ return { electronApp, appWindow };
};
export { startApp };