Skip to content

Commit

Permalink
UIQM-165: Update error message when user attempts to save a record wi…
Browse files Browse the repository at this point in the history
…thout a 852 (#231)

* UIQM-165: Update error message when user attempts to save a record without a 852

* UIQM-165 added tests for missing 852 field in marc holdings

* Update src/QuickMarcEditor/utils.js

Co-authored-by: Vladyslav Velytskyi <[email protected]>

Co-authored-by: Vladyslav Velytskyi <[email protected]>
  • Loading branch information
BogdanDenis and Vladyslav-Velytskyi committed Nov 9, 2021
1 parent 4a01216 commit f784ab7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change history for ui-quick-marc

## [4.0.2](IN PROGRESS)

* [UIQM-165](https://issues.folio.org/browse/UIQM-165) Update error message when user attempts to save a record without a 852.

## [4.0.2](https://github.com/folio-org/ui-quick-marc/tree/v4.0.2) (2021-11-02)

* [UIQM-161](https://issues.folio.org/browse/UIQM-161) Remove add button for MARC holdings tag 004.
Expand Down
14 changes: 14 additions & 0 deletions src/QuickMarcEditor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ const validateMarcBibRecord = (marcRecords) => {
return undefined;
};

const validateMarcHoldingsRecord = (marcRecords) => {
const locationRecords = marcRecords.filter(({ tag }) => tag === '852');

if (!locationRecords.length) {
return <FormattedMessage id="ui-quick-marc.record.error.location.empty" />;
}

return undefined;
};

export const validateMarcRecord = (marcRecord, marcType = MARC_TYPES.BIB) => {
const marcRecords = marcRecord.records || [];
const recordLeader = marcRecords[0];
Expand All @@ -247,6 +257,10 @@ export const validateMarcRecord = (marcRecord, marcType = MARC_TYPES.BIB) => {
validationResult = validateMarcBibRecord(marcRecords);
}

if (marcType === MARC_TYPES.HOLDINGS) {
validationResult = validateMarcHoldingsRecord(marcRecords);
}

if (validationResult) {
return validationResult;
}
Expand Down
45 changes: 41 additions & 4 deletions src/QuickMarcEditor/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
LEADER_TAG,
QUICK_MARC_ACTIONS,
} from './constants';
import { MARC_TYPES } from '../common/constants';
import { RECORD_STATUS_NEW } from './QuickMarcRecordInfo/constants';
import * as utils from './utils';

Expand Down Expand Up @@ -178,7 +179,7 @@ describe('QuickMarcEditor utils', () => {
records: [
{
content: '04706cam a2200865Ii 4500',
tag: '025',
tag: 'LDR',
},
{
tag: '008',
Expand All @@ -202,7 +203,7 @@ describe('QuickMarcEditor utils', () => {
records: [
{
content: '04706cam a2200865Ii 4500',
tag: '025',
tag: 'LDR',
},
],
};
Expand All @@ -216,7 +217,7 @@ describe('QuickMarcEditor utils', () => {
records: [
{
content: '04706cam a2200865Ii 4500',
tag: '025',
tag: 'LDR',
},
{
tag: '008',
Expand All @@ -237,7 +238,7 @@ describe('QuickMarcEditor utils', () => {
records: [
{
content: '04706cam a2200865Ii 4500',
tag: '245',
tag: 'LDR',
},
{
tag: '008',
Expand All @@ -249,11 +250,47 @@ describe('QuickMarcEditor utils', () => {
{
tag: '245',
},
{
tag: '245',
},
],
};

expect(utils.validateMarcRecord(record).props.id).toBe('ui-quick-marc.record.error.title.multiple');
});

describe('when record is MARC Holdings record', () => {
it('should not return error message when record is valid', () => {
const record = {
leader: '04706cxm a22008651i 4500',
records: [
{
content: '04706cxm a22008651i 4500',
tag: 'LDR',
},
{
tag: '852',
},
],
};

expect(utils.validateMarcRecord(record, MARC_TYPES.HOLDINGS)).not.toBeDefined();
});

it('should return error message when record is without 852 row', () => {
const record = {
leader: '04706cxm a22008651i 4500',
records: [
{
content: '04706cxm a22008651i 4500',
tag: 'LDR',
},
],
};

expect(utils.validateMarcRecord(record, MARC_TYPES.HOLDINGS).props.id).toBe('ui-quick-marc.record.error.location.empty');
});
});
});

describe('validateRecordMismatch', () => {
Expand Down
1 change: 1 addition & 0 deletions translations/ui-quick-marc/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"record.error.leader.invalidPositionValue": "Invalid value entered for the Leader {position}",
"record.error.title.multiple": "Record cannot be saved with more than one field 245.",
"record.error.title.empty": "Record cannot be saved without field 245.",
"record.error.location.empty": "Record cannot be saved. An 852 is required.",
"record.error.tag.length": "Record cannot be saved. Each field must contain three characters in the first text box of each row.",
"record.error.tag.nonDigits": "Invalid MARC tag. Please try again.",
"record.error.subfield": "Missing a subfield value for a MARC tag",
Expand Down

0 comments on commit f784ab7

Please sign in to comment.