From 2363f40243246f462b58e3a75efc1da501cf32bb Mon Sep 17 00:00:00 2001 From: Dmytro-Melnyshyn Date: Mon, 14 Oct 2024 16:37:18 +0300 Subject: [PATCH] UIQM-711: Update alidateFixedFieldPositions to display all 008 field errors instead of one in Bibliographic records. --- CHANGELOG.md | 1 + src/hooks/useValidation/validators.js | 2 +- src/hooks/useValidation/validators.test.js | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffa44ef4..402169f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ * [UIQM-704](https://issues.folio.org/browse/UIQM-704) Linked fields - combine split fields before sending for validation. * [UIQM-708](https://issues.folio.org/browse/UIQM-708) Change 007 Microforms type to allow 4 characters in RRR/RR field. * [UIQM-714](https://issues.folio.org/browse/UIQM-714) *BREAKING* Upgrade `inventory` to `14.0`. +* [UIQM-711](https://issues.folio.org/browse/UIQM-711) Update `validateFixedFieldPositions` to display all 008 field errors instead of one in Bibliographic records. ## [8.0.1] (https://github.com/folio-org/ui-quick-marc/tree/v8.0.1) (2024-04-18) diff --git a/src/hooks/useValidation/validators.js b/src/hooks/useValidation/validators.js index a1dfb5d2..4e23cbdb 100644 --- a/src/hooks/useValidation/validators.js +++ b/src/hooks/useValidation/validators.js @@ -399,7 +399,7 @@ export const validateFixedFieldPositions = ({ marcRecords, fixedFieldSpec, marcT const subFieldContentArray = Array.isArray(contents) ? contents : [contents]; if (!subFieldContentArray.every(content => subField.allowedValues.find(value => value.code === content))) { - return { ...acc, [field.id]: [rule.message(subField.code)] }; + acc[field.id] = [...(acc[field.id] || []), rule.message(subField.code)]; } } diff --git a/src/hooks/useValidation/validators.test.js b/src/hooks/useValidation/validators.test.js index ad0b7da0..9da6ae91 100644 --- a/src/hooks/useValidation/validators.test.js +++ b/src/hooks/useValidation/validators.test.js @@ -713,6 +713,25 @@ describe('validators', () => { expect(rule.message).toHaveBeenCalledWith('Ills'); }); + + it('should return all errors instead of one', () => { + const marcRecords = [{ + tag: LEADER_TAG, + content: bibLeader, + }, { + id: 'id-008', + tag: FIXED_FIELD_TAG, + content: { + DtSt: '_', + Ills: '_', + }, + }]; + const marcType = MARC_TYPES.BIB; + + const errors = validators.validateFixedFieldPositions({ marcRecords, fixedFieldSpec, marcType }, rule); + + expect(errors['id-008'].length).toBe(2); + }); }); describe('validateLccnDuplication', () => {