-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathuseWalletHomeOnboardingChecklistFundPress.test.ts
More file actions
112 lines (94 loc) · 3.32 KB
/
useWalletHomeOnboardingChecklistFundPress.test.ts
File metadata and controls
112 lines (94 loc) · 3.32 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { renderHook, act } from '@testing-library/react-native';
import { MetaMetricsEvents } from '../../../core/Analytics';
import { ActionLocation } from '../../../util/analytics/actionButtonTracking';
import { useWalletHomeOnboardingChecklistFundPress } from './useWalletHomeOnboardingChecklistFundPress';
const mockTrackEvent = jest.fn();
const mockAddProperties = jest.fn().mockReturnThis();
const mockBuild = jest.fn().mockReturnValue({ event: 'built' });
const mockCreateEventBuilder = jest.fn(() => ({
addProperties: mockAddProperties,
build: mockBuild,
}));
jest.mock('../../hooks/useAnalytics/useAnalytics', () => ({
useAnalytics: () => ({
trackEvent: mockTrackEvent,
createEventBuilder: mockCreateEventBuilder,
}),
}));
const mockUseRampsButtonClickData = jest.fn();
jest.mock('../Ramp/hooks/useRampsButtonClickData', () => ({
useRampsButtonClickData: () => mockUseRampsButtonClickData(),
}));
const mockUseRampsUnifiedV1Enabled = jest.fn();
jest.mock('../Ramp/hooks/useRampsUnifiedV1Enabled', () => ({
__esModule: true,
default: () => mockUseRampsUnifiedV1Enabled(),
}));
const mockUseRampsUnifiedV2Enabled = jest.fn();
jest.mock('../Ramp/hooks/useRampsUnifiedV2Enabled', () => ({
__esModule: true,
default: () => mockUseRampsUnifiedV2Enabled(),
}));
jest.mock('react-redux', () => ({
useSelector: jest.fn((selector: (...args: unknown[]) => unknown) =>
selector({} as never),
),
}));
jest.mock('../../../reducers/fiatOrders', () => ({
getDetectedGeolocation: () => 'US',
}));
jest.mock('./walletHomeOnboardingStepsStrings', () => ({
walletHomeOnboardingPrimaryLabelForStep: jest.fn(() => 'Add funds'),
}));
const defaultButtonClickData = {
ramp_routing: 'SMART_ROUTING' as const,
is_authenticated: true,
preferred_provider: 'test-provider',
order_count: 2,
};
describe('useWalletHomeOnboardingChecklistFundPress', () => {
const goToBuy = jest.fn();
beforeEach(() => {
jest.clearAllMocks();
mockUseRampsButtonClickData.mockReturnValue(defaultButtonClickData);
mockUseRampsUnifiedV1Enabled.mockReturnValue(false);
mockUseRampsUnifiedV2Enabled.mockReturnValue(false);
});
it('fires RAMPS_BUTTON_CLICKED with location onboarding_checklist then calls goToBuy', () => {
const { result } = renderHook(() =>
useWalletHomeOnboardingChecklistFundPress(goToBuy),
);
act(() => {
result.current();
});
expect(mockCreateEventBuilder).toHaveBeenCalledWith(
MetaMetricsEvents.RAMPS_BUTTON_CLICKED,
);
expect(mockAddProperties).toHaveBeenCalledWith({
button_text: 'Add funds',
location: ActionLocation.ONBOARDING_CHECKLIST,
ramp_type: 'BUY',
region: 'US',
ramp_routing: 'SMART_ROUTING',
is_authenticated: true,
preferred_provider: 'test-provider',
order_count: 2,
});
expect(mockTrackEvent).toHaveBeenCalledWith({ event: 'built' });
expect(goToBuy).toHaveBeenCalledTimes(1);
});
it('uses UNIFIED_BUY_2 ramp_type when V2 unified is enabled', () => {
mockUseRampsUnifiedV2Enabled.mockReturnValue(true);
const { result } = renderHook(() =>
useWalletHomeOnboardingChecklistFundPress(goToBuy),
);
act(() => {
result.current();
});
expect(mockAddProperties).toHaveBeenCalledWith(
expect.objectContaining({
ramp_type: 'UNIFIED_BUY_2',
}),
);
});
});