-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WALL] [Fix] Rostislav / WALL-3096 / Fix amounts not fitting in ATM i…
…nputs on mobile (#12377) * refactor: 14 -> 10 max digits * refactor: 10 -> 12 * fix: a poc * fix: edge case * fix: tests * refactor: a minor change + tests
- Loading branch information
1 parent
59a4968
commit 0373314
Showing
5 changed files
with
213 additions
and
20 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
170 changes: 170 additions & 0 deletions
170
...es/Transfer/components/TransferFormAmountInput/__tests__/TransferFormAmountInput.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,170 @@ | ||
/* eslint-disable camelcase */ | ||
import React from 'react'; | ||
import { Formik } from 'formik'; | ||
import { APIProvider } from '@deriv/api'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { TransferProvider } from '../../../provider'; | ||
import { TAccount, TInitialTransferFormValues } from '../../../types'; | ||
import TransferFormAmountInput from '../TransferFormAmountInput'; | ||
|
||
const RATES = { | ||
BTC: { | ||
USD: 44000, | ||
}, | ||
USD: { | ||
BTC: 0.000023, | ||
}, | ||
}; | ||
|
||
const ACCOUNTS: NonNullable<TAccount>[] = [ | ||
{ | ||
account_category: 'wallet', | ||
account_type: 'doughflow', | ||
balance: '1000', | ||
currency: 'USD', | ||
currencyConfig: { | ||
fractional_digits: 2, | ||
}, | ||
}, | ||
{ | ||
account_category: 'wallet', | ||
account_type: 'crypto', | ||
balance: '0.1', | ||
currency: 'BTC', | ||
currencyConfig: { | ||
fractional_digits: 8, | ||
}, | ||
}, | ||
] as NonNullable<TAccount>[]; | ||
|
||
const FORM_VALUES: TInitialTransferFormValues = { | ||
activeAmountFieldName: 'fromAmount', | ||
fromAccount: ACCOUNTS[0], | ||
fromAmount: 0, | ||
toAccount: ACCOUNTS[1], | ||
toAmount: 0, | ||
}; | ||
|
||
jest.mock('@deriv/api', () => ({ | ||
...jest.requireActual('@deriv/api'), | ||
useGetExchangeRate: jest.fn(({ base_currency }: { base_currency: string }) => ({ | ||
data: { | ||
base_currency, | ||
rates: RATES[base_currency as keyof typeof RATES], | ||
}, | ||
refetch: () => ({ | ||
data: { | ||
base_currency, | ||
rates: RATES[base_currency as keyof typeof RATES], | ||
}, | ||
}), | ||
})), | ||
useTransferBetweenAccounts: jest.fn(() => ({ | ||
data: { accounts: ACCOUNTS }, | ||
})), | ||
})); | ||
|
||
describe('TransferFormAmountInput', () => { | ||
it('renders two fields', () => { | ||
render( | ||
<APIProvider> | ||
<TransferProvider accounts={ACCOUNTS}> | ||
{/* eslint-disable-next-line @typescript-eslint/no-empty-function */} | ||
<Formik initialValues={FORM_VALUES} onSubmit={() => {}}> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<TransferFormAmountInput fieldName='fromAmount' /> | ||
</form> | ||
)} | ||
</Formik> | ||
</TransferProvider> | ||
</APIProvider> | ||
); | ||
|
||
const fields = screen.getAllByRole('textbox'); | ||
expect(fields).toHaveLength(2); | ||
}); | ||
|
||
it('has 2 decimal places in case of USD', () => { | ||
render( | ||
<APIProvider> | ||
<TransferProvider accounts={ACCOUNTS}> | ||
{/* eslint-disable-next-line @typescript-eslint/no-empty-function */} | ||
<Formik initialValues={FORM_VALUES} onSubmit={() => {}}> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<TransferFormAmountInput fieldName='fromAmount' /> | ||
</form> | ||
)} | ||
</Formik> | ||
</TransferProvider> | ||
</APIProvider> | ||
); | ||
|
||
const field = screen.getByDisplayValue(/^\d+\.\d+$/u); | ||
expect(field).toHaveValue('0.00'); | ||
}); | ||
|
||
it('has 8 decimal places in case of BTC', () => { | ||
render( | ||
<APIProvider> | ||
<TransferProvider accounts={ACCOUNTS}> | ||
{/* eslint-disable-next-line @typescript-eslint/no-empty-function */} | ||
<Formik initialValues={FORM_VALUES} onSubmit={() => {}}> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<TransferFormAmountInput fieldName='toAmount' /> | ||
</form> | ||
)} | ||
</Formik> | ||
</TransferProvider> | ||
</APIProvider> | ||
); | ||
|
||
const field = screen.getByDisplayValue(/^\d+\.\d+$/u); | ||
expect(field).toHaveValue('0.00000000'); | ||
}); | ||
|
||
it('has 8 max digits restriction in case of USD', () => { | ||
render( | ||
<APIProvider> | ||
<TransferProvider accounts={ACCOUNTS}> | ||
{/* eslint-disable-next-line @typescript-eslint/no-empty-function */} | ||
<Formik initialValues={FORM_VALUES} onSubmit={() => {}}> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<TransferFormAmountInput fieldName='fromAmount' /> | ||
</form> | ||
)} | ||
</Formik> | ||
</TransferProvider> | ||
</APIProvider> | ||
); | ||
|
||
const field = screen.getByDisplayValue(/^\d+\.\d+$/u); | ||
userEvent.type(field, '9999999999999999999999999999'); | ||
expect(field).toHaveValue('999,999.99'); | ||
}); | ||
|
||
it('has 9 max digits restriction in case of BTC', () => { | ||
render( | ||
<APIProvider> | ||
<TransferProvider accounts={ACCOUNTS}> | ||
{/* eslint-disable-next-line @typescript-eslint/no-empty-function */} | ||
<Formik initialValues={FORM_VALUES} onSubmit={() => {}}> | ||
{({ handleSubmit }) => ( | ||
<form onSubmit={handleSubmit}> | ||
<TransferFormAmountInput fieldName='toAmount' /> | ||
</form> | ||
)} | ||
</Formik> | ||
</TransferProvider> | ||
</APIProvider> | ||
); | ||
|
||
const field = screen.getByDisplayValue(/^\d+\.\d+$/u); | ||
userEvent.type(field, '9999999999999999999999999999'); | ||
expect(field).toHaveValue('9.99999999'); | ||
}); | ||
}); |
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
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
0373314
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
deriv-app – ./
binary.sx
deriv-app.vercel.app
deriv-app-git-master.binary.sx
deriv-app.binary.sx