Skip to content

Commit 1518a90

Browse files
committed
fix: mocks
1 parent 51a4dc2 commit 1518a90

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

.github/workflows/ci-nym-vpn-app-js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747

4848
- name: Run tests
4949
working-directory: nym-vpn-app
50-
run: npm run test
50+
run: npm run test --silent
5151

5252
- name: Check build
5353
working-directory: nym-vpn-app

nym-vpn-app/src/screens/home/__tests__/Home.test.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { screen, waitFor, render as rtlRender } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { invoke } from '@tauri-apps/api/core';
55
import Home from '../Home';
6-
import { useMainDispatch, useMainState } from '../../../contexts';
6+
import {
7+
useMainDispatch,
8+
useMainState,
9+
useNodeListState,
10+
} from '../../../contexts';
711

812
const mockDispatch = jest.fn();
913
const mockNavigate = jest.fn();
@@ -87,6 +91,26 @@ describe('Home Component', () => {
8791
beforeEach(() => {
8892
jest.clearAllMocks();
8993

94+
(
95+
useNodeListState as jest.MockedFunction<typeof useNodeListState>
96+
).mockReturnValue({
97+
reset: jest.fn(),
98+
entry: {
99+
expanded: [],
100+
focused: null,
101+
search: null,
102+
},
103+
exit: {
104+
expanded: [],
105+
focused: null,
106+
search: null,
107+
},
108+
setExpanded: jest.fn(),
109+
addToExpanded: jest.fn(),
110+
setFocused: jest.fn(),
111+
setSearch: jest.fn(),
112+
});
113+
90114
Object.defineProperty(window, '_APP', {
91115
value: {
92116
updaterEnabled: false,

nym-vpn-app/src/screens/home/__tests__/TunnelState.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
useI18nError,
99
useI18nProgressMsg,
1010
} from '../../../hooks';
11+
import { AccountState } from '../../../types';
1112

1213
const mockUseMainState = useMainState as jest.MockedFunction<
1314
typeof useMainState
@@ -68,7 +69,7 @@ describe('TunnelState Component', () => {
6869
});
6970

7071
mockUseI18nAccountState.mockReturnValue({
71-
t: (state: string) => `Account: ${state}`,
72+
t: (state: AccountState) => `Account: ${state}`,
7273
});
7374

7475
mockUseI18nProgressMsg.mockReturnValue({

nym-vpn-app/src/screens/node/list/__tests__/NodeList.test.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
UiGateway,
88
UiCountry,
99
SelectedKind,
10+
useNodeListState,
1011
} from '../../../../contexts';
1112
import { NodeHop, VpnMode } from '../../../../types';
1213

@@ -136,6 +137,26 @@ describe('NodeList', () => {
136137

137138
beforeEach(() => {
138139
jest.clearAllMocks();
140+
141+
(
142+
useNodeListState as jest.MockedFunction<typeof useNodeListState>
143+
).mockReturnValue({
144+
reset: jest.fn(),
145+
entry: {
146+
expanded: [],
147+
focused: null,
148+
search: null,
149+
},
150+
exit: {
151+
expanded: [],
152+
focused: null,
153+
search: null,
154+
},
155+
setExpanded: jest.fn(),
156+
addToExpanded: jest.fn(),
157+
setFocused: jest.fn(),
158+
setSearch: jest.fn(),
159+
});
139160
});
140161

141162
describe('Rendering', () => {
@@ -192,17 +213,6 @@ describe('NodeList', () => {
192213
expect(screen.getAllByTestId('mocked-fold-button')).toHaveLength(2);
193214
});
194215

195-
it('renders accordion content containers', () => {
196-
render(<NodeList {...mockProps} />);
197-
198-
expect(
199-
screen.getByTestId('country-accordion-content-US'),
200-
).toBeInTheDocument();
201-
expect(
202-
screen.getByTestId('country-accordion-content-DE'),
203-
).toBeInTheDocument();
204-
});
205-
206216
it('renders standalone gateways section', () => {
207217
render(<NodeList {...mockProps} gateways={mockStandaloneGateways} />);
208218

nym-vpn-app/src/test/setup.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,19 @@ jest.mock('../contexts', () => ({
7979
useNodeListState: jest.fn(() => ({
8080
reset: jest.fn(),
8181
entry: {
82-
expanded: new Set(),
82+
expanded: [],
8383
focused: null,
84+
search: null,
8485
},
8586
exit: {
86-
expanded: new Set(),
87+
expanded: [],
8788
focused: null,
89+
search: null,
8890
},
8991
setExpanded: jest.fn(),
92+
addToExpanded: jest.fn(),
93+
setFocused: jest.fn(),
94+
setSearch: jest.fn(),
9095
})),
9196
}));
9297

0 commit comments

Comments
 (0)