Skip to content
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-159: fix A user can not save edited PO line issue #713

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Fund distribution can be saved with a "blank" expense class. Refs UISACQCOMP-156.
* *BREAKING* Update `react` to `v18`. Refs UISACQCOMP-157.
* Update `Node.js` to `v18` in GitHub Actions. Refs UISACQCOMP-158.
* A user can not save edited PO line when budget without expense class was selected. Refs UISACQCOMP-159.

## [4.0.2](https://github.com/folio-org/stripes-acq-components/tree/v4.0.2) (2023-03-17)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v4.0.1...v4.0.2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ const FundDistributionFieldsFinal = ({
onSelectFund(elem, selectedFundId);
};

const { fundId, expenseClassId } = fields.value[index];
const { fundId, expenseClassId, value: fieldValue } = fields.value[index];

const expenseClassesForSelect = expenseClassesByFundId[fundId]?.map(expenseClass => ({
label: expenseClass.name,
value: expenseClass.id,
Expand All @@ -162,7 +163,7 @@ const FundDistributionFieldsFinal = ({
}

return (
<Row>
<Row key={fundId}>
<Col xs>
<FieldSelectionFinal
dataOptions={fundsOptions}
Expand All @@ -174,7 +175,7 @@ const FundDistributionFieldsFinal = ({
onChange={selectFund}
validate={required ? validateRequired : undefined}
validateFields={[name]}
onBlur={() => debouncedValidate(fields.value)}
beforeSubmit={() => (required ? Boolean(fundId) : true)}
/>
</Col>
<Col xs>
Expand All @@ -188,7 +189,7 @@ const FundDistributionFieldsFinal = ({
isNonInteractive={disabled}
validateFields={[]}
key={expenseClassId}
beforeSubmit={() => Boolean(expenseClassId)}
beforeSubmit={() => (required ? Boolean(expenseClassId) : true)}
/>
)}
</Col>
Expand All @@ -205,6 +206,7 @@ const FundDistributionFieldsFinal = ({
validate={required ? validateRequired : undefined}
isNonInteractive={disabled}
validateFields={[name]}
beforeSubmit={() => (required ? Boolean(fieldValue) : true)}
/>
</Col>
<Col xs>
Expand Down Expand Up @@ -233,7 +235,6 @@ const FundDistributionFieldsFinal = ({
amounts,
currency,
disabled,
debouncedValidate,
expenseClassesByFundId,
funds,
fundsForSelect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('FundDistributionFieldsFinal', () => {
expect(validateFundDistributionTotalDefault).toHaveBeenCalled();
});

it('should call validateRequired onBlur fundDistribution selection', async () => {
it('should call validateRequired for fundId selection', async () => {
const expenseClassesByFundId = { [FUNDS[0].id]: [{ id: 'expClassId', name: 'expClassName' }] };
const fundDistribution = [{
code: FUNDS[0].code,
Expand All @@ -167,21 +167,55 @@ describe('FundDistributionFieldsFinal', () => {
expect(validation).toHaveBeenCalled();
});

it('should call beforeSubmit validation on submit form', async () => {
it.each`
required
${true}
${false}
`('should call beforeSubmit validation with required = $required for expanseClass field on submit form', async ({ required }) => {
const expenseClassesByFundId = {
[FUNDS[1].id]: [{ id: 'expClassId', name: 'expClassName 1' }, { id: 'expClassId', name: 'expClassName 2' }],
};
const fundDistribution = [{ code: 'TEST', fundId: '2', value: 100, distributionType: FUND_DISTR_TYPE.percent }];

renderComponent({ required: true, fundDistribution, expenseClassesByFundId });
renderComponent({ required, fundDistribution, expenseClassesByFundId });
const valueInput = await screen.findByText('stripes-acq-components.fundDistribution.expenseClass');

expect(valueInput).toBeInTheDocument();
user.click(screen.getByText('expClassName 2'));
user.tab();

user.click(screen.getByText('Submit'));
expect(screen.getByText('error message')).toBeInTheDocument();
if (required) {
expect(screen.getByText('error message')).toBeInTheDocument();
} else {
expect(screen.queryByText('error message')).not.toBeInTheDocument();
}
});

it.each`
required
${true}
${false}
`('should call beforeSubmit validation with required = $required for value field on submit form', async ({ required }) => {
const expenseClassesByFundId = {
[FUNDS[1].id]: [{ id: 'expClassId', name: 'expClassName 1' }, { id: 'expClassId', name: 'expClassName 2' }],
};
const fundDistribution = [{ code: 'TEST', fundId: '2', value: null, distributionType: FUND_DISTR_TYPE.percent }];

renderComponent({ required, fundDistribution, expenseClassesByFundId });
const valueInput = await screen.findByText('stripes-acq-components.fundDistribution.value');

expect(valueInput).toBeInTheDocument();
user.type(valueInput, '0');
user.tab();

user.click(screen.getByText('Submit'));

if (required) {
expect(screen.getByText('error message')).toBeInTheDocument();
} else {
expect(screen.queryByText('error message')).not.toBeInTheDocument();
}
});

it('should call \'handleValidationErrorResponse\' when validator rejected with an error', async () => {
Expand Down
Loading