Skip to content

Commit

Permalink
UIIN-3195: Display failure message during Update Ownership action whe…
Browse files Browse the repository at this point in the history
…n Item contains Local reference data (#2719)
  • Loading branch information
OleksandrHladchenko1 authored Jan 22, 2025
1 parent 9ae6bd9 commit 55d3001
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Remove hover-over text next to "Effective call number" on the Item record detail view. Refs UIIN-3131.
* Change import of `exportToCsv` from `stripes-util` to `stripes-components`. Refs UIIN-3025.
* ECS: Disable opening item details if a user is not affiliated with item's member tenant. Fixes UIIN-3187.
* Display failure message during `Update Ownership` action when Item contains Local reference data. Fixes UIIN-3195.

## [12.0.10](https://github.com/folio-org/ui-inventory/tree/v12.0.10) (2025-01-20)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v12.0.9...v12.0.10)
Expand Down
27 changes: 22 additions & 5 deletions src/views/ItemView.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,28 @@ const ItemView = props => {
goBack();
};

const resetFormAndCloseModal = () => {
setTargetTenant({});
setUpdateOwnershipData({});
setIsConfirmUpdateOwnershipModalOpen(false);
};

const showErrorMessage = () => {
calloutContext.sendCallout({
type: 'error',
message: <FormattedMessage id="ui-inventory.communicationProblem" />,
});

setTargetTenant({});
setUpdateOwnershipData({});
setIsConfirmUpdateOwnershipModalOpen(false);
resetFormAndCloseModal();
};

const showReferenceDataError = () => {
calloutContext.sendCallout({
type: 'error',
message: <FormattedMessage id="ui-inventory.updateOwnership.items.message.error" />,
});

resetFormAndCloseModal();
};

const createNewHoldingForlocation = async (itemId, targetLocation, targetTenantId) => {
Expand Down Expand Up @@ -590,8 +603,12 @@ const ItemView = props => {
targetTenantId: tenantId,
});
showSuccessMessageAndGoBack(item.hrid);
} catch (e) {
showErrorMessage();
} catch (error) {
if (error.response.status === 400) {
showReferenceDataError();
} else {
showErrorMessage();
}
}
}
};
Expand Down
36 changes: 34 additions & 2 deletions src/views/ItemView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,42 @@ describe('ItemView', () => {
expect(screen.queryByText('Linked order line')).not.toBeInTheDocument();
});

describe('when an error was occured', () => {
describe('when error was occured due to local-specific reference data', () => {
it('should show an error message', async () => {
useHoldingMutation.mockClear().mockReturnValue({ mutateHolding: mockMutate });
useUpdateOwnership.mockClear().mockReturnValue({ updateOwnership: jest.fn().mockRejectedValue() });
useUpdateOwnership.mockClear().mockReturnValue({
updateOwnership: jest.fn().mockRejectedValue({
response: {
status: 400,
}
})
});
checkIfUserInCentralTenant.mockClear().mockReturnValue(false);

renderWithIntl(<ItemViewSetup />, translationsProperties);

const updateOwnershipBtn = screen.getByText('Update ownership');
fireEvent.click(updateOwnershipBtn);

act(() => UpdateItemOwnershipModal.mock.calls[0][0].handleSubmit('university', { id: 'locationId' }, 'holdingId'));

const confirmationModal = screen.getByText('Update ownership of items');
fireEvent.click(within(confirmationModal).getByText('confirm'));

await waitFor(() => expect(screen.queryByText('Item ownership could not be updated because it contains local-specific reference data.')).toBeDefined());
});
});

describe('when error was occured', () => {
it('should show an error message', async () => {
useHoldingMutation.mockClear().mockReturnValue({ mutateHolding: mockMutate });
useUpdateOwnership.mockClear().mockReturnValue({
updateOwnership: jest.fn().mockRejectedValue({
response: {
status: 500,
},
})
});
checkIfUserInCentralTenant.mockClear().mockReturnValue(false);

renderWithIntl(<ItemViewSetup />, translationsProperties);
Expand Down
1 change: 1 addition & 0 deletions translations/ui-inventory/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@
"updateOwnership.items.modal.heading": "Update ownership of items",
"updateOwnership.items.modal.message": "Would you like to update ownership of Item <strong>{itemHrid}</strong> from <strong>{currentTenant}</strong> to <strong>{targetTenant}</strong>?",
"updateOwnership.item.message.success": "Ownership of item <strong>{itemHrid}</strong> has been successfully updated to <strong>{targetTenantName}</strong>",
"updateOwnership.items.message.error": "Item ownership could not be updated because it contains local-specific reference data.",
"consortialHoldings": "Consortial holdings",
"instanceData": "Administrative data",
"instanceHrid": "Instance HRID",
Expand Down

0 comments on commit 55d3001

Please sign in to comment.