From 0702527cb2b36c1feb467bd6b9c4e33858b72464 Mon Sep 17 00:00:00 2001 From: Dmytro-Melnyshyn Date: Wed, 25 Oct 2023 17:53:40 +0300 Subject: [PATCH 1/2] UIEH-1394: Fix deleting and then saving custom embargo. --- CHANGELOG.md | 1 + .../custom-embargo/custom-embargo-fields.js | 2 +- .../custom-embargo/custom-embargo.test.js | 15 +++++++++++++ .../resource-edit-route.js | 2 +- .../resource-edit-route.test.js | 22 +++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7e7094d5..3c2932ad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/components/resource/_fields/custom-embargo/custom-embargo-fields.js b/src/components/resource/_fields/custom-embargo/custom-embargo-fields.js index f17ffae68..75c1690cd 100644 --- a/src/components/resource/_fields/custom-embargo/custom-embargo-fields.js +++ b/src/components/resource/_fields/custom-embargo/custom-embargo-fields.js @@ -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); } diff --git a/src/components/resource/_fields/custom-embargo/custom-embargo.test.js b/src/components/resource/_fields/custom-embargo/custom-embargo.test.js index 94a0c4a5b..d6bb12e80 100644 --- a/src/components/resource/_fields/custom-embargo/custom-embargo.test.js +++ b/src/components/resource/_fields/custom-embargo/custom-embargo.test.js @@ -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(); + }); + }); }); diff --git a/src/routes/resource-edit-route/resource-edit-route.js b/src/routes/resource-edit-route/resource-edit-route.js index b0bef9823..433bca766 100644 --- a/src/routes/resource-edit-route/resource-edit-route.js +++ b/src/routes/resource-edit-route/resource-edit-route.js @@ -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, diff --git a/src/routes/resource-edit-route/resource-edit-route.test.js b/src/routes/resource-edit-route/resource-edit-route.test.js index 4aea3944d..281f24f33 100644 --- a/src/routes/resource-edit-route/resource-edit-route.test.js +++ b/src/routes/resource-edit-route/resource-edit-route.test.js @@ -331,4 +331,26 @@ describe('Given ResourceEditRoute', () => { expect(mockUpdateResource).toHaveBeenCalled(); }); }); + + describe('when user clicks 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, + })); + }); + }); }); From da4a5defd3dc2eb599705a31004fdc9cc2959b0c Mon Sep 17 00:00:00 2001 From: Dmytro-Melnyshyn Date: Thu, 26 Oct 2023 13:54:37 +0300 Subject: [PATCH 2/2] move to 9.0.1 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c2932ad0..c4707780b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ * Remove Bigtest tests. (UIEH-1390) * Remove eslint deps that are already listed in eslint-config-stripes. (UIEH-1389) + +## [9.0.1] (IN PROGRESS) + * 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)