diff --git a/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.js b/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.js index a106f97d..da83fff8 100644 --- a/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.js +++ b/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.js @@ -19,16 +19,16 @@ import { Row, } from '@folio/stripes/components'; +import { FILED_NAMES } from './constants'; import { FieldCurrency } from '../Currency'; +import CurrentExchangeRate from './CurrentExchangeRate'; import { TextField } from '../Fields'; import { TooltippedControl } from '../TooltippedControl'; import { IfFieldVisible, VisibilityControl, } from '../VisibilityControl'; -import CurrentExchangeRate from './CurrentExchangeRate'; -import { FILED_NAMES } from './constants'; -import { validateRequired, validateRequiredPositiveAmount } from '../utils'; +import { validateRequiredPositiveAmount } from '../utils'; const CurrencyExchangeRateFields = ({ currencyFieldName, @@ -65,14 +65,6 @@ const CurrencyExchangeRateFields = ({ resetExchangeRate(); }, [change, resetExchangeRate, currencyFieldName]); - const validateExchangeRate = (value) => { - if (value === undefined || value === null) { - return validateRequired(value); - } - - return validateRequiredPositiveAmount(value); - }; - const systemCurrency = stripes.currency; const filledCurrency = get(values, currencyFieldName); const isSetUseExangeRateDisabled = isUseExangeRateDisabled || @@ -154,7 +146,7 @@ const CurrencyExchangeRateFields = ({ readOnly={!isExchangeRateEnabled} tooltipText={tooltipTextExchangeRate} required={isExchangeRateRequired} - validate={isExchangeRateRequired ? validateExchangeRate : undefined} + validate={isExchangeRateRequired ? validateRequiredPositiveAmount : undefined} key={isExchangeRateRequired ? 1 : 0} isNonInteractive={isSetExchangeRateNonIntaractive ?? isNonInteractive} /> diff --git a/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.test.js b/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.test.js index 02fdee32..043681a8 100644 --- a/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.test.js +++ b/lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.test.js @@ -28,11 +28,11 @@ const renderForm = ({ handleSubmit }) => ( const FormCmpt = stripesFinalForm({})(renderForm); -const renderComponent = (props = {}) => (render( +const renderComponent = (props = {}) => render( { }} initialValues={{}} {...props} /> , -)); +); describe('CurrencyExchangeRateFields', () => { it('should display validation messages', async () => { @@ -47,11 +47,8 @@ describe('CurrencyExchangeRateFields', () => { await waitFor(() => expect(screen.getByTestId('use-set-exchange-rate')).toBeChecked()); CurrentExchangeRate.mock.calls[0][0].setExchangeRateRequired(true); - await user.click(screen.getByText('Save')); - - await waitFor(() => expect(screen.getByText('stripes-acq-components.validation.required')).toBeInTheDocument()); await user.type(screen.getByTestId('exchange-rate'), '-1'); - + await user.click(screen.getByText('Save')); await waitFor(() => expect(screen.getByText('stripes-acq-components.validation.shouldBePositiveAmount')).toBeInTheDocument()); });