forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: withdrawal crypto disclaimer and receipt unit tests (deriv-com…
- Loading branch information
1 parent
91d8afb
commit 2fc317b
Showing
8 changed files
with
278 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...rypto/components/WithdrawalCryptoDisclaimer/__tests__/WithdrawalCryptoDisclaimer.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import WithdrawalCryptoDisclaimer from '../WithdrawalCryptoDisclaimer'; | ||
|
||
describe('WithdrawalCryptoDisclaimer', () => { | ||
it('should render content of withdrawal crypto disclaimer', () => { | ||
render(<WithdrawalCryptoDisclaimer />); | ||
|
||
expect(screen.getByText(/Do not enter an address linked to an initial coin offering/)).toBeInTheDocument(); | ||
expect( | ||
screen.getByText(/Please note that your maximum and minimum withdrawal limits aren't fixed./) | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
...onents/WithdrawalCryptoAmountConverter/__tests__/WithdrawalCryptoAmountConverter.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import React from 'react'; | ||
import { Formik } from 'formik'; | ||
import { act, fireEvent, render, screen } from '@testing-library/react'; | ||
import { useWithdrawalCryptoContext } from '../../../../../provider'; | ||
import { validateCryptoInput, validateFiatInput } from '../../../../../utils'; | ||
import WithdrawalCryptoAmountConverter from '../WithdrawalCryptoAmountConverter'; | ||
|
||
jest.mock('../../../../../utils', () => ({ | ||
...jest.requireActual('../../../../../utils'), | ||
validateCryptoInput: jest.fn(), | ||
validateFiatInput: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../../../../provider', () => ({ | ||
...jest.requireActual('../../../../../provider'), | ||
useWithdrawalCryptoContext: jest.fn(), | ||
})); | ||
|
||
const mockUseWithdrawalCryptoContext = useWithdrawalCryptoContext as jest.MockedFunction< | ||
typeof useWithdrawalCryptoContext | ||
>; | ||
const mockValidateCryptoInput = validateCryptoInput as jest.Mock; | ||
const mockValidateFiatInput = validateFiatInput as jest.Mock; | ||
|
||
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => { | ||
return ( | ||
<Formik | ||
initialErrors={{}} | ||
initialValues={{ | ||
cryptoAddress: '', | ||
cryptoAmount: '', | ||
fiatAmount: '', | ||
}} | ||
onSubmit={jest.fn()} | ||
> | ||
{children} | ||
</Formik> | ||
); | ||
}; | ||
|
||
describe('WithdrawalCryptoAmountConverter', () => { | ||
beforeEach(() => { | ||
mockUseWithdrawalCryptoContext.mockReturnValue({ | ||
accountLimits: { | ||
remainder: undefined, | ||
}, | ||
// @ts-expect-error - since this is a mock, we only need partial properties of the hook | ||
activeAccount: { | ||
currency: 'BTC', | ||
}, | ||
fractionalDigits: { | ||
crypto: 8, | ||
fiat: 2, | ||
}, | ||
getConvertedCryptoAmount: (fiatInput: number | string) => fiatInput as string, | ||
getConvertedFiatAmount: (cryptoInput: number | string) => cryptoInput as string, | ||
isClientVerified: false, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should display error below crypto input field if crypto input is invalid', async () => { | ||
mockValidateCryptoInput.mockReturnValue('Crypto Input Error'); | ||
|
||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const cryptoInput = screen.getByTestId('dt_withdrawal_crypto_amount_input'); | ||
|
||
await act(async () => { | ||
await fireEvent.change(cryptoInput, { target: { value: '10' } }); | ||
}); | ||
expect(screen.getByText('Crypto Input Error')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should change value of fiat input field when value of crypto input changes', async () => { | ||
mockValidateCryptoInput.mockReturnValue(''); | ||
|
||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const cryptoInput = screen.getByTestId('dt_withdrawal_crypto_amount_input'); | ||
const fiatInput = screen.getByTestId('dt_withdrawal_fiat_amount_input'); | ||
await act(async () => { | ||
await fireEvent.change(cryptoInput, { target: { value: '10' } }); | ||
}); | ||
expect(fiatInput).toHaveValue('10'); | ||
}); | ||
|
||
it('should empty fiat input field if crypto input field has errors', async () => { | ||
mockValidateCryptoInput.mockReturnValue('Crypto Input Error'); | ||
|
||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const cryptoInput = screen.getByTestId('dt_withdrawal_crypto_amount_input'); | ||
const fiatInput = screen.getByTestId('dt_withdrawal_fiat_amount_input'); | ||
await act(async () => { | ||
await fireEvent.change(cryptoInput, { target: { value: '10' } }); | ||
}); | ||
expect(fiatInput).toHaveValue(''); | ||
}); | ||
|
||
it('should display error below fiat input field if fiat input is invalid', async () => { | ||
mockValidateFiatInput.mockReturnValue('Fiat Input Error'); | ||
|
||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const fiatInput = screen.getByTestId('dt_withdrawal_fiat_amount_input'); | ||
|
||
await act(async () => { | ||
await fireEvent.change(fiatInput, { target: { value: '10' } }); | ||
}); | ||
expect(screen.getByText('Fiat Input Error')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should change value of crypto input field when value of fiat input changes', async () => { | ||
mockValidateFiatInput.mockReturnValue(''); | ||
|
||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const cryptoInput = screen.getByTestId('dt_withdrawal_crypto_amount_input'); | ||
const fiatInput = screen.getByTestId('dt_withdrawal_fiat_amount_input'); | ||
await act(async () => { | ||
await fireEvent.change(fiatInput, { target: { value: '10' } }); | ||
}); | ||
expect(cryptoInput).toHaveValue('10'); | ||
}); | ||
|
||
it('should empty crypto input field if fiat input field has errors', async () => { | ||
mockValidateFiatInput.mockReturnValue('Fiat Input Error'); | ||
|
||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const cryptoInput = screen.getByTestId('dt_withdrawal_crypto_amount_input'); | ||
const fiatInput = screen.getByTestId('dt_withdrawal_fiat_amount_input'); | ||
await act(async () => { | ||
await fireEvent.change(fiatInput, { target: { value: '10' } }); | ||
}); | ||
expect(cryptoInput).toHaveValue(''); | ||
}); | ||
|
||
it('should handle onFocus for crypto input field', async () => { | ||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const cryptoInput = screen.getByTestId('dt_withdrawal_crypto_amount_input'); | ||
await act(async () => { | ||
await fireEvent.focus(cryptoInput); | ||
}); | ||
|
||
expect(screen.queryByTestId('dt_withdrawal_crypto_amount_converter_arrow')).not.toHaveClass( | ||
'wallets-withdrawal-crypto-amount-converter__arrow--rtl' | ||
); | ||
}); | ||
|
||
it('should handle onFocus for fiat input field', async () => { | ||
render(<WithdrawalCryptoAmountConverter />, { wrapper }); | ||
|
||
const fiatInput = screen.getByTestId('dt_withdrawal_fiat_amount_input'); | ||
await act(async () => { | ||
await fireEvent.focus(fiatInput); | ||
}); | ||
|
||
expect(screen.getByTestId('dt_withdrawal_crypto_amount_converter_arrow')).toHaveClass( | ||
'wallets-withdrawal-crypto-amount-converter__arrow--rtl' | ||
); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
...rawalCrypto/components/WithdrawalCryptoReceipt/__tests__/WithdrawalCryptoReceipt.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { PropsWithChildren } from 'react'; | ||
import { APIProvider, AuthProvider } from '@deriv/api-v2'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import WithdrawalCryptoReceipt from '../WithdrawalCryptoReceipt'; | ||
|
||
const mockPush = jest.fn(); | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useHistory: jest.fn(() => ({ | ||
push: mockPush, | ||
})), | ||
})); | ||
|
||
const mockWithdrawalReceipt = { | ||
address: 'test_crypto_address', | ||
}; | ||
|
||
const wrapper = ({ children }: PropsWithChildren) => ( | ||
<APIProvider> | ||
<AuthProvider>{children}</AuthProvider> | ||
</APIProvider> | ||
); | ||
|
||
describe('WithdrawalCryptoReceipt', () => { | ||
it('should render the component with withdrawal information', () => { | ||
const mockBTCWithdrawalReceipt = { | ||
address: 'test_crypto_address', | ||
amount: '100', | ||
currency: 'BTC', | ||
}; | ||
render(<WithdrawalCryptoReceipt onClose={() => jest.fn()} withdrawalReceipt={mockBTCWithdrawalReceipt} />, { | ||
wrapper, | ||
}); | ||
|
||
const amountElement = screen.getByText('100 BTC'); | ||
expect(amountElement).toBeInTheDocument(); | ||
|
||
const addressElement = screen.getByText('test_crypto_address'); | ||
expect(addressElement).toBeInTheDocument(); | ||
|
||
const reviewTextElement = screen.getByText( | ||
'Your withdrawal is currently in review. It will be processed within 24 hours. We’ll send you an email once your transaction has been processed.' | ||
); | ||
expect(reviewTextElement).toBeInTheDocument(); | ||
}); | ||
|
||
it('should trigger the close function when the "Close" button is clicked', () => { | ||
const onCloseMock = jest.fn(); | ||
|
||
render(<WithdrawalCryptoReceipt onClose={onCloseMock} withdrawalReceipt={mockWithdrawalReceipt} />, { | ||
wrapper, | ||
}); | ||
|
||
fireEvent.click(screen.getByText('Close')); | ||
|
||
expect(onCloseMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should navigate to the transactions page when the "View transactions" button is clicked', () => { | ||
render(<WithdrawalCryptoReceipt onClose={() => jest.fn()} withdrawalReceipt={mockWithdrawalReceipt} />, { | ||
wrapper, | ||
}); | ||
|
||
fireEvent.click(screen.getByText('View transactions')); | ||
|
||
expect(mockPush).toHaveBeenCalledWith('/wallets/cashier/transactions'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../WithdrawalCryptoDestinationAddress/__tests__/WithdrawalCryptoDestinationAddress.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import WithdrawalCryptoDestinationAddress from '../WithdrawalCryptoDestinationAddress'; | ||
|
||
describe('WithdrawalCryptoDestinationAddress', () => { | ||
it('should render the component with the provided address', () => { | ||
const address = 'your_crypto_address'; | ||
render(<WithdrawalCryptoDestinationAddress address={address} />); | ||
|
||
const addressElement = screen.getByText(address); | ||
expect(addressElement).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the component without an address', () => { | ||
render(<WithdrawalCryptoDestinationAddress />); | ||
|
||
const noAddressElement = screen.getByText('Destination address'); | ||
expect(noAddressElement).toBeInTheDocument(); | ||
}); | ||
}); |