From baaffe863af5fc858232aa119938bfb236742ecf Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Thu, 12 Oct 2023 20:13:19 +0400 Subject: [PATCH 1/2] UIOR-1159 Provide 'instanceTenantId' from the PO form to PO line form --- src/components/LayerCollection/LayerPO.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/LayerCollection/LayerPO.js b/src/components/LayerCollection/LayerPO.js index f13938506..57585af11 100644 --- a/src/components/LayerCollection/LayerPO.js +++ b/src/components/LayerCollection/LayerPO.js @@ -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 => { @@ -97,6 +97,7 @@ function LayerPO({ history, instanceId, location.search, + location.state?.instanceTenantId, memoizedMutator.order, openOrderErrorModalShow, sendCallout, From 12683e42494cea0228c899a6f45441b2d1e4d947 Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Thu, 12 Oct 2023 21:53:32 +0400 Subject: [PATCH 2/2] UIOR-1159 Add unit test --- .../LayerCollection/LayerPO.test.js | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/components/LayerCollection/LayerPO.test.js b/src/components/LayerCollection/LayerPO.test.js index 9f0a74f07..47aecb364 100644 --- a/src/components/LayerCollection/LayerPO.test.js +++ b/src/components/LayerCollection/LayerPO.test.js @@ -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, @@ -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(); @@ -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\/(?.+)\/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()); }); });