Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raksooo authored and dlon committed Oct 18, 2024
1 parent 1c209ec commit 95c0f9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
31 changes: 17 additions & 14 deletions gui/test/e2e/installed/state-dependent/settings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import path from 'path';
import os from 'os';
import { execSync } from 'child_process';
import { expect, Page, test } from '@playwright/test';
import { startInstalledApp } from '../installed-utils';
import { execSync } from 'child_process';
import os from 'os';
import path from 'path';

import { fileExists, TestUtils } from '../../utils';
import { startInstalledApp } from '../installed-utils';

function getAutoStartPath() {
return path.join(os.homedir(), '.config', 'autostart', 'mullvad-vpn.desktop');
Expand All @@ -27,35 +28,37 @@ test.afterAll(async () => {
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'));
await util.waitForNavigation(() => page.click('button[aria-label="Settings"]'));
await util.waitForNavigation(() => 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')
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')
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 launch on start-up toggle
const launchOnStartupToggle =
page.getByText('Launch app on start-up').locator('..').getByRole('checkbox');
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')
await expect(launchOnStartupToggle).toHaveAttribute('aria-checked', 'false');
if (process.platform === 'linux') {
expect(autoStartPathExists()).toBeFalsy();
}
Expand All @@ -64,7 +67,7 @@ test.describe('VPN Settings', () => {
await launchOnStartupToggle.click();

// Verify the setting was applied correctly
await expect(launchOnStartupToggle).toHaveAttribute('aria-checked', 'true')
await expect(launchOnStartupToggle).toHaveAttribute('aria-checked', 'true');
if (process.platform === 'linux') {
expect(autoStartPathExists()).toBeTruthy();
}
Expand All @@ -87,13 +90,13 @@ test.describe('VPN Settings', () => {
// Check initial state
const initialCliState = execSync('mullvad lan get').toString().trim();
expect(initialCliState).toMatch(/block$/);
await expect(lanToggle).toHaveAttribute('aria-checked', 'false')
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')
await expect(lanToggle).toHaveAttribute('aria-checked', 'true');
const newState = execSync('mullvad lan get').toString().trim();
expect(newState).toMatch(/allow$/);
});
Expand Down
5 changes: 2 additions & 3 deletions gui/test/e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import { Locator, Page, _electron as electron, ElectronApplication } from 'playwright';
import { _electron as electron, ElectronApplication, Locator, Page } from 'playwright';

export interface StartAppResponse {
app: ElectronApplication;
Expand Down Expand Up @@ -124,12 +124,11 @@ 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) {
} catch {
return false;
}
}

0 comments on commit 95c0f9b

Please sign in to comment.