-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDailyLimitModal.spec.tsx
103 lines (92 loc) · 3.34 KB
/
DailyLimitModal.spec.tsx
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
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import DailyLimitModal from '../DailyLimitModal';
const mockUseAdvertiserUpdateMutate = jest.fn();
const mockOnRequestClose = jest.fn();
let mockUseAdvertiserUpdate = {
data: {
daily_buy_limit: 100,
daily_sell_limit: 200,
},
error: undefined,
isPending: true,
isSuccess: false,
mutate: mockUseAdvertiserUpdateMutate,
};
jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
api: {
advertiser: {
useUpdate: jest.fn(() => mockUseAdvertiserUpdate),
},
notification: {
useUpdate: jest.fn(() => ({ mutate: jest.fn() })),
},
},
}));
jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
useDevice: () => ({ isMobile: false }),
}));
describe('DailyLimitModal', () => {
it('should render loader when data is not ready', async () => {
render(<DailyLimitModal currency='USD' isModalOpen onRequestClose={mockOnRequestClose} />);
expect(screen.getByTestId('dt_derivs-loader')).toBeVisible();
});
it('should render the correct title and behaviour', async () => {
mockUseAdvertiserUpdate = {
...mockUseAdvertiserUpdate,
isPending: false,
isSuccess: false,
};
render(<DailyLimitModal currency='USD' isModalOpen onRequestClose={mockOnRequestClose} />);
expect(
screen.getByText(
`You won’t be able to change your buy and sell limits again after this. Do you want to continue?`
)
).toBeVisible();
const continueBtn = screen.getByRole('button', {
name: 'Yes, continue',
});
await userEvent.click(continueBtn);
expect(mockUseAdvertiserUpdateMutate).toBeCalledWith({
upgrade_limits: 1,
});
});
it('should render the successful limits increase', async () => {
mockUseAdvertiserUpdate = {
...mockUseAdvertiserUpdate,
isPending: false,
isSuccess: true,
};
render(<DailyLimitModal currency='USD' isModalOpen onRequestClose={mockOnRequestClose} />);
expect(
screen.getByText(`Your daily limits have been increased to 100 USD (buy) and 200 USD (sell).`)
).toBeVisible();
const okBtn = screen.getByRole('button', {
name: 'Ok',
});
await userEvent.click(okBtn);
expect(mockOnRequestClose).toHaveBeenCalled();
});
it('should render the error information when limits are unable to be upgraded', async () => {
mockUseAdvertiserUpdate = {
...mockUseAdvertiserUpdate,
// @ts-expect-error Mock assertion of error
error: new Error(),
isLoading: false,
isSuccess: false,
};
render(<DailyLimitModal currency='USD' isModalOpen onRequestClose={mockOnRequestClose} />);
expect(
screen.getByText(
'Sorry, we’re unable to increase your limits right now. Please try again in a few minutes.'
)
).toBeVisible();
const okBtn = screen.getByRole('button', {
name: 'Ok',
});
await userEvent.click(okBtn);
expect(mockOnRequestClose).toBeCalled();
});
});