Skip to content

Commit

Permalink
UIIN-2614 Provide an instance tenantId to the PO line form when cre…
Browse files Browse the repository at this point in the history
…ating an order from the instance (#2299)

* UIIN-2614 Provide an instance tenantId to the PO line form when creating an order from the instance

* update tests
  • Loading branch information
usavkov-epam authored Oct 12, 2023
1 parent afc506a commit 664357f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
* Consortial Central Tenant: Handling Holdings and Item actions on the Instance detail view. Refs UIIN-2523.
* Hide Held by facet in Inventory contributor and subject browse. Refs UIIN-2591.
* Use `==` for exact phrase search in Advanced Search for all full-text and term fields. Refs UIIN-2612.
* Provide an instance `tenantId` to the PO line form when creating an order from the instance. Refs UIIN-2614.

## [9.4.12](https://github.com/folio-org/ui-inventory/tree/v9.4.12) (2023-09-21)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v9.4.11...v9.4.12)
Expand Down
13 changes: 10 additions & 3 deletions src/components/NewOrderModal/NewOrderModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import {
useParams,
} from 'react-router-dom';

import { useOkapiKy } from '@folio/stripes/core';
import {
useOkapiKy,
useStripes,
} from '@folio/stripes/core';

import { useInstance } from '../../common';
import { ORDERS_API } from '../../constants';
import NewOrderModal from './NewOrderModal';

Expand All @@ -20,7 +24,9 @@ const NewOrderModalContainer = ({
}) => {
const history = useHistory();
const ky = useOkapiKy();
const stripes = useStripes();
const { id } = useParams();
const { instance } = useInstance(id);
const [orderId, setOrderId] = useState();

const validatePONumber = useCallback(async (poNumber) => {
Expand All @@ -45,9 +51,10 @@ const NewOrderModalContainer = ({

const onSubmit = useCallback(() => {
const route = orderId ? `/orders/view/${orderId}/po-line/create` : '/orders/create';
const instanceTenantId = instance?.tenantId || stripes.okapi.tenant;

history.push(route, { instanceId: id });
}, [orderId]);
history.push(route, { instanceId: instance?.id, instanceTenantId });
}, [instance, orderId, stripes.okapi.tenant]);

return (
<NewOrderModal
Expand Down
44 changes: 34 additions & 10 deletions src/components/NewOrderModal/NewOrderModalContainer.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import React from 'react';
import {
BrowserRouter as Router,
useHistory,
} from 'react-router-dom';
import { act, render, screen, fireEvent } from '@folio/jest-config-stripes/testing-library/react';

import '../../../test/jest/__mock__';

// eslint-disable-next-line import/order
import userEvent from '@folio/jest-config-stripes/testing-library/user-event';
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';
import { useOkapiKy } from '@folio/stripes/core';

import '../../../test/jest/__mock__';

import { translationsProperties } from '../../../test/jest/helpers';
import Harness from '../../../test/jest/helpers/Harness';
import { instance } from '../../../test/fixtures/instance';
import { useInstance } from '../../common';
import NewOrderModalContainer from './NewOrderModalContainer';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: jest.fn()
}));
jest.mock('../../common', () => ({
...jest.requireActual('../../common'),
useInstance: jest.fn(),
}));

global.document.createRange = jest.fn(() => new Range());

const defaultProps = {
onCancel: jest.fn(),
Expand All @@ -44,18 +51,25 @@ describe('NewOrderModalContainer', () => {
const historyMock = {
push: jest.fn(),
};
const order = {
id: 'orderId',
};
const kyMock = {
get: jest.fn(() => ({
json: () => Promise.resolve({
purchaseOrders: [{ id: 'orderId' }],
purchaseOrders: [order],
})
}))
};

beforeEach(() => {
historyMock.push.mockClear();
useHistory
.mockClear()
.mockReturnValue(historyMock);
useInstance
.mockClear()
.mockReturnValue({ instance });
useOkapiKy
.mockClear()
.mockReturnValue(kyMock);
Expand All @@ -70,17 +84,27 @@ describe('NewOrderModalContainer', () => {
it('should navigate to \'PO\' creation form when create btn was clicked and \'PO number\' field is empty', async () => {
renderNewOrderModalContainer();

await act(async () => fireEvent.click(screen.getByText(/^Create$/)));
await userEvent.click(screen.getByText(/^Create$/));

expect(historyMock.push).toHaveBeenCalledWith('/orders/create', expect.anything());
});

it('should navigate to \'PO Line\' creation form when create btn was clicked and PO is exist', async () => {
renderNewOrderModalContainer();

await act(async () => fireEvent.change(screen.getByLabelText(/PO number/i), { target: { value: '123' } }));
await act(async () => fireEvent.click(screen.getByText(/^Create$/)));
await userEvent.type(screen.getByLabelText(/PO number/i), '123');
await userEvent.tab();

expect(screen.queryByText('ui-inventory.newOrder.modal.PONumber.doesNotExist')).not.toBeInTheDocument();

await userEvent.click(await screen.findByText(/^Create$/));

expect(historyMock.push).toHaveBeenCalledWith('/orders/create', { 'instanceId': undefined });
expect(historyMock.push).toHaveBeenCalledWith(
`/orders/view/${order.id}/po-line/create`,
{
instanceId: instance.id,
instanceTenantId: 'diku',
},
);
});
});

0 comments on commit 664357f

Please sign in to comment.