Skip to content

Commit

Permalink
UIEH-1394: Fix deleting and then saving custom embargo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro-Melnyshyn committed Oct 25, 2023
1 parent 80dbb08 commit 10662f1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Remove Bigtest tests. (UIEH-1390)
* Remove eslint deps that are already listed in eslint-config-stripes. (UIEH-1389)
* Fix deleting and then saving custom embargo. (UIEH-1394)

## [9.0.0] (https://github.com/folio-org/ui-eholdings/tree/v9.0.0) (2023-10-13)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class CustomEmbargoFields extends Component {
initialValues,
];

return fields.value.length
return fields.value?.length
? this.renderInputs(...fieldsData)
: this.renderAddButton(...fieldsData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,19 @@ describe('Given CustomEmbargoFields', () => {
expect(getByTestId('custom-embargo-value')).toBeDefined();
});
});

describe('when the user deleted the embargo period', () => {
it('should see the "Add custom embargo period" button', () => {
const { getByRole } = renderCustomEmbargoFields({
customEmbargoPeriod: [{ embargoUnit: 'Days', embargoValue: 33 }],
});

const deleteEmbargoBtn = getByRole('button', { name: 'ui-eholdings.resource.embargoPeriod.clear' });
fireEvent.click(deleteEmbargoBtn);

const addEmbargoBtn = getByRole('button', { name: 'ui-eholdings.resource.embargoPeriod.addCustom' });

expect(addEmbargoBtn).toBeDefined();
});
});
});
2 changes: 1 addition & 1 deletion src/routes/resource-edit-route/resource-edit-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ResourceEditRoute extends Component {
url: customUrl,
visibilityData: { isHidden: !isVisible },
coverageStatement,
customEmbargoPeriod: customEmbargoPeriod[0] || defaultEmbargoPeriod,
customEmbargoPeriod: customEmbargoPeriod?.[0] || defaultEmbargoPeriod,
proxy: { id: proxyId },
accessTypeId: newAccessTypeId,
userDefinedField1,
Expand Down
22 changes: 22 additions & 0 deletions src/routes/resource-edit-route/resource-edit-route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,26 @@ describe('Given ResourceEditRoute', () => {
expect(mockUpdateResource).toHaveBeenCalled();
});
});

describe('when click on Save & close button', () => {
it('should call updateResource with default embargo period', () => {
const defaultEmbargoPeriod = { embargoValue: 0 };

const { getByRole } = renderResourceEditRoute({
model: {
...model,
isSelected: true,
},
});

const deleteEmbargoBtn = getByRole('button', { name: 'ui-eholdings.resource.embargoPeriod.clear' });
fireEvent.click(deleteEmbargoBtn);

fireEvent.submit(getByRole('button', { name: 'stripes-components.saveAndClose' }));

expect(mockUpdateResource).toHaveBeenCalledWith(expect.objectContaining({
customEmbargoPeriod: defaultEmbargoPeriod,
}));
});
});
});

0 comments on commit 10662f1

Please sign in to comment.