From 31ace6d3ab1a5755a232ec453eb09e9fe1bb93b3 Mon Sep 17 00:00:00 2001 From: Denys Bohdan Date: Tue, 5 Nov 2024 13:57:16 +0100 Subject: [PATCH] UIQM-725 Fix wrong error message while saving MARC Bib record with invalid LDR position values. (#754) --- CHANGELOG.md | 4 ++++ src/QuickMarcEditor/utils.js | 4 ++++ src/QuickMarcEditor/utils.test.js | 32 ++++++++++++++++++------------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d69ed29..abe8543b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change history for ui-quick-marc +## [9.0.1] (IN PROGRESS) + +* [UIQM-725](https://issues.folio.org/browse/UIQM-725) Fix wrong error message while saving MARC Bib record with invalid LDR position values. + ## [9.0.0](https://github.com/folio-org/ui-quick-marc/tree/v9.0.0) (2024-11-01) * [UIQM-647](https://issues.folio.org/browse/UIQM-647) Import `useUserTenantPermissions` from `@folio/stripes/core`. diff --git a/src/QuickMarcEditor/utils.js b/src/QuickMarcEditor/utils.js index 82832f93..91d70fb6 100644 --- a/src/QuickMarcEditor/utils.js +++ b/src/QuickMarcEditor/utils.js @@ -1228,6 +1228,10 @@ export const isDiacritic = (char) => { }; export const getVisibleNonSelectable008Subfields = (fixedFieldType) => { + if (!fixedFieldType) { + return []; + } + return fixedFieldType.items .filter(field => !field.readOnly) .filter(field => !field.isArray); diff --git a/src/QuickMarcEditor/utils.test.js b/src/QuickMarcEditor/utils.test.js index b4082e71..ec49871f 100644 --- a/src/QuickMarcEditor/utils.test.js +++ b/src/QuickMarcEditor/utils.test.js @@ -1865,21 +1865,19 @@ describe('QuickMarcEditor utils', () => { }); describe('getFixedFieldStringPositions', () => { - beforeEach(() => { - jest.spyOn(FixedFieldFactory, 'getFixedFieldType').mockReturnValue({ - items: [{ - code: 'test1', - isArray: true, - }, { - code: 'test2', - isArray: false, - readOnly: false, - }], - }); - }); - describe('when a field is an 008', () => { it('should return an 008 config', () => { + jest.spyOn(FixedFieldFactory, 'getFixedFieldType').mockReturnValueOnce({ + items: [{ + code: 'test1', + isArray: true, + }, { + code: 'test2', + isArray: false, + readOnly: false, + }], + }); + const field = { tag: '008' }; expect(utils.getFixedFieldStringPositions('a', 'm', field, fixedFieldSpecBib)).toEqual([ @@ -1890,6 +1888,14 @@ describe('QuickMarcEditor utils', () => { }, ]); }); + + describe('when type or subtype are invalid', () => { + it('should return an empty array', () => { + const field = { tag: '008' }; + + expect(utils.getFixedFieldStringPositions('|', '|', field, fixedFieldSpecBib)).toEqual([]); + }); + }); }); describe('when a field is an 007', () => {