summaryrefslogtreecommitdiffhomepage
path: root/gui/test
diff options
context:
space:
mode:
authorOskar <oskar@mullvad.net>2024-09-09 21:50:08 +0200
committerDavid Lönnhager <david.l@mullvad.net>2024-10-18 12:04:18 +0200
commitc6601eebf13510057fd338e60166322b2ddcf908 (patch)
tree914a467ec9a7dbc9236121e4a8bc5393a59dc5d8 /gui/test
parent620a6cf767ff39b7afecbf2c607bbbdba840b6ac (diff)
downloadmullvadvpn-c6601eebf13510057fd338e60166322b2ddcf908.tar.xz
mullvadvpn-c6601eebf13510057fd338e60166322b2ddcf908.zip
Add settings test
Diffstat (limited to 'gui/test')
-rw-r--r--gui/test/e2e/installed/state-dependent/settings.spec.ts85
-rw-r--r--gui/test/e2e/utils.ts13
2 files changed, 97 insertions, 1 deletions
diff --git a/gui/test/e2e/installed/state-dependent/settings.spec.ts b/gui/test/e2e/installed/state-dependent/settings.spec.ts
new file mode 100644
index 0000000000..2b5643a310
--- /dev/null
+++ b/gui/test/e2e/installed/state-dependent/settings.spec.ts
@@ -0,0 +1,85 @@
+import path from 'path';
+import { execSync } from 'child_process';
+import { expect, Page, test } from '@playwright/test';
+import { startInstalledApp } from '../installed-utils';
+import { fileExists, TestUtils } from '../../utils';
+
+if (process.env.HOME === undefined) {
+ throw new Error('$HOME not set');
+}
+
+const AUTOSTART_PATH = path.join(process.env.HOME, '.config', 'autostart', 'mullvad-vpn.desktop');
+
+let page: Page;
+let util: TestUtils;
+
+test.beforeAll(async () => {
+ ({ page, util } = await startInstalledApp());
+});
+
+test.afterAll(async () => {
+ await page.close();
+});
+
+test.describe('VPN Settings', () => {
+ test('Auto-connect setting', async () => {
+ // Navigate to the VPN settings view
+ await util.waitForNavigation(async () => await page.click('button[aria-label="Settings"]'));
+ await util.waitForNavigation(async () => await page.click('text=VPN settings'));
+
+ // Find the auto-connect toggle
+ const autoConnectToggle = page.getByText('Auto-connect').locator('..').getByRole('checkbox');
+
+ // Check initial state
+ const initialCliState = execSync('mullvad auto-connect get').toString().trim();
+ expect(initialCliState).toMatch(/off$/);
+ await expect(autoConnectToggle).toHaveAttribute('aria-checked', 'false')
+
+ // Toggle auto-connect
+ await autoConnectToggle.click();
+
+ // Verify the setting was applied correctly
+ await expect(autoConnectToggle).toHaveAttribute('aria-checked', 'true')
+ const newCliState = execSync('mullvad auto-connect get').toString().trim();
+ expect(newCliState).toMatch(/off$/);
+ });
+
+ test('Launch on startup setting', async () => {
+ // Find the auto-connect toggle
+ const launchOnStartupToggle =
+ page.getByText('Launch app on start-up').locator('..').getByRole('checkbox');
+
+ // Check initial state
+ const initialCliState = execSync('mullvad auto-connect get').toString().trim();
+ expect(initialCliState).toMatch(/off$/);
+ await expect(launchOnStartupToggle).toHaveAttribute('aria-checked', 'false')
+ expect(fileExists(AUTOSTART_PATH)).toBeFalsy();
+
+ // Toggle auto-connect
+ await launchOnStartupToggle.click();
+
+ // Verify the setting was applied correctly
+ await expect(launchOnStartupToggle).toHaveAttribute('aria-checked', 'true')
+ expect(fileExists(AUTOSTART_PATH)).toBeTruthy();
+ const newCliState = execSync('mullvad auto-connect get').toString().trim();
+ expect(newCliState).toMatch(/on$/);
+ });
+
+ test('LAN settings', async () => {
+ // Find the LAN toggle
+ const lanToggle = page.getByText('Local network sharing').locator('..').getByRole('checkbox');
+
+ // Check initial state
+ const initialCliState = execSync('mullvad lan get').toString().trim();
+ expect(initialCliState).toMatch(/block$/);
+ await expect(lanToggle).toHaveAttribute('aria-checked', 'false')
+
+ // Toggle LAN setting
+ await lanToggle.click();
+
+ // Verify the setting was applied correctly
+ await expect(lanToggle).toHaveAttribute('aria-checked', 'true')
+ const newState = execSync('mullvad lan get').toString().trim();
+ expect(newState).toMatch(/allow$/);
+ });
+});
diff --git a/gui/test/e2e/utils.ts b/gui/test/e2e/utils.ts
index 2fb33319f2..3e5e40e75f 100644
--- a/gui/test/e2e/utils.ts
+++ b/gui/test/e2e/utils.ts
@@ -1,4 +1,5 @@
-import { _electron as electron, ElectronApplication, Locator, Page } from 'playwright';
+import fs from 'fs';
+import { Locator, Page, _electron as electron, ElectronApplication } from 'playwright';
export interface StartAppResponse {
app: ElectronApplication;
@@ -122,3 +123,13 @@ export function anyOf(...values: string[]): RegExp {
export function escapeRegExp(regexp: string): string {
return regexp.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
+
+
+export function fileExists(filePath: string): boolean {
+ try {
+ fs.accessSync(filePath);
+ return true;
+ } catch (e) {
+ return false;
+ }
+}