|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { Page } from 'playwright'; |
| 3 | + |
| 4 | +import { MockedTestUtils, startMockedApp } from './mocked-utils'; |
| 5 | +import { FeatureIndicator, ILocation, ITunnelEndpoint, TunnelState } from '../../../src/shared/daemon-rpc-types'; |
| 6 | +import { expectConnected } from '../shared/tunnel-state'; |
| 7 | + |
| 8 | +const endpoint: ITunnelEndpoint = { |
| 9 | + address: 'wg10:80', |
| 10 | + protocol: 'tcp', |
| 11 | + quantumResistant: false, |
| 12 | + tunnelType: 'wireguard', |
| 13 | + daita: false, |
| 14 | +}; |
| 15 | + |
| 16 | +const mockDisconnectedLocation: ILocation = { |
| 17 | + country: 'Sweden', |
| 18 | + city: 'Gothenburg', |
| 19 | + latitude: 58, |
| 20 | + longitude: 12, |
| 21 | + mullvadExitIp: false, |
| 22 | +}; |
| 23 | + |
| 24 | +const mockConnectedLocation: ILocation = { ...mockDisconnectedLocation, mullvadExitIp: true }; |
| 25 | + |
| 26 | +let page: Page; |
| 27 | +let util: MockedTestUtils; |
| 28 | + |
| 29 | +test.beforeAll(async () => { |
| 30 | + ({ page, util } = await startMockedApp()); |
| 31 | +}); |
| 32 | + |
| 33 | +test.afterAll(async () => { |
| 34 | + await page.close(); |
| 35 | +}); |
| 36 | + |
| 37 | +test('App should show no feature indicators', async () => { |
| 38 | + await util.mockIpcHandle<ILocation>({ |
| 39 | + channel: 'location-get', |
| 40 | + response: mockDisconnectedLocation, |
| 41 | + }); |
| 42 | + await util.sendMockIpcResponse<TunnelState>({ |
| 43 | + channel: 'tunnel-', |
| 44 | + response: { |
| 45 | + state: 'connected', |
| 46 | + details: { endpoint, location: mockConnectedLocation }, |
| 47 | + featureIndicators: undefined, |
| 48 | + }, |
| 49 | + }); |
| 50 | + |
| 51 | + await expectConnected(page); |
| 52 | + await expectFeatureIndicators(page, []); |
| 53 | + |
| 54 | + const ellipsis = page.getByText(/^\d more.../); |
| 55 | + await expect(ellipsis).not.toBeVisible(); |
| 56 | + |
| 57 | + await page.getByTestId('connection-panel-chevron').click(); |
| 58 | + await expect(ellipsis).not.toBeVisible(); |
| 59 | + |
| 60 | + await expectFeatureIndicators(page, []); |
| 61 | +}); |
| 62 | + |
| 63 | +test('App should show feature indicators', async () => { |
| 64 | + await util.mockIpcHandle<ILocation>({ |
| 65 | + channel: 'location-get', |
| 66 | + response: mockDisconnectedLocation, |
| 67 | + }); |
| 68 | + await util.sendMockIpcResponse<TunnelState>({ |
| 69 | + channel: 'tunnel-', |
| 70 | + response: { |
| 71 | + state: 'connected', |
| 72 | + details: { endpoint, location: mockConnectedLocation }, |
| 73 | + featureIndicators: [ |
| 74 | + FeatureIndicator.daita, |
| 75 | + FeatureIndicator.udp2tcp, |
| 76 | + FeatureIndicator.customMssFix, |
| 77 | + FeatureIndicator.customMtu, |
| 78 | + FeatureIndicator.lanSharing, |
| 79 | + FeatureIndicator.serverIpOverride, |
| 80 | + FeatureIndicator.customDns, |
| 81 | + FeatureIndicator.lockdownMode, |
| 82 | + FeatureIndicator.quantumResistance, |
| 83 | + FeatureIndicator.multihop, |
| 84 | + ], |
| 85 | + }, |
| 86 | + }); |
| 87 | + |
| 88 | + await expectConnected(page); |
| 89 | + await expectFeatureIndicators(page, ["DAITA", "Quantum resistance"], false); |
| 90 | + await expectHiddenFeatureIndicator(page, "Mssfix"); |
| 91 | + |
| 92 | + const ellipsis = page.getByText(/^\d more.../); |
| 93 | + await expect(ellipsis).toBeVisible(); |
| 94 | + |
| 95 | + await page.getByTestId('connection-panel-chevron').click(); |
| 96 | + await expect(ellipsis).not.toBeVisible(); |
| 97 | + |
| 98 | + await expectFeatureIndicators(page, [ |
| 99 | + "DAITA", |
| 100 | + "Quantum resistance", |
| 101 | + "Mssfix", |
| 102 | + "MTU", |
| 103 | + "Obfuscation", |
| 104 | + "Local network sharing", |
| 105 | + "Lockdown mode", |
| 106 | + "Multihop", |
| 107 | + "Custom DNS", |
| 108 | + "Server IP override", |
| 109 | + ]); |
| 110 | +}); |
| 111 | + |
| 112 | +async function expectHiddenFeatureIndicator(page: Page, hiddenIndicator: string) { |
| 113 | + const indicators = page.getByTestId('feature-indicator'); |
| 114 | + const indicator = indicators.getByText(hiddenIndicator, { exact: true }); |
| 115 | + |
| 116 | + await expect(indicator).toHaveCount(1); |
| 117 | + await expect(indicator).not.toBeVisible(); |
| 118 | +} |
| 119 | + |
| 120 | +async function expectFeatureIndicators( |
| 121 | + page: Page, |
| 122 | + expectedIndicators: Array<string>, |
| 123 | + only = true, |
| 124 | +) { |
| 125 | + const indicators = page.getByTestId('feature-indicator'); |
| 126 | + if (only) { |
| 127 | + await expect(indicators).toHaveCount(expectedIndicators.length); |
| 128 | + } |
| 129 | + |
| 130 | + for (const indicator of expectedIndicators) { |
| 131 | + await expect(indicators.getByText(indicator, { exact: true })).toBeVisible(); |
| 132 | + } |
| 133 | +} |
0 commit comments