Skip to content

Commit

Permalink
UIOR-1159 Provide 'instanceTenantId' from the PO form to PO line form (
Browse files Browse the repository at this point in the history
…#1513)

* UIOR-1159 Provide 'instanceTenantId' from the PO form to PO line form

* UIOR-1159 Add unit test
  • Loading branch information
usavkov-epam authored Oct 12, 2023
1 parent 2d39c94 commit 33da646
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/LayerCollection/LayerPO.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function LayerPO({
history.push({
pathname: instanceId ? `/orders/view/${savedOrder.id}/po-line/create` : `/orders/view/${savedOrder.id}`,
search: location.search,
state: instanceId ? { instanceId } : {},
state: instanceId ? { instanceId, instanceTenantId: location.state?.instanceTenantId } : {},
});
})
.catch(async e => {
Expand All @@ -97,6 +97,7 @@ function LayerPO({
history,
instanceId,
location.search,
location.state?.instanceTenantId,
memoizedMutator.order,
openOrderErrorModalShow,
sendCallout,
Expand Down
36 changes: 34 additions & 2 deletions src/components/LayerCollection/LayerPO.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MemoryRouter } from 'react-router';

import { render, screen, waitFor } from '@folio/jest-config-stripes/testing-library/react';
import { ORDER_TYPES } from '@folio/stripes-acq-components';

import {
address,
Expand Down Expand Up @@ -71,6 +72,12 @@ const renderLayerPO = (props = {}) => render(
);

describe('LayerPO', () => {
beforeEach(() => {
defaultProps.mutator.order.POST.mockClear();
history.push.mockClear();
POForm.mockClear();
});

it('should render PO form', async () => {
renderLayerPO();

Expand All @@ -91,19 +98,44 @@ describe('LayerPO', () => {
renderLayerPO();

await waitFor(() => POForm.mock.calls[0][0].onSubmit({
orderType: 'ongoing',
orderType: ORDER_TYPES.ongoing,
}));

expect(history.push).toHaveBeenCalled();
});

describe('Create from inventory', () => {
it('should call onSubmit when form was submitted 2', async () => {
const locationState = {
instanceId: 'instanceId',
instanceTenantId: 'instanceTenantId',
};

renderLayerPO({
location: {
...defaultProps.location,
state: locationState,
},
});

await waitFor(() => POForm.mock.calls[0][0].onSubmit({
orderType: ORDER_TYPES.ongoing,
}));

expect(history.push).toHaveBeenCalledWith(expect.objectContaining({
pathname: expect.stringMatching(/^\/orders\/view\/(?<orderId>.+)\/po-line\/create$/),
state: locationState,
}));
});
});

it('should throw an error if the order update was failed ', async () => {
defaultProps.mutator.order.POST.mockRejectedValue({});

renderLayerPO();

await waitFor(() => expect(POForm.mock.calls[0][0].onSubmit({
orderType: 'ongoing',
orderType: ORDER_TYPES.ongoing,
})).rejects.toBeTruthy());
});
});

0 comments on commit 33da646

Please sign in to comment.