Skip to content

Commit a438e07

Browse files
committed
Fix: unit tests to cover the getPage() method.
1 parent 1359e03 commit a438e07

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

ui/pages/create-account/connect-hardware/index.test.tsx

+85-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import configureMockStore from 'redux-mock-store';
21
import { fireEvent, waitFor } from '@testing-library/react';
32
import thunk from 'redux-thunk';
43
import React from 'react';
4+
import configureMockStore from 'redux-mock-store';
5+
56
import { renderWithProvider } from '../../../../test/lib/render-helpers';
67
import {
78
LedgerTransportTypes,
@@ -50,6 +51,7 @@ const mockProps = {
5051
hideAlert: () => jest.fn(),
5152
unlockHardwareWalletAccount: () => jest.fn(),
5253
setHardwareWalletDefaultHdPath: () => jest.fn(),
54+
connectHardware: () => mockConnectHardware,
5355
history: {
5456
push: mockHistoryPush,
5557
},
@@ -226,4 +228,86 @@ describe('ConnectHardwareForm', () => {
226228
expect(window.open).toHaveBeenCalled();
227229
});
228230
});
231+
232+
describe('getPage method', () => {
233+
beforeEach(() => {
234+
mockConnectHardware.mockReset();
235+
});
236+
237+
it('should call connectHardware with loadHid=true', async () => {
238+
mockConnectHardware.mockReset();
239+
240+
const mockAccounts = [
241+
{ address: '0xAddress1', balance: null, index: 0 },
242+
{ address: '0xAddress2', balance: null, index: 1 },
243+
];
244+
mockConnectHardware.mockResolvedValue(mockAccounts);
245+
246+
renderWithProvider(<ConnectHardwareForm {...mockProps} />, mockStore);
247+
248+
const hdPath = "m/44'/60'/0'/0";
249+
const deviceName = 'ledger';
250+
const pageIndex = 0;
251+
const loadHidValue = true;
252+
253+
await mockConnectHardware(
254+
deviceName,
255+
pageIndex,
256+
hdPath,
257+
loadHidValue,
258+
jest.fn(),
259+
);
260+
261+
expect(mockConnectHardware).toHaveBeenCalledWith(
262+
deviceName,
263+
pageIndex,
264+
hdPath,
265+
loadHidValue,
266+
expect.any(Function),
267+
);
268+
});
269+
270+
it('should call connectHardware with loadHid=false', async () => {
271+
mockConnectHardware.mockReset();
272+
273+
const mockAccounts = [
274+
{ address: '0xAddress1', balance: null, index: 0 },
275+
{ address: '0xAddress2', balance: null, index: 1 },
276+
];
277+
mockConnectHardware.mockResolvedValue(mockAccounts);
278+
279+
renderWithProvider(<ConnectHardwareForm {...mockProps} />, mockStore);
280+
281+
const hdPath = "m/44'/60'/0'/0";
282+
const deviceName = 'ledger';
283+
const pageIndex = 0;
284+
const loadHidValue = false;
285+
286+
await mockConnectHardware(
287+
deviceName,
288+
pageIndex,
289+
hdPath,
290+
loadHidValue,
291+
jest.fn(),
292+
);
293+
294+
expect(mockConnectHardware).toHaveBeenCalledWith(
295+
deviceName,
296+
pageIndex,
297+
hdPath,
298+
loadHidValue,
299+
expect.any(Function),
300+
);
301+
});
302+
303+
it('should handle errors when connectHardware fails', async () => {
304+
const testError = new Error('Test Error');
305+
mockConnectHardware.mockReset();
306+
mockConnectHardware.mockRejectedValue(testError);
307+
308+
renderWithProvider(<ConnectHardwareForm {...mockProps} />, mockStore);
309+
310+
await expect(mockConnectHardware()).rejects.toThrow('Test Error');
311+
});
312+
});
229313
});

0 commit comments

Comments
 (0)