From 9d545a235f9cf1e5ee6530f3bf1c4967ca512ef6 Mon Sep 17 00:00:00 2001 From: Denys Bohdan Date: Mon, 2 Dec 2024 16:22:24 +0100 Subject: [PATCH] UIQM-740 Don't show warn/fail error toasts when there are no warns/fails. --- CHANGELOG.md | 1 + src/QuickMarcEditor/QuickMarcEditor.js | 5 +++++ src/QuickMarcEditor/QuickMarcEditor.test.js | 24 +++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index faebbb1e..acedde57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [UIQM-716](https://issues.folio.org/browse/UIQM-716) *BREAKING* Consolidate routes based on MARC type for bib and authority records to avoid page refresh after redirecting from the create page to the edit one. * [UIQM-730](https://issues.folio.org/browse/UIQM-730) Create/Edit/Derive MARC record - Retain focus when MARC record validation rules error display. Show validation issues toasts. +* [UIQM-740](https://issues.folio.org/browse/UIQM-740) Don't show warn/fail error toasts when there are no warns/fails. ## [9.0.1](https://github.com/folio-org/ui-quick-marc/tree/v9.0.1) (2024-11-22) diff --git a/src/QuickMarcEditor/QuickMarcEditor.js b/src/QuickMarcEditor/QuickMarcEditor.js index 0e1a04d0..1526fd24 100644 --- a/src/QuickMarcEditor/QuickMarcEditor.js +++ b/src/QuickMarcEditor/QuickMarcEditor.js @@ -232,11 +232,16 @@ const QuickMarcEditor = ({ const failCount = allIssuesArray.filter(issue => issue.severity === SEVERITY.ERROR).length; const warnCount = allIssuesArray.length - failCount; + if (!failCount && !warnCount) { + return; + } + const values = { warnCount, failCount, breakingLine:
, }; + let messageId = null; if (failCount && warnCount) { diff --git a/src/QuickMarcEditor/QuickMarcEditor.test.js b/src/QuickMarcEditor/QuickMarcEditor.test.js index edc89a62..60ee8c87 100644 --- a/src/QuickMarcEditor/QuickMarcEditor.test.js +++ b/src/QuickMarcEditor/QuickMarcEditor.test.js @@ -895,6 +895,30 @@ describe('Given QuickMarcEditor', () => { }); }); + describe('when saving form without validation warnings or errors', () => { + beforeEach(async () => { + mockValidate.mockClear().mockResolvedValue({}); + + const { + getByText, + getByTestId, + } = renderQuickMarcEditor(); + + const contentField = getByTestId('content-field-3'); + + fireEvent.change(contentField, { target: { value: '' } }); + await fireEvent.click(getByText('stripes-acq-components.FormFooter.save')); + }); + + it('should show a toast notification about validation warning and error', async () => { + await waitFor(() => { + expect(mockShowCallout).not.toHaveBeenCalledWith(expect.objectContaining({ + messageId: expect.stringContaining('ui-quick-marc.record.save.error'), + })); + }); + }); + }); + describe('when marc record is of type HOLDINGS', () => { describe('when action is create', () => { it('should not show "Save & keep editing" button', () => {