Skip to content

Commit

Permalink
Add basic functionality for managing missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko committed Nov 26, 2024
1 parent 21f2a60 commit 2ccc297
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add circulation-storage.staff-slips.collection.get for get staff-slips on Send item in transit. Refs UIREQMED-55.
* Add Decline Action for Mediated request with status of New - Awaiting confirmation. Refs UIREQMED-42.
* Fix DOMPurify import. Refs UIREQMED-56.
* Add functionality for managing missing data related to item, instance, requester. Refs UIREQMED-51.

## [1.1.0](https://github.com/folio-org/ui-requests-mediated/tree/v1.1.0) (2024-10-30)
* Update github actions. Refs UIREQMED-14.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class InstanceInformation extends Component {
isLoading: PropTypes.bool.isRequired,
enterButtonClass: PropTypes.string.isRequired,
isInstancePreselected: PropTypes.bool.isRequired,
isEditMode: PropTypes.bool.isRequired,
stripes: PropTypes.object.isRequired,
request: PropTypes.object,
selectedInstance: PropTypes.object,
};

Expand All @@ -58,11 +60,22 @@ class InstanceInformation extends Component {
const {
isInstancePreselected,
selectedInstance,
isEditMode,
triggerValidation,
request,
} = this.props;
const isNewPreselectedValue = isInstancePreselected && isInstancePreselected !== prevProps.isInstancePreselected;

if (selectedInstance && isInstancePreselected && isInstancePreselected !== prevProps.isInstancePreselected) {
if (selectedInstance && isNewPreselectedValue) {
this.setState({ validatedId: selectedInstance.hrid });
}

if (isEditMode && !selectedInstance && isNewPreselectedValue) {
this.setState({
validatedId: request?.instance?.hrid,
shouldValidate: true,
}, triggerValidation);
}
}

validate = memoizeValidation(async (instanceId) => {
Expand Down Expand Up @@ -183,6 +196,7 @@ class InstanceInformation extends Component {
isLoading,
enterButtonClass,
stripes,
isEditMode,
} = this.props;
const {
isInstanceClicked,
Expand Down Expand Up @@ -211,7 +225,7 @@ class InstanceInformation extends Component {
>
{({ input, meta }) => {
const selectInstanceError = meta.touched && meta.error;
const instanceDoesntExistError = (isInstanceClicked || isInstanceBlurred) && meta.error;
const instanceDoesntExistError = (isInstanceClicked || isInstanceBlurred || (isEditMode && !selectedInstance)) && meta.error;
const error = selectInstanceError || instanceDoesntExistError || null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const basicProps = {
isLoading: false,
submitting: false,
isInstancePreselected: false,
isEditMode: false,
stripes: {
hasPerm: jest.fn(() => true),
},
Expand Down Expand Up @@ -557,9 +558,8 @@ describe('InstanceInformation', () => {
});

describe('Component updating', () => {
const onBlur = jest.fn();

beforeEach(() => {
it('should not trigger onBlur handler', () => {
const onBlur = jest.fn();
const rerender = renderInstanceInfoWithHrid(onBlur);
const newProps = {
...basicProps,
Expand All @@ -574,15 +574,36 @@ describe('InstanceInformation', () => {
{...newProps}
/>
);
});

it('should not trigger onBlur handler', () => {
const instanceHridField = screen.getByTestId(testIds.instanceHridField);

fireEvent.click(instanceHridField);
fireEvent.blur(instanceHridField);

expect(onBlur).not.toHaveBeenCalled();
});

it('should trigger validation', () => {
const rerender = renderInstanceInfoWithHrid();
const newProps = {
...basicProps,
isInstancePreselected: true,
selectedInstance: null,
isEditMode: true,
request: {
instance: {
hrid: 'hrid',
},
},
};

rerender(
<InstanceInformation
{...newProps}
/>
);

expect(basicProps.triggerValidation).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ class ItemInformation extends Component {
getItemValidationData: PropTypes.func.isRequired,
form: PropTypes.object.isRequired,
values: PropTypes.object.isRequired,
request: PropTypes.object.isRequired,
onSetSelectedItem: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
submitting: PropTypes.bool.isRequired,
isItemIdRequest: PropTypes.bool.isRequired,
enterButtonClass: PropTypes.string.isRequired,
isItemPreselected: PropTypes.bool.isRequired,
isEditMode: PropTypes.bool.isRequired,
request: PropTypes.object,
stripes: PropTypes.shape({
hasPerm: PropTypes.func,
}).isRequired,
Expand All @@ -59,11 +60,22 @@ class ItemInformation extends Component {
const {
isItemPreselected,
selectedItem,
isEditMode,
triggerValidation,
request,
} = this.props;
const isNewPreselectedValue = isItemPreselected && isItemPreselected !== prevProps.isItemPreselected;

if (selectedItem && isItemPreselected && isItemPreselected !== prevProps.isItemPreselected) {
if (selectedItem && isNewPreselectedValue) {
this.setState({ validatedBarcode: selectedItem.barcode });
}

if (isEditMode && !selectedItem && isNewPreselectedValue) {
this.setState({
shouldValidate: true,
validatedBarcode: request?.item?.barcode,
}, triggerValidation);
}
}

validate = memoizeValidation(async (barcode) => {
Expand Down Expand Up @@ -186,6 +198,7 @@ class ItemInformation extends Component {
selectedLoan,
enterButtonClass,
stripes,
isEditMode,
} = this.props;
const {
isItemClicked,
Expand Down Expand Up @@ -213,7 +226,7 @@ class ItemInformation extends Component {
>
{({ input, meta }) => {
const selectItemError = meta.touched && meta.error;
const itemDoesntExistError = (isItemClicked || isItemBlurred) && meta.error;
const itemDoesntExistError = (isItemClicked || isItemBlurred || (isEditMode && !selectedItem)) && meta.error;
const error = selectItemError || itemDoesntExistError || null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const basicProps = {
hasPerm: jest.fn(() => true),
},
resetRequestInformation: jest.fn(),
isEditMode: false,
};
const labelIds = {
inputPlaceholder: 'ui-requests-mediated.form.item.inputPlaceholder',
Expand Down Expand Up @@ -506,9 +507,8 @@ describe('ItemInformation', () => {
});

describe('Component updating', () => {
const onBlur = jest.fn();

beforeEach(() => {
it('should not trigger onBlur handler', () => {
const onBlur = jest.fn();
const rerender = renderItemInfoWithBarcode(onBlur);
const newProps = {
...basicProps,
Expand All @@ -523,15 +523,31 @@ describe('ItemInformation', () => {
{...newProps}
/>
);
});

it('should not trigger onBlur handler', () => {
const itemBarcodeField = screen.getByTestId(testIds.itemBarcodeField);

fireEvent.click(itemBarcodeField);
fireEvent.blur(itemBarcodeField);

expect(onBlur).not.toHaveBeenCalled();
});

it('should trigger validation', () => {
const rerender = renderItemInfoWithBarcode();
const newProps = {
...basicProps,
isItemPreselected: true,
selectedItem: null,
isEditMode: true,
};

rerender(
<ItemInformation
{...newProps}
/>
);

expect(basicProps.triggerValidation).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class RequestForm extends React.Component {
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.ITEM_BARCODE, request.item.barcode);
}

form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUESTER_BARCODE, request.requester.barcode);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUESTER_BARCODE, request.requester?.barcode);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.PATRON_COMMENTS, request.patronComments);

Promise.allSettled([
Expand Down Expand Up @@ -648,20 +648,22 @@ class RequestForm extends React.Component {
const { requestPreferences } = await findResource(RESOURCE_TYPES.REQUEST_PREFERENCES, userId);
const preferences = requestPreferences[0];
const fulfillmentPreference = getFulfillmentPreference(preferences, initialValues);
const defaultDeliveryAddressTypeId = preferences?.defaultDeliveryAddressTypeId;
const defaultServicePointId = preferences?.defaultServicePointId;

this.setState({
defaultDeliveryAddressTypeId: preferences.defaultDeliveryAddressTypeId,
defaultServicePointId: preferences.defaultServicePointId,
defaultDeliveryAddressTypeId,
defaultServicePointId,
fulfillmentPreference,
});

return {
...defaultPreferences,
defaultDeliveryAddressTypeId: preferences.defaultDeliveryAddressTypeId,
defaultServicePointId: preferences.defaultServicePointId,
hasDelivery: Boolean(preferences.delivery),
hasDelivery: Boolean(preferences?.delivery),
isDeliverySelected: isDelivery(fulfillmentPreference),
selectedAddress: preferences.defaultDeliveryAddressTypeId,
selectedAddress: defaultDeliveryAddressTypeId,
defaultDeliveryAddressTypeId,
defaultServicePointId,
fulfillmentPreference,
};
} catch (e) {
Expand Down Expand Up @@ -952,6 +954,8 @@ class RequestForm extends React.Component {
onSetSelectedInstance={onSetSelectedInstance}
isLoading={isItemOrInstanceLoading}
enterButtonClass={css.enterButton}
isEditMode={isEditMode}
request={request}
/>
</Accordion>
)
Expand All @@ -975,6 +979,7 @@ class RequestForm extends React.Component {
selectedLoan={selectedLoan}
isLoading={isItemOrInstanceLoading}
enterButtonClass={css.enterButton}
isEditMode={isEditMode}
/>
</Accordion>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ class RequesterInformation extends Component {
const {
isUserPreselected,
selectedUser,
triggerUserBarcodeValidation,
isEditMode,
request,
} = this.props;
const isNewPreselectedValue = isUserPreselected && isUserPreselected !== prevProps.isUserPreselected;

if (selectedUser && isUserPreselected && isUserPreselected !== prevProps.isUserPreselected) {
if (selectedUser && isNewPreselectedValue) {
this.setState({ validatedBarcode: selectedUser.barcode });
}

if (isEditMode && !selectedUser && isNewPreselectedValue) {
this.setState({
validatedBarcode: request?.requester?.barcode,
shouldValidate: true,
}, triggerUserBarcodeValidation);
}
}

validate = memoizeValidation(async (barcode) => {
Expand Down Expand Up @@ -246,7 +257,7 @@ class RequesterInformation extends Component {
>
{({ input, meta }) => {
const selectUserError = meta.touched && !selectedUser?.id && meta.error;
const userDoesntExistError = (isUserClicked || isUserBlurred) && meta.error;
const userDoesntExistError = (isUserClicked || isUserBlurred || (isEditMode && !selectedUser)) && meta.error;
const error = selectUserError || userDoesntExistError || null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,8 @@ describe('RequesterInformation', () => {
});

describe('Component updating', () => {
const onBlur = jest.fn();

beforeEach(() => {
it('should not trigger onBlur handler', () => {
const onBlur = jest.fn();
const rerender = renderRequesterInfoWithBarcode(onBlur);
const newProps = {
...basicProps,
Expand All @@ -228,16 +227,31 @@ describe('RequesterInformation', () => {
{...newProps}
/>
);
});

it('should not trigger onBlur handler', () => {
const requesterBarcodeField = screen.getByTestId(testIds.requesterBarcodeField);

fireEvent.click(requesterBarcodeField);
fireEvent.blur(requesterBarcodeField);

expect(onBlur).not.toHaveBeenCalled();
});

it('should trigger validation', () => {
const rerender = renderRequesterInfoWithBarcode();
const newProps = {
...basicProps,
isUserPreselected: true,
selectedUser: null,
isEditMode: true,
};

rerender(
<RequesterInformation
{...newProps}
/>
);

expect(basicProps.triggerUserBarcodeValidation).toHaveBeenCalled();
});
});

describe('Validation', () => {
Expand Down

0 comments on commit 2ccc297

Please sign in to comment.