Skip to content

Commit 1b6cade

Browse files
committed
Add feature-indicator test
1 parent 0c72fce commit 1b6cade

File tree

3 files changed

+141
-2
lines changed

3 files changed

+141
-2
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ interface IProps {
2525

2626
export default function ConnectionPanelChevron(props: IProps) {
2727
return (
28-
<Container className={props.className} onClick={props.onToggle}>
28+
<Container
29+
data-testid="connection-panel-chevron"
30+
className={props.className}
31+
onClick={props.onToggle}>
2932
<Chevron
3033
source={props.pointsUp ? 'icon-chevron-up' : 'icon-chevron-down'}
3134
width={24}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ export default function FeatureIndicators(props: FeatureIndicatorsProps) {
157157
ref={featureIndicatorsContainerRef}
158158
$expanded={props.expanded}>
159159
{tunnelState.featureIndicators?.sort().map((indicator) => (
160-
<StyledFeatureIndicatorLabel key={indicator.toString()} $expanded={props.expanded}>
160+
<StyledFeatureIndicatorLabel
161+
key={indicator.toString()}
162+
data-testid="feature-indicator"
163+
$expanded={props.expanded}>
161164
{getFeatureIndicatorLabel(indicator)}
162165
</StyledFeatureIndicatorLabel>
163166
))}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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

Comments
 (0)