-
-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathReceiveAddressActions.test.tsx
More file actions
85 lines (66 loc) · 3.26 KB
/
Copy pathReceiveAddressActions.test.tsx
File metadata and controls
85 lines (66 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Share } from 'react-native';
import { getTranslation } from '@suite-native/intl';
import { ReceiveAddressVerificationSource } from '@suite-native/navigation';
import { renderWithBasicProvider, userEvent, waitFor } from '@suite-native/test-utils';
import { ReceiveAddressActions } from './ReceiveAddressActions';
const mockOpenSharedAddressBottomSheet = jest.fn();
const mockCloseSharedAddressBottomSheet = jest.fn();
const mockCopyAddress = jest.fn();
const mockVerifyAddress = jest.fn();
const mockShare = jest.spyOn(Share, 'share');
const mockUseBottomSheetModal = jest.fn();
jest.mock('@suite-native/atoms', () => ({
...jest.requireActual('@suite-native/atoms'),
useBottomSheetModal: () => mockUseBottomSheetModal(),
}));
describe('ReceiveAddressActions', () => {
const address = 'bc1qreceiveaddress';
const renderActions = () =>
renderWithBasicProvider(
<ReceiveAddressActions
address={address}
onCopyAddress={mockCopyAddress}
onVerifyAddress={mockVerifyAddress}
/>,
);
beforeEach(() => {
jest.clearAllMocks();
mockCopyAddress.mockResolvedValue(undefined);
mockShare.mockResolvedValue({ action: Share.sharedAction });
mockUseBottomSheetModal.mockReturnValue({
bottomSheetRef: { current: null },
openModal: mockOpenSharedAddressBottomSheet,
closeModal: mockCloseSharedAddressBottomSheet,
});
});
it('copies the address', async () => {
const { getByText } = renderActions();
await userEvent.press(getByText(getTranslation('qrCode.copyButton')));
await waitFor(() => {
expect(mockCopyAddress).toHaveBeenCalledTimes(1);
expect(mockOpenSharedAddressBottomSheet).not.toHaveBeenCalled();
});
});
it('starts address verification directly', async () => {
const { getByText } = renderActions();
await userEvent.press(getByText(getTranslation('moduleReceive.addressActions.verify')));
expect(mockCloseSharedAddressBottomSheet).not.toHaveBeenCalled();
expect(mockVerifyAddress).toHaveBeenCalledWith(ReceiveAddressVerificationSource.Pasted);
});
it('opens shared address verification after sharing', async () => {
const { getByText, getByTestId } = renderActions();
await userEvent.press(getByText(getTranslation('qrCode.shareButton')));
await userEvent.press(getByTestId('@receive/address-verification/shared/verify-button'));
expect(mockShare).toHaveBeenCalledWith({ message: address });
expect(mockOpenSharedAddressBottomSheet).toHaveBeenCalledTimes(1);
expect(mockCloseSharedAddressBottomSheet).toHaveBeenCalledTimes(1);
expect(mockVerifyAddress).toHaveBeenCalledWith(ReceiveAddressVerificationSource.Shared);
});
it('does not open shared address verification after cancelling sharing', async () => {
mockShare.mockResolvedValue({ action: Share.dismissedAction });
const { getByText } = renderActions();
await userEvent.press(getByText(getTranslation('qrCode.shareButton')));
expect(mockShare).toHaveBeenCalledWith({ message: address });
expect(mockOpenSharedAddressBottomSheet).not.toHaveBeenCalled();
});
});