-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UISACQCOMP-218: add "Amount must be a positive number" validation for "Set exchange rate" field. #815
UISACQCOMP-218: add "Amount must be a positive number" validation for "Set exchange rate" field. #815
Changes from 6 commits
b604627
731b753
e6c31bb
bfcf518
ea94317
c34d15f
972efe2
0b7cce5
c787856
bcc4a6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import React from 'react'; | ||
import { render, cleanup, fireEvent } from '@testing-library/react'; | ||
import { noop } from 'lodash'; | ||
import { fireEvent, render, cleanup } from '@testing-library/react'; | ||
|
||
import CountryFilter from './CountryFilter'; | ||
|
||
|
@@ -25,7 +24,7 @@ describe('CountryFilter component', () => { | |
expect(getByText('ui-organizations.filterConfig.country')).toBeDefined(); | ||
}); | ||
|
||
it('should invoke onChange callback when something is selected', async () => { | ||
it('should invoke onChange callback when something is selected', () => { | ||
const onChangeFilter = jest.fn(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
const { container, getByText } = renderFilter(false, onChangeFilter); | ||
const button = container.querySelector('[id="org-filter-country-selection"]'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ import { | |
} from '../VisibilityControl'; | ||
import CurrentExchangeRate from './CurrentExchangeRate'; | ||
import { FILED_NAMES } from './constants'; | ||
import { validateRequired } from '../utils'; | ||
import { validateRequired, validateRequiredPositiveAmount } from '../utils'; | ||
|
||
const CurrencyExchangeRateFields = ({ | ||
currencyFieldName, | ||
|
@@ -65,6 +65,14 @@ const CurrencyExchangeRateFields = ({ | |
resetExchangeRate(); | ||
}, [change, resetExchangeRate, currencyFieldName]); | ||
|
||
const validateExchangeRate = (value) => { | ||
if (value === undefined || value === null) { | ||
return validateRequired(value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where did you find such requirement? doing this you introduce inconsistency |
||
} | ||
|
||
return validateRequiredPositiveAmount(value); | ||
}; | ||
|
||
const systemCurrency = stripes.currency; | ||
const filledCurrency = get(values, currencyFieldName); | ||
const isSetUseExangeRateDisabled = isUseExangeRateDisabled || | ||
|
@@ -118,9 +126,9 @@ const CurrencyExchangeRateFields = ({ | |
<TooltippedControl | ||
controlComponent={Checkbox} | ||
checked={isExchangeRateEnabled} | ||
data-testid="use-set-exhange-rate" | ||
data-testid="use-set-exchange-rate" | ||
readOnly={isSetUseExangeRateDisabled} | ||
id="use-set-exhange-rate" | ||
id="use-set-exchange-rate" | ||
label={<FormattedMessage id="stripes-acq-components.useSetExchangeRate" />} | ||
onChange={enableExchangeRate} | ||
vertical | ||
|
@@ -146,7 +154,7 @@ const CurrencyExchangeRateFields = ({ | |
readOnly={!isExchangeRateEnabled} | ||
tooltipText={tooltipTextExchangeRate} | ||
required={isExchangeRateRequired} | ||
validate={isExchangeRateRequired ? validateRequired : undefined} | ||
validate={isExchangeRateRequired ? validateExchangeRate : undefined} | ||
key={isExchangeRateRequired ? 1 : 0} | ||
isNonInteractive={isSetExchangeRateNonIntaractive ?? isNonInteractive} | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,14 @@ const renderFieldLocationFinalContainer = (props = {}, formProps = {}) => (rende | |
)); | ||
|
||
describe('FieldLocationFinalContainer component', () => { | ||
beforeEach(() => { | ||
renderFieldLocationFinalContainer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you do it in before each, why do you keep render in tests? if you want to avoid such code duplication - update render function, it's not a place for beforeEach |
||
|
||
const button = screen.getByText('stripes-components.selection.controlLabel'); | ||
|
||
fireEvent.click(button); | ||
}); | ||
|
||
it('should display passed label', () => { | ||
renderFieldLocationFinalContainer({ labelId: 'Location' }); | ||
|
||
|
@@ -41,8 +49,6 @@ describe('FieldLocationFinalContainer component', () => { | |
it('should render options based on passed locationIds', async () => { | ||
renderFieldLocationFinalContainer(); | ||
|
||
fireEvent.click(screen.getByText('stripes-components.selection.controlLabel')); | ||
|
||
const renderedLocationOptions = await screen.findAllByText(/Location #[0-9]/); | ||
|
||
expect(renderedLocationOptions.length).toBe(locationsIds.length); | ||
|
@@ -53,8 +59,6 @@ describe('FieldLocationFinalContainer component', () => { | |
filterLocations: (records) => records.slice(0, 2), | ||
}); | ||
|
||
fireEvent.click(screen.getByText('stripes-components.selection.controlLabel')); | ||
|
||
const renderedLocationOptions = await screen.findAllByText(/Location #[0-9]/); | ||
|
||
expect(renderedLocationOptions).toHaveLength(2); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import React from 'react'; | ||
import { render, cleanup, fireEvent } from '@testing-library/react'; | ||
import { | ||
cleanup, | ||
Check warning on line 2 in lib/LanguageFilter/LanguageFilter.test.js GitHub Actions / github-actions-ci
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you removed function call, but not import... |
||
fireEvent, | ||
render, | ||
} from '@testing-library/react'; | ||
import { noop } from 'lodash'; | ||
|
||
import LanguageFilter from './LanguageFilter'; | ||
|
@@ -17,8 +20,6 @@ | |
)); | ||
|
||
describe('LanguageFilter component', () => { | ||
afterEach(cleanup); | ||
|
||
it('should display passed title', () => { | ||
const { getByText } = renderFilter(); | ||
|
||
|
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.
it's not async