Skip to content

Commit

Permalink
UIQM-704: Linked fields - combine split fields before sending for val…
Browse files Browse the repository at this point in the history
…idation. (#739)
  • Loading branch information
Dmytro-Melnyshyn authored Oct 1, 2024
1 parent 76bead7 commit 30c579b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [UIQM-695](https://issues.folio.org/browse/UIQM-695) Remove extra `$` from error messages when adding/removing `$t` from 1XX of linked MARC authority record.
* [UIQM-706](https://issues.folio.org/browse/UIQM-706) *BREAKING* Upgrade `marc-records-editor` to `6.0`.
* [UIQM-698](https://issues.folio.org/browse/UIQM-698) Validate 006/007 field lengths.
* [UIQM-704](https://issues.folio.org/browse/UIQM-704) Linked fields - combine split fields before sending for validation.

## [8.0.1] (https://github.com/folio-org/ui-quick-marc/tree/v8.0.1) (2024-04-18)

Expand Down
6 changes: 2 additions & 4 deletions src/QuickMarcEditor/QuickMarcCreateWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const QuickMarcCreateWrapper = ({
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec, marcType),
marcRecord => formatLeaderForSubmit(marcType, marcRecord),
combineSplitFields,
)(formValues);

return formValuesForCreate;
Expand All @@ -123,10 +124,7 @@ const QuickMarcCreateWrapper = ({
return complete();
}

const formValuesToProcess = flow(
prepareForSubmit,
combineSplitFields,
)(formValues);
const formValuesToProcess = prepareForSubmit(formValues);

let formValuesToHydrate;

Expand Down
6 changes: 2 additions & 4 deletions src/QuickMarcEditor/QuickMarcDeriveWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const QuickMarcDeriveWrapper = ({
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec, marcType),
marcRecord => formatLeaderForSubmit(marcType, marcRecord),
combineSplitFields,
)(formValues);

return formValuesForDerive;
Expand All @@ -101,10 +102,7 @@ const QuickMarcDeriveWrapper = ({
return complete();
}

const formValuesToProcess = flow(
prepareForSubmit,
combineSplitFields,
)(formValues);
const formValuesToProcess = prepareForSubmit(formValues);

showCallout({ messageId: 'ui-quick-marc.record.saveNew.onSave' });

Expand Down
6 changes: 2 additions & 4 deletions src/QuickMarcEditor/QuickMarcEditWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const QuickMarcEditWrapper = ({
autopopulateMaterialCharsField,
marcRecord => autopopulateSubfieldSection(marcRecord, marcType),
marcRecord => cleanBytesFields(marcRecord, fixedFieldSpec, marcType),
combineSplitFields,
)(formValues);

return formValuesToSave;
Expand All @@ -148,10 +149,7 @@ const QuickMarcEditWrapper = ({
is1xxOr010Updated = are010Or1xxUpdated(initialValues.records, formValues.records);
}

const formValuesToProcess = flow(
prepareForSubmit,
combineSplitFields,
)(formValues);
const formValuesToProcess = prepareForSubmit(formValues);

const path = EXTERNAL_INSTANCE_APIS[marcType];

Expand Down
91 changes: 79 additions & 12 deletions src/QuickMarcEditor/QuickMarcEditWrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { useLocation } from 'react-router';

import QuickMarcEditWrapper from './QuickMarcEditWrapper';
import { useAuthorityLinking } from '../hooks';
import { useMarcRecordMutation } from '../queries';
import {
useMarcRecordMutation,
useValidate,
} from '../queries';
import { QUICK_MARC_ACTIONS } from './constants';
import { MARC_TYPES } from '../common/constants';
import { applyCentralTenantInHeaders } from './utils';
Expand Down Expand Up @@ -43,6 +46,7 @@ jest.mock('../queries', () => ({
isLoading: false,
duplicateLccnCheckingEnabled: false,
}),
useValidate: jest.fn(),
}));

jest.mock('../hooks', () => ({
Expand Down Expand Up @@ -266,17 +270,7 @@ const mockLeaders = {
[MARC_TYPES.AUTHORITY]: authorityLeader,
};

const mockFormValues = jest.fn((marcType) => ({
fields: undefined,
externalId: '17064f9d-0362-468d-8317-5984b7efd1b5',
marcFormat: marcType.toUpperCase(),
leader: mockLeaders[marcType],
parsedRecordDtoId: '1bf159d9-4da8-4c3f-9aac-c83e68356bbf',
parsedRecordId: '1bf159d9-4da8-4c3f-9aac-c83e68356bbf',
records: mockRecords[marcType],
suppressDiscovery: false,
updateInfo: { recordState: 'NEW' },
}));
const mockFormValues = jest.fn();

const mockSpecs = {
[MARC_TYPES.BIB]: fixedFieldSpecBib,
Expand All @@ -286,6 +280,7 @@ const mockSpecs = {
const mockActualizeLinks = jest.fn((formValuesToProcess) => Promise.resolve(formValuesToProcess));
const mockUpdateMarcRecord = jest.fn().mockResolvedValue();
const mockOnCheckCentralTenantPerm = jest.fn().mockReturnValue(false);
const mockValidateFetch = jest.fn().mockResolvedValue({});

jest.mock('@folio/stripes/final-form', () => () => (Component) => ({
onSubmit,
Expand Down Expand Up @@ -421,6 +416,18 @@ describe('Given QuickMarcEditWrapper', () => {
},
};

mockFormValues.mockImplementation((marcType) => ({
fields: undefined,
externalId: '17064f9d-0362-468d-8317-5984b7efd1b5',
marcFormat: marcType.toUpperCase(),
leader: mockLeaders[marcType],
parsedRecordDtoId: '1bf159d9-4da8-4c3f-9aac-c83e68356bbf',
parsedRecordId: '1bf159d9-4da8-4c3f-9aac-c83e68356bbf',
records: mockRecords[marcType],
suppressDiscovery: false,
updateInfo: { recordState: 'NEW' },
}));

useAuthorityLinking.mockReturnValue({
linkableBibFields: [],
actualizeLinks: mockActualizeLinks,
Expand All @@ -439,6 +446,10 @@ describe('Given QuickMarcEditWrapper', () => {
search: 'relatedRecordVersion=1',
});

useValidate.mockReturnValue({
validate: mockValidateFetch,
});

jest.clearAllMocks();
});

Expand Down Expand Up @@ -621,6 +632,62 @@ describe('Given QuickMarcEditWrapper', () => {
expect(mockUpdateMarcRecord).toHaveBeenCalledWith(formValuesForEdit);
});

describe('and there is a linked field', () => {
it('should run backend validation with the content from all split fields', async () => {
const formValues = mockFormValues(MARC_TYPES.BIB);

const field240 = {
'tag': '240',
'content': '$a a $0 http://id.loc.gov/authorities/names/n2016004081 $9 58e3deb0-d1c9-4e22-918d-a393f627e18c',
'indicators': ['\\', '\\'],
'isProtected': false,
'linkDetails': {
'authorityId': '58e3deb0-d1c9-4e22-918d-a393f627e18c',
'authorityNaturalId': 'n2016004081',
'linkingRuleId': 5,
'status': 'ACTUAL',
},
'id': '5cc17747-0b0a-44f6-807e-fd28138bbcaa',
'_isDeleted': false,
'_isLinked': true,
'subfieldGroups': {
'controlled': '$a a',
'uncontrolledAlpha': '$3 test',
'zeroSubfield': '$0 http://id.loc.gov/authorities/names/n2016004081',
'nineSubfield': '$9 58e3deb0-d1c9-4e22-918d-a393f627e18c',
'uncontrolledNumber': '',
},
};

mockFormValues.mockReturnValue({
...formValues,
records: [
field240,
...formValues.records,
],
});

const { getByText } = renderQuickMarcEditWrapper({
instance,
mutator,
});

await act(async () => { fireEvent.click(getByText('stripes-acq-components.FormFooter.save')); });

expect(mockValidateFetch).toHaveBeenCalledWith(expect.objectContaining({
body: expect.objectContaining({
fields: expect.arrayContaining([
expect.objectContaining({
tag: '240',
content: '$a a $3 test $0 http://id.loc.gov/authorities/names/n2016004081 $9 58e3deb0-d1c9-4e22-918d-a393f627e18c',
indicators: ['\\', '\\'],
}),
]),
}),
}));
});
});

describe('when there is an error during POST request', () => {
it('should show an error message', async () => {
const { getByText } = renderQuickMarcEditWrapper({
Expand Down

0 comments on commit 30c579b

Please sign in to comment.