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

UIEH-1394: Fix deleting and then saving custom embargo. #1691

Merged
merged 2 commits into from
Oct 26, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 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)

* Custom labels | Remove a dashes below labels. (UIEH-1361)
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 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,
}));
});
});
});
Loading