Skip to content

Commit

Permalink
remove required message
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Sep 26, 2024
1 parent 972efe2 commit 0b7cce5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
16 changes: 4 additions & 12 deletions lib/CurrencyExchangeRateFields/CurrencyExchangeRateFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const renderForm = ({ handleSubmit }) => (

const FormCmpt = stripesFinalForm({})(renderForm);

const renderComponent = (props = {}) => (render(
const renderComponent = (props = {}) => render(
<MemoryRouter>
<FormCmpt onSubmit={() => { }} initialValues={{}} {...props} />
</MemoryRouter>,
));
);

describe('CurrencyExchangeRateFields', () => {
it('should display validation messages', async () => {
Expand All @@ -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());
});

Expand Down

0 comments on commit 0b7cce5

Please sign in to comment.