Skip to content

Commit 1ce2754

Browse files
committed
Fix tunnel-state tests
1 parent 21d366f commit 1ce2754

File tree

6 files changed

+42
-56
lines changed

6 files changed

+42
-56
lines changed

gui/src/renderer/components/main-view/ConnectionActionButton.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const StyledConnectionButton = styled(SmallButton)({
1414
export default function ConnectionActionButton() {
1515
const tunnelState = useSelector((state) => state.connection.status.state);
1616

17-
if (tunnelState === 'disconnected') {
18-
return <ConnectButton />;
17+
if (tunnelState === 'disconnected' || tunnelState === 'disconnecting') {
18+
return <ConnectButton disabled={tunnelState === 'disconnecting'} />;
1919
} else {
20-
return <DisconnectButton disabled={tunnelState === 'disconnecting'} />;
20+
return <DisconnectButton />;
2121
}
2222
}
2323

24-
function ConnectButton() {
24+
function ConnectButton(props: Partial<Parameters<typeof SmallButton>[0]>) {
2525
const { connectTunnel } = useAppContext();
2626

2727
const onConnect = useCallback(async () => {
@@ -34,13 +34,13 @@ function ConnectButton() {
3434
}, []);
3535

3636
return (
37-
<StyledConnectionButton color={SmallButtonColor.green} onClick={onConnect}>
37+
<StyledConnectionButton color={SmallButtonColor.green} onClick={onConnect} {...props}>
3838
{messages.pgettext('tunnel-control', 'Connect')}
3939
</StyledConnectionButton>
4040
);
4141
}
4242

43-
function DisconnectButton(props: Partial<Parameters<typeof SmallButton>[0]>) {
43+
function DisconnectButton() {
4444
const { disconnectTunnel } = useAppContext();
4545
const tunnelState = useSelector((state) => state.connection.status.state);
4646

@@ -56,7 +56,7 @@ function DisconnectButton(props: Partial<Parameters<typeof SmallButton>[0]>) {
5656
const displayAsCancel = tunnelState !== 'connected';
5757

5858
return (
59-
<StyledConnectionButton color={SmallButtonColor.red} onClick={onDisconnect} {...props}>
59+
<StyledConnectionButton color={SmallButtonColor.red} onClick={onDisconnect}>
6060
{displayAsCancel ? messages.gettext('Cancel') : messages.gettext('Disconnect')}
6161
</StyledConnectionButton>
6262
);

gui/src/renderer/components/main-view/ConnectionDetails.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ export default function ConnectionDetails() {
7676
<StyledConnectionDetailsHeading>
7777
{messages.pgettext('connect-view', 'Connection details')}
7878
</StyledConnectionDetailsHeading>
79-
<StyledConnectionDetailsLabel>
79+
<StyledConnectionDetailsLabel data-testid="tunnel-protocol">
8080
{tunnelTypeToString(entry.tunnelType)}
8181
</StyledConnectionDetailsLabel>
8282
<StyledIpTable>
8383
<StyledConnectionDetailsTitle>
8484
{messages.pgettext('connection-info', 'In')}
8585
</StyledConnectionDetailsTitle>
86-
<StyledConnectionDetailsLabel>
86+
<StyledConnectionDetailsLabel data-testid="in-ip">
8787
{`${entry.ip}:${entry.port} ${entry.protocol.toUpperCase()}`}
8888
</StyledConnectionDetailsLabel>
8989
<StyledConnectionDetailsTitle>

gui/src/renderer/components/main-view/ConnectionStatus.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export default function ConnectionStatus() {
1919
const color = getConnectionSTatusLabelColor(tunnelState, lockdownMode);
2020
const text = getConnectionStatusLabelText(tunnelState);
2121

22-
return <StyledConnectionStatus $color={color}>{text}</StyledConnectionStatus>;
22+
return (
23+
<StyledConnectionStatus role="status" $color={color}>
24+
{text}
25+
</StyledConnectionStatus>
26+
);
2327
}
2428

2529
function getConnectionSTatusLabelColor(tunnelState: TunnelState, lockdownMode: boolean) {

gui/src/renderer/components/main-view/Hostname.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function Hostname() {
2727

2828
return (
2929
<StyledAccordion expanded={tunnelState === 'connecting' || tunnelState === 'connected'}>
30-
<StyledHostname>
30+
<StyledHostname data-testid="hostname-line">
3131
<Marquee>{text}</Marquee>
3232
</StyledHostname>
3333
</StyledAccordion>

gui/test/e2e/installed/state-dependent/tunnel-state.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { expect, test } from '@playwright/test';
44
import { Page } from 'playwright';
55
import {
66
expectConnected,
7-
expectConnectedPq,
87
expectDisconnected,
98
expectError,
109
} from '../../shared/tunnel-state';
@@ -35,7 +34,7 @@ test('App should show disconnected tunnel state', async () => {
3534
});
3635

3736
test('App should connect', async () => {
38-
await page.getByText('Secure my connection').click();
37+
await page.getByText('Connect', { exact: true }).click();
3938
await expectConnected(page);
4039

4140
const relay = page.getByTestId('hostname-line');
@@ -151,14 +150,14 @@ test('App should disconnect', async () => {
151150

152151
test('App should create quantum secure connection', async () => {
153152
await exec('mullvad tunnel set wireguard --quantum-resistant on');
154-
await page.getByText('Secure my connection').click();
153+
await page.getByText('Connect').click();
155154

156-
await expectConnectedPq(page);
155+
await expectConnected(page);
157156
});
158157

159158
test('App should show multihop', async () => {
160159
await exec('mullvad relay set tunnel wireguard --use-multihop=on');
161-
await expectConnectedPq(page);
160+
await expectConnected(page);
162161
const relay = page.getByTestId('hostname-line');
163162
await expect(relay).toHaveText(new RegExp('^' + escapeRegExp(`${process.env.HOSTNAME} via`), 'i'));
164163
await exec('mullvad relay set tunnel wireguard --use-multihop=off');

gui/test/e2e/shared/tunnel-state.ts

+23-40
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,62 @@ import { Page } from 'playwright';
33
import { colors } from '../../../src/config.json';
44
import { anyOf } from '../utils';
55

6-
const UNSECURED_COLOR = colors.red;
7-
const SECURE_COLOR = colors.green;
6+
const DISCONNECTED_COLOR = colors.red;
7+
const CONNECTED_COLOR = colors.green;
88
const WHITE_COLOR = colors.white;
99

10-
const UNSECURE_BUTTON_COLOR = anyOf(colors.red60, colors.red80);
11-
const SECURE_BUTTON_COLOR = anyOf(colors.green, colors.green90);
10+
const DISCONNECTED_BUTTON_COLOR = anyOf(colors.red, colors.red80);
11+
const DISCONNECTING_BUTTON_COLOR = anyOf(colors.green40);
12+
const CONNECTED_BUTTON_COLOR = anyOf(colors.green, colors.green90);
1213

1314
const getLabel = (page: Page) => page.locator('span[role="status"]');
1415
const getHeader = (page: Page) => page.locator('header');
1516

1617
export async function expectDisconnected(page: Page) {
1718
await expectTunnelState(page, {
18-
labelText: 'unsecured connection',
19-
labelColor: UNSECURED_COLOR,
20-
headerColor: UNSECURED_COLOR,
21-
buttonText: 'secure my connection',
22-
buttonColor: SECURE_BUTTON_COLOR,
19+
labelText: 'disconnected',
20+
labelColor: DISCONNECTED_COLOR,
21+
headerColor: DISCONNECTED_COLOR,
22+
buttonText: 'connect',
23+
buttonColor: CONNECTED_BUTTON_COLOR,
2324
});
2425
}
2526

2627
export async function expectConnecting(page: Page) {
2728
await expectTunnelState(page, {
28-
labelText: 'creating secure connection',
29+
labelText: 'connecting',
2930
labelColor: WHITE_COLOR,
30-
headerColor: SECURE_COLOR,
31+
headerColor: CONNECTED_COLOR,
3132
buttonText: 'cancel',
32-
buttonColor: UNSECURE_BUTTON_COLOR,
33+
buttonColor: DISCONNECTED_BUTTON_COLOR,
3334
});
3435
}
3536

3637
export async function expectConnected(page: Page) {
3738
await expectTunnelState(page, {
38-
labelText: 'secure connection',
39-
labelColor: SECURE_COLOR,
40-
headerColor: SECURE_COLOR,
39+
labelText: 'connected',
40+
labelColor: CONNECTED_COLOR,
41+
headerColor: CONNECTED_COLOR,
4142
buttonText: 'disconnect',
42-
buttonColor: UNSECURE_BUTTON_COLOR,
43+
buttonColor: DISCONNECTED_BUTTON_COLOR,
4344
});
4445
}
4546

4647
export async function expectDisconnecting(page: Page) {
4748
await expectTunnelState(page, {
48-
headerColor: UNSECURED_COLOR,
49-
buttonText: 'secure my connection',
50-
buttonColor: SECURE_BUTTON_COLOR,
49+
labelText: 'disconnecting',
50+
labelColor: WHITE_COLOR,
51+
headerColor: DISCONNECTED_COLOR,
52+
buttonText: 'connect',
53+
buttonColor: DISCONNECTING_BUTTON_COLOR,
5154
});
5255
}
5356

5457
export async function expectError(page: Page) {
5558
await expectTunnelState(page, {
5659
labelText: 'blocked connection',
5760
labelColor: WHITE_COLOR,
58-
headerColor: SECURE_COLOR,
59-
});
60-
}
61-
62-
export async function expectConnectingPq(page: Page) {
63-
await expectTunnelState(page, {
64-
labelText: 'creating quantum secure connection',
65-
labelColor: WHITE_COLOR,
66-
headerColor: SECURE_COLOR,
67-
buttonText: 'cancel',
68-
buttonColor: UNSECURE_BUTTON_COLOR,
69-
});
70-
}
71-
72-
export async function expectConnectedPq(page: Page) {
73-
await expectTunnelState(page, {
74-
labelText: 'quantum secure connection',
75-
labelColor: SECURE_COLOR,
76-
headerColor: SECURE_COLOR,
77-
buttonText: 'disconnect',
78-
buttonColor: UNSECURE_BUTTON_COLOR,
61+
headerColor: CONNECTED_COLOR,
7962
});
8063
}
8164

0 commit comments

Comments
 (0)