Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / wallet / store / hooks / useBitcoinAddressHighestIndex.test.tsx
blob1e6c8adaec8be8ad127114c99cc62c19f1a2bcf1
1 import type { PropsWithChildren } from 'react';
3 import { renderHook } from '@testing-library/react-hooks';
4 import type { MockedFunction } from 'vitest';
6 import type { WasmBitcoinAddressClient } from '@proton/andromeda';
7 import { ProtonStoreProvider } from '@proton/redux-shared-store';
8 import { getMockedApi } from '@proton/wallet/tests';
10 import { extendStore, setupStore } from '../store';
11 import { useGetBitcoinAddressHighestIndex } from './useBitcoinAddressHighestIndex';
13 describe('useBitcoinAddressHighestIndex', () => {
14     let mockedGetBitcoinAddressHighestIndex: MockedFunction<WasmBitcoinAddressClient['getBitcoinAddressHighestIndex']>;
16     describe('useGetBitcoinAddressHighestIndex', () => {
17         beforeEach(() => {
18             mockedGetBitcoinAddressHighestIndex = vi
19                 .fn()
20                 .mockResolvedValueOnce(BigInt(3))
21                 .mockResolvedValueOnce(BigInt(16))
22                 .mockResolvedValueOnce(BigInt(3))
23                 .mockResolvedValueOnce(BigInt(16));
25             extendStore({
26                 walletApi: getMockedApi({
27                     bitcoin_address: {
28                         getBitcoinAddressHighestIndex: mockedGetBitcoinAddressHighestIndex,
29                     },
30                 }),
31             });
32         });
34         it('should not cache result for each account', async () => {
35             const store = setupStore();
37             function Wrapper({ children }: PropsWithChildren<{}>): JSX.Element {
38                 return <ProtonStoreProvider store={store}>{children}</ProtonStoreProvider>;
39             }
41             const { result } = renderHook(() => useGetBitcoinAddressHighestIndex(), {
42                 wrapper: Wrapper,
43             });
45             expect(await result.current('01', '001')).toBe(3);
46             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledTimes(1);
47             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledWith('01', '001');
49             expect(await result.current('01', '002')).toBe(16);
50             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledTimes(2);
51             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledWith('01', '002');
53             // should not makes call again
54             mockedGetBitcoinAddressHighestIndex.mockClear();
56             expect(await result.current('01', '001')).toBe(3);
57             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledTimes(1);
58             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledWith('01', '001');
60             expect(await result.current('01', '002')).toBe(16);
61             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledTimes(2);
62             expect(mockedGetBitcoinAddressHighestIndex).toHaveBeenCalledWith('01', '002');
63         });
64     });
65 });