diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2024-04-16 08:06:53 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2024-04-19 11:35:01 +0200 |
| commit | a45790318396d5f8b73a55c82d512868968fbe4b (patch) | |
| tree | c42f14c823b239f245a75f563ed5c0c8433e69d5 | |
| parent | b2e98f22541612604a2438746f1e784342d23a6f (diff) | |
| download | mullvadvpn-a45790318396d5f8b73a55c82d512868968fbe4b.tar.xz mullvadvpn-a45790318396d5f8b73a55c82d512868968fbe4b.zip | |
Add GUI test for custom bridge
| -rw-r--r-- | gui/src/renderer/components/OpenVpnSettings.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/components/cell/Selector.tsx | 10 | ||||
| -rw-r--r-- | gui/test/e2e/installed/state-dependent/custom-bridge.spec.ts | 173 |
3 files changed, 183 insertions, 3 deletions
diff --git a/gui/src/renderer/components/OpenVpnSettings.tsx b/gui/src/renderer/components/OpenVpnSettings.tsx index dee1e64089..5013b158f8 100644 --- a/gui/src/renderer/components/OpenVpnSettings.tsx +++ b/gui/src/renderer/components/OpenVpnSettings.tsx @@ -269,6 +269,7 @@ function BridgeModeSelector() { label: messages.gettext('On'), value: 'on', disabled: tunnelProtocol !== 'openvpn' || transportProtocol === 'udp', + 'data-testid': 'bridge-mode-on', }, { label: messages.gettext('Off'), @@ -367,7 +368,7 @@ function BridgeModeSelector() { <SmallButton key="cancel" onClick={hideConfirmationDialog}> {messages.gettext('Cancel')} </SmallButton>, - <SmallButton key="confirm" onClick={confirmBridgeState}> + <SmallButton key="confirm" onClick={confirmBridgeState} data-testid="enable-confirm"> {messages.gettext('Enable')} </SmallButton>, ]} diff --git a/gui/src/renderer/components/cell/Selector.tsx b/gui/src/renderer/components/cell/Selector.tsx index e527017435..5e5d685a59 100644 --- a/gui/src/renderer/components/cell/Selector.tsx +++ b/gui/src/renderer/components/cell/Selector.tsx @@ -16,6 +16,8 @@ export interface SelectorItem<T> { label: string; value: T; disabled?: boolean; + // eslint-disable-next-line @typescript-eslint/naming-convention + 'data-testid'?: string; } // T represents the available values and U represent the value of "Automatic"/"Any" if there is one. @@ -51,7 +53,8 @@ export default function Selector<T, U>(props: SelectorProps<T, U>) { isSelected={selected} disabled={props.disabled || item.disabled} forwardedRef={ref} - onSelect={props.onSelect}> + onSelect={props.onSelect} + data-testid={item['data-testid']}> {item.label} </SelectorCell> ); @@ -133,6 +136,8 @@ interface SelectorCellProps<T> { onSelect: (value: T) => void; children: React.ReactNode | Array<React.ReactNode>; forwardedRef?: React.Ref<HTMLButtonElement>; + // eslint-disable-next-line @typescript-eslint/naming-convention + 'data-testid'?: string; } function SelectorCell<T>(props: SelectorCellProps<T>) { @@ -150,7 +155,8 @@ function SelectorCell<T>(props: SelectorCellProps<T>) { disabled={props.disabled} role="option" aria-selected={props.isSelected} - aria-disabled={props.disabled}> + aria-disabled={props.disabled} + data-testid={props['data-testid']}> <StyledCellIcon $visible={props.isSelected} source="icon-tick" diff --git a/gui/test/e2e/installed/state-dependent/custom-bridge.spec.ts b/gui/test/e2e/installed/state-dependent/custom-bridge.spec.ts new file mode 100644 index 0000000000..5efd110213 --- /dev/null +++ b/gui/test/e2e/installed/state-dependent/custom-bridge.spec.ts @@ -0,0 +1,173 @@ +import { expect, test } from '@playwright/test'; +import { Page } from 'playwright'; + +import { startInstalledApp } from '../installed-utils'; +import { TestUtils } from '../../utils'; +import { colors } from '../../../../src/config.json'; +import { RoutePath } from '../../../../src/renderer/lib/routes'; + +// This test expects the daemon to be logged in and not have a custom bridge configured. +// Env parameters: +// `SHADOWSOCKS_SERVER_IP` +// `SHADOWSOCKS_SERVER_PORT` +// `SHADOWSOCKS_SERVER_CIPHER` +// `SHADOWSOCKS_SERVER_PASSWORD` + +let page: Page; +let util: TestUtils; + +test.beforeAll(async () => { + ({ page, util } = await startInstalledApp()); +}); + +test.afterAll(async () => { + await page.close(); +}); + +test('App should enable bridge mode', async () => { + await util.waitForNavigation(async () => await page.click('button[aria-label="Settings"]')); + expect( + await util.waitForNavigation(async () => await page.getByText('VPN settings').click()), + ).toBe(RoutePath.vpnSettings); + + await page.getByRole('option', { name: 'OpenVPN' }).click(); + + expect( + await util.waitForNavigation(async () => await page.getByText('OpenVPN settings').click()), + ).toBe(RoutePath.openVpnSettings); + + await page.getByTestId('bridge-mode-on').click(); + await expect(page.getByText('Enable bridge mode?')).toBeVisible(); + + page.getByTestId('enable-confirm').click(); + + await util.waitForNavigation(async () => await page.click('button[aria-label="Back"]')); + await util.waitForNavigation(async () => await page.click('button[aria-label="Back"]')); + expect( + await util.waitForNavigation(async () => await page.click('button[aria-label="Close"]')), + ).toBe(RoutePath.main); +}); + +test('App display disabled custom bridge', async () => { + expect( + await util.waitForNavigation( + async () => await page.click('button[aria-label^="Select location"]'), + ), + ).toBe(RoutePath.selectLocation); + + const title = page.locator('h1') + await expect(title).toHaveText('Select location'); + + await page.getByText(/^Entry$/).click(); + + const customBridgeButton = page.getByText('Custom bridge'); + await expect(customBridgeButton).toBeDisabled(); +}); + +test('App should add new custom bridge', async () => { + expect( + await util.waitForNavigation( + async () => await page.click('button[aria-label="Add new custom bridge"]'), + ), + ).toBe(RoutePath.editCustomBridge); + + const title = page.locator('h1') + await expect(title).toHaveText('Add custom bridge'); + + const inputs = page.locator('input'); + const addButton = page.locator('button:has-text("Add")'); + await expect(addButton).toBeVisible(); + await expect(addButton).toBeDisabled(); + + await inputs.first().fill(process.env.SHADOWSOCKS_SERVER_IP!); + await expect(addButton).toBeDisabled(); + + await inputs.nth(1).fill('443'); + await expect(addButton).toBeEnabled(); + + await inputs.nth(2).fill(process.env.SHADOWSOCKS_SERVER_PASSWORD!); + + await page.getByTestId('ciphers').click(); + await page.getByRole('option', { name: process.env.SHADOWSOCKS_SERVER_CIPHER!, exact: true }).click(); + + expect( + await util.waitForNavigation(async () => await addButton.click()) + ).toEqual(RoutePath.selectLocation); + + const customBridgeButton = page.getByText('Custom bridge'); + await expect(customBridgeButton).toBeEnabled(); + + await expect(page.locator('button[aria-label="Edit custom bridge"]')).toBeVisible(); +}); + +test('App should select custom bridge', async () => { + const customBridgeButton = page.locator('button:has-text("Custom bridge")'); + await expect(customBridgeButton).toHaveCSS('background-color', colors.green); + + const automaticButton = page.getByText('Automatic'); + await automaticButton.click(); + await page.getByText(/^Entry$/).click(); + await expect(customBridgeButton).not.toHaveCSS('background-color', colors.green); + + + await customBridgeButton.click(); + await page.getByText(/^Entry$/).click(); + await expect(customBridgeButton).toHaveCSS('background-color', colors.green); + +}); + +test('App should edit custom bridge', async () => { + const automaticButton = page.getByText('Automatic'); + await automaticButton.click(); + await page.getByText(/^Entry$/).click(); + + expect( + await util.waitForNavigation( + async () => await page.click('button[aria-label="Edit custom bridge"]'), + ), + ).toBe(RoutePath.editCustomBridge); + + const title = page.locator('h1') + await expect(title).toHaveText('Edit custom bridge'); + + const inputs = page.locator('input'); + const saveButton = page.locator('button:has-text("Save")'); + await expect(saveButton).toBeVisible(); + await expect(saveButton).toBeEnabled(); + + await inputs.nth(1).fill(process.env.SHADOWSOCKS_SERVER_PORT!); + await expect(saveButton).toBeEnabled(); + + + expect( + await util.waitForNavigation(async () => await saveButton.click()) + ).toEqual(RoutePath.selectLocation); + + const customBridgeButton = page.locator('button:has-text("Custom bridge")'); + await expect(customBridgeButton).toBeEnabled(); + await expect(customBridgeButton).toHaveCSS('background-color', colors.green); +}); + +test('App should delete custom bridge', async () => { + expect( + await util.waitForNavigation( + async () => await page.click('button[aria-label="Edit custom bridge"]'), + ), + ).toBe(RoutePath.editCustomBridge); + + const deleteButton = page.locator('button:has-text("Delete")'); + await expect(deleteButton).toBeVisible(); + await expect(deleteButton).toBeEnabled(); + + await deleteButton.click(); + await expect(page.getByText('Delete custom bridge?')).toBeVisible(); + + const confirmButton = page.getByTestId('delete-confirm'); + expect( + await util.waitForNavigation(async () => await confirmButton.click()) + ).toEqual(RoutePath.selectLocation); + + const customBridgeButton = page.locator('button:has-text("Custom bridge")'); + await expect(customBridgeButton).toBeDisabled(); + await expect(customBridgeButton).not.toHaveCSS('background-color', colors.green); +}); |
