Skip to content

Commit

Permalink
Merge branch 'master' into UIREQMED-27
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko committed Jul 8, 2024
2 parents 84a26bb + 66980c6 commit 08c6043
Show file tree
Hide file tree
Showing 44 changed files with 715 additions and 119 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Add caret to `react` peer dependency. Refs UIREQMED-23.
* Add Search field for Mediated requests activity page. Refs UIREQMED-3.
* Add Filters for Mediated requests actions page. Refs UIREQMED-4.
* Update permission for Mediated requests. Refs UIREQMED-29.
* Implement `Create mediated request` form with basic functionality. Refs UIREQMED-27.

## 1.0.0
Expand Down
43 changes: 36 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,60 @@
"mod-settings.global.read.circulation",
"mod-settings.entries.collection.get",
"mod-settings.entries.item.get",
"settings.requests-mediated.enabled"
"settings.requests-mediated.enabled",

"circulation.items-by-instance.get",
"circulation.loans.collection.get",
"circulation.requests.collection.get",
"circulation.requests.item.get",
"circulation-storage.loans.collection.get",
"circulation-storage.loans.item.get",
"circulation-storage.requests.collection.get",
"circulation-storage.requests.item.get",
"users.collection.get",
"users.item.get",
"configuration.entries.collection.get"
],
"visible": true
},
{
"permissionName": "ui-requests-mediated.view-create",
"displayName": "Mediated requests: View, create",
"permissionName": "ui-requests-mediated.view-create-edit",
"displayName": "Mediated requests: View, create, edit",
"subPermissions": [
"ui-requests-mediated.view",

"circulation.requests.item.post",
"circulation.requests.item.put",
"circulation.requests.allowed-service-points.get",
"circulation-storage.requests.item.post",
"circulation-storage.requests.item.put",
"circulation-storage.requests.item.delete",
"circulation-storage.request-preferences.collection.get"
],
"visible": true
},
{
"permissionName": "ui-requests-mediated.view-decline",
"displayName": "Mediated requests: View, decline",
"subPermissions": [
"ui-requests-mediated.view"
],
"visible": true
},
{
"permissionName": "ui-requests-mediated.view-edit-cancel",
"displayName": "Mediated requests: View, edit, cancel",
"permissionName": "ui-requests-mediated.view-edit-decline",
"displayName": "Mediated requests: View, edit, decline",
"subPermissions": [
"ui-requests-mediated.view-create"
"ui-requests-mediated.view-decline"
],
"visible": true
},
{
"permissionName": "ui-requests-mediated.all",
"displayName": "Mediated requests: All permissions",
"subPermissions": [
"ui-requests-mediated.view-edit-cancel"
"ui-requests-mediated.view-create-edit",
"ui-requests-mediated.view-decline"
],
"visible": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,6 @@ class RequestForm extends React.Component {
}

componentDidMount() {
const { location } = this.props;
const {
userId,
userBarcode,
itemBarcode,
itemId,
instanceId,
} = parse(location?.search);

if (userBarcode) {
this.findUser(RESOURCE_KEYS.BARCODE, userBarcode);
} else if (userId) {
this.findUser(RESOURCE_KEYS.ID, userId);
}

if (itemBarcode) {
this.findItem(RESOURCE_KEYS.BARCODE, itemBarcode);
}

if (itemId) {
this.findItem(RESOURCE_KEYS.ID, itemId);
}

if (instanceId && !itemBarcode && !itemId) {
this.findInstance(instanceId);
}

this.setTlrCheckboxInitialState();
}

Expand All @@ -124,29 +97,13 @@ class RequestForm extends React.Component {
request,
onSetSelectedItem,
onSetSelectedUser,
location,
settings,

Check failure on line 100 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings' is missing in props validation

Check failure on line 100 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings' is missing in props validation
} = this.props;
const {
initialValues: prevInitialValues,
request: prevRequest,
location: prevLocation,
settings: prevSettings,

Check failure on line 105 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings' is missing in props validation

Check failure on line 105 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings' is missing in props validation
} = prevProps;
const {
userId,
userBarcode,
itemBarcode,
itemId,
instanceId,
} = parse(location?.search);
const {
userId: prevUserId,
userBarcode: prevUserBarcode,
itemBarcode: prevItemBarcode,
itemId: prevItemId,
instanceId: prevInstanceId,
} = parse(prevLocation?.search);
const newSettings = settings?.items[0]?.value;

Check failure on line 107 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings.items' is missing in props validation

Check failure on line 107 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings.items[].value' is missing in props validation

Check failure on line 107 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings.items' is missing in props validation

Check failure on line 107 in src/components/MediatedRequestsActivities/components/RequestForm/RequestForm.js

View workflow job for this annotation

GitHub Actions / build-npm

'settings.items[].value' is missing in props validation

if (
Expand All @@ -160,27 +117,6 @@ class RequestForm extends React.Component {
this.setState({ selectedLoan: request.loan });
}

if (prevUserBarcode !== userBarcode) {
this.findUser(RESOURCE_KEYS.BARCODE, userBarcode);
}

if (prevUserId !== userId) {
this.findUser(RESOURCE_KEYS.ID, userId);
}

if (prevItemBarcode !== itemBarcode) {
this.findItem(RESOURCE_KEYS.BARCODE, itemBarcode);
}

if (prevItemId !== itemId) {
this.findItem(RESOURCE_KEYS.ID, itemId);
}

if (prevInstanceId !== instanceId) {
this.findInstance(instanceId);
this.setTlrCheckboxInitialState();
}

if (prevSettings?.items[0]?.value !== newSettings) {
const { titleLevelRequestsFeatureEnabled } = getTlrSettings(newSettings);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import {
fireEvent,
render,
screen,
waitFor,
} from '@folio/jest-config-stripes/testing-library/react';

import RequestForm from './RequestForm';
import {
REQUEST_FORM_FIELD_NAMES,
RESOURCE_KEYS,
RESOURCE_TYPES,
} from '../../../../constants';

const basicProps = {
handleSubmit: jest.fn(),
Expand Down Expand Up @@ -33,12 +40,32 @@ const basicProps = {
const labelIds = {
itemAccordion: 'ui-requests-mediated.form.item.accordionLabel',
};
const testIds = {
findItem: 'findItem',
};
const itemBarcode = 'itemBarcode';

jest.mock('@folio/stripes/final-form', () => () => jest.fn((component) => component));
jest.mock('../RequestFormShortcutsWrapper', () => jest.fn(({ children }) => <div>{children}</div>));
jest.mock('../RequestFormFirstMenu', () => jest.fn(() => <div/>));
jest.mock('../RequestFormFooter', () => jest.fn(() => <div/>));
jest.mock('../ItemInformation', () => jest.fn(() => <div/>));
jest.mock('../ItemInformation', () => jest.fn(({
findItem,
}) => {
const onFindItem = () => {
findItem('barcode', itemBarcode);
};

return (
<>
<button
type="button"
data-testid={testIds.findItem}
onClick={onFindItem}
>Find Item</button>
</>
);
}));
jest.mock('../InstanceInformation', () => jest.fn(() => <div/>));
jest.mock('../RequesterInformation', () => jest.fn(() => <div/>));
jest.mock('../ItemsDialog', () => jest.fn(() => <div/>));
Expand All @@ -52,6 +79,9 @@ jest.mock('../../../../utils', () => ({
}));

describe('RequestForm', () => {
afterEach(() => {
jest.clearAllMocks();
});

describe('Initial render', () => {
beforeEach(() => {
Expand All @@ -68,4 +98,129 @@ describe('RequestForm', () => {
expect(accordionLabel).toBeInTheDocument();
});
});

describe('ItemInformation', () => {
describe('When item data exists', () => {
const foundItem = {
items: [
{
id: 'itemId',
barcode: 'itemBarcode',
}
],
};
const foundLoan = {
loans: [],
};
const foundRequests = {
requests: [],
};

beforeEach(() => {
render(
<RequestForm
{...basicProps}
/>
);

const findItemButton = screen.getByTestId(testIds.findItem);

basicProps.findResource
.mockResolvedValueOnce(foundItem)
.mockResolvedValueOnce(foundLoan)
.mockResolvedValueOnce(foundRequests);
fireEvent.click(findItemButton);
});

it('should find item', () => {
const expectedArgs = [RESOURCE_TYPES.ITEM, itemBarcode, RESOURCE_KEYS.BARCODE];

expect(basicProps.findResource).toHaveBeenCalledWith(...expectedArgs);
});

it('should set item id form value', () => {
const expectedArgs = [REQUEST_FORM_FIELD_NAMES.ITEM_ID, foundItem.items[0].id];

expect(basicProps.form.change).toHaveBeenCalledWith(...expectedArgs);
});

it('should set item barcode form value', () => {
const expectedArgs = [REQUEST_FORM_FIELD_NAMES.ITEM_BARCODE, foundItem.items[0].barcode];

expect(basicProps.form.change).toHaveBeenCalledWith(...expectedArgs);
});

it('should set selected item', () => {
expect(basicProps.onSetSelectedItem).toHaveBeenCalledWith(foundItem.items[0]);
});

it('should find related loans', () => {
const expectedArgs = [RESOURCE_TYPES.LOAN, foundItem.items[0].id];

expect(basicProps.findResource).toHaveBeenCalledWith(...expectedArgs);
});

it('should find item requests', () => {
const expectedArgs = [RESOURCE_TYPES.REQUESTS_FOR_ITEM, foundItem.items[0].id];

expect(basicProps.findResource).toHaveBeenCalledWith(...expectedArgs);
});
});

describe('When item data does not exist', () => {
const foundItem = {
items: [],
};

beforeEach(() => {
render(
<RequestForm
{...basicProps}
/>
);

const findItemButton = screen.getByTestId(testIds.findItem);

basicProps.findResource.mockResolvedValueOnce(foundItem);
fireEvent.click(findItemButton);
});

it('should not set item id form value', async () => {
const expectedArgs = [REQUEST_FORM_FIELD_NAMES.ITEM_ID, expect.any(String)];

await waitFor(() => {
expect(basicProps.form.change).not.toHaveBeenCalledWith(...expectedArgs);
});
});

it('should not set item barcode form value', async () => {
const expectedArgs = [REQUEST_FORM_FIELD_NAMES.ITEM_BARCODE, expect.any(String)];

await waitFor(() => {
expect(basicProps.form.change).not.toHaveBeenCalledWith(...expectedArgs);
});
});
});

describe('When item data request throws error', () => {
beforeEach(() => {
render(
<RequestForm
{...basicProps}
/>
);

const findItemButton = screen.getByTestId(testIds.findItem);

basicProps.findResource.mockRejectedValueOnce({});
fireEvent.click(findItemButton);
});

it('should set selected item to null', async () => {
await waitFor(() => {
expect(basicProps.onSetSelectedItem).toHaveBeenCalledWith(null);
});
});
});
});
});
1 change: 1 addition & 0 deletions src/hooks/useCirculationRequests/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './useCirculationRequests';
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
import {
MAX_RECORDS,
OPEN_REQUESTS_STATUSES,
} from '../constants';
import { getStatusQuery } from '../utils';
} from '../../constants';
import { getStatusQuery } from '../../utils';

const CHUNK_SIZE = 40;

Expand All @@ -30,7 +30,7 @@ export const getRequests = async (ky, instanceId) => {
let query = itemChunk.map(i => `itemId==${i.id}`).join(' or ');
const statusQuery = getStatusQuery(OPEN_REQUESTS_STATUSES);

query = `(${query}) and (${statusQuery})")`;
query = `(${query}) and (${statusQuery})`;

const searchParams = {
query,
Expand Down Expand Up @@ -63,10 +63,10 @@ const useCirculationRequests = (instanceId, open) => {
{ enabled: Boolean(instanceId && open) },
);

return ({
return {
isFetching,
data,
});
};
};

export default useCirculationRequests;
Loading

0 comments on commit 08c6043

Please sign in to comment.