Skip to content

Commit 8ea415b

Browse files
authored
[WALL] Lubega / WALL-2988 / TransactionStatusSuccess unit test (deriv-com#13062)
* chore: transaction status success unit test * fix: applied comments * fix: rerun workflow
1 parent bb69546 commit 8ea415b

File tree

1 file changed

+229
-0
lines changed

1 file changed

+229
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
import React from 'react';
2+
import { useHistory } from 'react-router-dom';
3+
import { APIProvider } from '@deriv/api';
4+
import { fireEvent, render, screen } from '@testing-library/react';
5+
import { ModalProvider } from '../../../../../../../components/ModalProvider';
6+
import TransactionStatusSuccess from '../TransactionStatusSuccess';
7+
8+
jest.mock('react-router-dom', () => ({
9+
useHistory: jest.fn(),
10+
}));
11+
const mockUseHistory = useHistory as jest.Mock;
12+
13+
const mockTransactions = [
14+
{
15+
address_hash: '',
16+
address_url: '',
17+
amount: 0.0001,
18+
description: '',
19+
formatted_address_hash: '',
20+
formatted_amount: '',
21+
formatted_confirmations: '',
22+
formatted_transaction_hash: '',
23+
id: '',
24+
is_deposit: false,
25+
is_valid_to_cancel: 1 as const,
26+
is_withdrawal: true,
27+
status_code: 'LOCKED' as const,
28+
status_message: '',
29+
status_name: '',
30+
submit_date: 123456,
31+
transaction_type: 'withdrawal' as const,
32+
},
33+
];
34+
35+
const mockWallet = {
36+
account_category: 'wallet' as const,
37+
account_type: '',
38+
balance: 1,
39+
broker: '',
40+
created_at: new Date('01/01/1970'),
41+
currency: '',
42+
currency_config: {
43+
code: '',
44+
display_code: '',
45+
fractional_digits: 1,
46+
is_AUD: false,
47+
is_BTC: true,
48+
is_BUSD: false,
49+
is_crypto: true,
50+
is_DAI: false,
51+
is_deposit_suspended: 0 as const,
52+
is_ETH: false,
53+
is_EUR: false,
54+
is_EURS: false,
55+
is_eUSDT: false,
56+
is_fiat: false,
57+
is_GBP: false,
58+
is_IDK: false,
59+
is_LTC: false,
60+
is_PAX: false,
61+
is_suspended: 0 as const,
62+
is_TUSD: false,
63+
is_tUSDT: false,
64+
is_USB: false,
65+
is_USD: false,
66+
is_USDC: false,
67+
is_USDK: false,
68+
is_USDT: false,
69+
is_withdrawal_suspended: 0 as const,
70+
minimum_withdrawal: 0.1,
71+
name: '',
72+
stake_default: 0.1,
73+
transfer_between_accounts: {
74+
fees: {},
75+
limits: { max: 0.1, min: 0.1 },
76+
limits_ctrader: { max: 0.1, min: 0.1 },
77+
limits_derivez: { max: 0.1, min: 0.1 },
78+
limits_dxtrade: { max: 0.1, min: 0.1 },
79+
limits_mt5: { max: 0.1, min: 0.1 },
80+
},
81+
type: 'crypto' as const,
82+
},
83+
display_balance: '',
84+
dtrade_loginid: undefined,
85+
excluded_until: undefined,
86+
is_active: true,
87+
is_crypto: true,
88+
is_disabled: false,
89+
is_malta_wallet: false,
90+
is_mf: false,
91+
is_trading: false,
92+
is_virtual: false,
93+
is_wallet: true,
94+
landing_company_name: '',
95+
linked_to: [],
96+
loginid: '',
97+
platform: 'deriv' as const,
98+
wallet_currency_type: '',
99+
};
100+
101+
describe('TransactionStatusSuccess', () => {
102+
beforeEach(() => {
103+
jest.clearAllMocks();
104+
});
105+
106+
it('should render winthdrawal info for withdrawal transactions', () => {
107+
render(
108+
<APIProvider>
109+
<ModalProvider>
110+
<TransactionStatusSuccess
111+
transactionType='withdrawal'
112+
transactions={mockTransactions}
113+
wallet={mockWallet}
114+
/>
115+
</ModalProvider>
116+
</APIProvider>
117+
);
118+
119+
expect(screen.getByText('Withdrawal')).toBeInTheDocument();
120+
expect(screen.getByText('0.0001')).toBeInTheDocument();
121+
expect(screen.queryByText('No recent transactions.')).not.toBeInTheDocument();
122+
expect(screen.queryByText('View more')).not.toBeInTheDocument();
123+
});
124+
125+
it('should render deposit info for deposit transactions', () => {
126+
const mockDeposit = [
127+
{
128+
address_hash: '',
129+
address_url: '',
130+
amount: 0.0001,
131+
description: '',
132+
formatted_address_hash: '',
133+
formatted_amount: '',
134+
formatted_confirmations: '',
135+
formatted_transaction_hash: '',
136+
id: '',
137+
is_deposit: true,
138+
is_valid_to_cancel: 1 as const,
139+
is_withdrawal: false,
140+
status_code: 'LOCKED' as const,
141+
status_message: '',
142+
status_name: '',
143+
submit_date: 123456,
144+
transaction_type: 'withdrawal' as const,
145+
},
146+
];
147+
148+
render(
149+
<APIProvider>
150+
<ModalProvider>
151+
<TransactionStatusSuccess
152+
transactionType='deposit'
153+
transactions={mockDeposit}
154+
wallet={mockWallet}
155+
/>
156+
</ModalProvider>
157+
</APIProvider>
158+
);
159+
160+
expect(screen.getByText('Deposit')).toBeInTheDocument();
161+
expect(screen.getByText('0.0001')).toBeInTheDocument();
162+
expect(screen.queryByText('No recent transactions.')).not.toBeInTheDocument();
163+
expect(screen.queryByText('View more')).not.toBeInTheDocument();
164+
});
165+
166+
it('should render "No recent transactions" when there are no transactions', () => {
167+
render(
168+
<APIProvider>
169+
<ModalProvider>
170+
<TransactionStatusSuccess transactions={[]} wallet={mockWallet} />
171+
</ModalProvider>
172+
</APIProvider>
173+
);
174+
175+
expect(screen.getByText('No recent transactions.')).toBeInTheDocument();
176+
expect(screen.queryByText('Deposit')).not.toBeInTheDocument();
177+
expect(screen.queryByText('Withdrawal')).not.toBeInTheDocument();
178+
expect(screen.queryByText('View more')).not.toBeInTheDocument();
179+
});
180+
181+
it('should render correct elements when there are more than 3 transactions', () => {
182+
const pushMock = jest.fn();
183+
mockUseHistory.mockReturnValue({ push: pushMock });
184+
185+
for (let i = 0; i < 5; i++) {
186+
const newTransaction = {
187+
address_hash: '',
188+
address_url: '',
189+
amount: 0.0001,
190+
description: '',
191+
formatted_address_hash: '',
192+
formatted_amount: '',
193+
formatted_confirmations: '',
194+
formatted_transaction_hash: '',
195+
id: '',
196+
is_deposit: false,
197+
is_valid_to_cancel: 1 as const,
198+
is_withdrawal: true,
199+
status_code: 'LOCKED' as const,
200+
status_message: '',
201+
status_name: '',
202+
submit_date: 123456,
203+
transaction_type: 'withdrawal' as const,
204+
};
205+
206+
mockTransactions.push(newTransaction);
207+
}
208+
209+
render(
210+
<APIProvider>
211+
<ModalProvider>
212+
<TransactionStatusSuccess
213+
transactionType='withdrawal'
214+
transactions={mockTransactions}
215+
wallet={mockWallet}
216+
/>
217+
</ModalProvider>
218+
</APIProvider>
219+
);
220+
221+
expect(screen.queryByText('No recent transactions.')).not.toBeInTheDocument();
222+
expect(screen.getAllByText('Withdrawal')[0]).toBeInTheDocument();
223+
expect(screen.getAllByText('0.0001')[0]).toBeInTheDocument();
224+
expect(screen.getByText('View more')).toBeInTheDocument();
225+
226+
fireEvent.click(screen.getByText('View more'));
227+
expect(pushMock).toHaveBeenCalledWith('/wallets/cashier/transactions?showPending');
228+
});
229+
});

0 commit comments

Comments
 (0)