From 3cb1179debe4aaaf1b026ad0b7a0dbd594e004d3 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Fri, 16 Feb 2024 15:52:09 +0400 Subject: [PATCH 1/6] UIBULKED-210: Improve user errors for invalid data - IncorrectTokenCountException error --- src/components/ProgressBar/ProgressBar.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/ProgressBar/ProgressBar.js b/src/components/ProgressBar/ProgressBar.js index df6b88c1..f0aae149 100644 --- a/src/components/ProgressBar/ProgressBar.js +++ b/src/components/ProgressBar/ProgressBar.js @@ -1,4 +1,4 @@ -import { useContext, useEffect } from 'react'; +import React, { useContext, useEffect } from 'react'; import { useParams } from 'react-router'; import { useLocation } from 'react-router-dom'; import { FormattedMessage, useIntl } from 'react-intl'; @@ -8,7 +8,7 @@ import { Icon, Loading } from '@folio/stripes/components'; import { useShowCallout } from '@folio/stripes-acq-components'; import { useBulkOperationDetails } from '../../hooks/api'; -import { JOB_STATUSES } from '../../constants'; +import { ERRORS, JOB_STATUSES } from '../../constants'; import { getBulkOperationStep } from './utils'; import css from './ProgressBar.css'; @@ -33,6 +33,7 @@ export const ProgressBar = () => { }); const status = bulkDetails?.status; + const errorMessage = bulkDetails?.errorMessage; const progressPercentage = bulkDetails ? (bulkDetails.processedNumOfRecords / bulkDetails.totalNumOfRecords) * 100 : 0; @@ -40,7 +41,9 @@ export const ProgressBar = () => { const swwCallout = () => { callout({ type: 'error', - message: intl.formatMessage({ id: 'ui-bulk-edit.error.sww' }), + message:errorMessage?.includes(ERRORS.TOKEN) ? + : + intl.formatMessage({ id: 'ui-bulk-edit.error.sww' }), }); }; From 69707c0acdbf50cdf5beab0841adeff1d91bba1a Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Fri, 16 Feb 2024 17:35:36 +0400 Subject: [PATCH 2/6] UIBULKED-210: Improve user errors for invalid data - IncorrectTokenCountException error --- .../BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js index 1e1e7087..6f69184f 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.js @@ -101,9 +101,10 @@ const BulkEditInAppPreviewModal = ({ onSuccess: fileData => { const searchParams = new URLSearchParams(history.location.search); let fileName = searchParams.get('fileName'); + const criteria = searchParams.get('criteria'); if (!fileName) { - fileName = `${currentRecordType}-${searchParams.get('criteria')}.csv`; + fileName = `${criteria.charAt(0).toUpperCase().toUpperCase() + criteria.slice(1)}-${bulkOperationId}.csv`; } saveAs(new Blob([fileData]), `${getFormattedFilePrefixDate()}-Updates-Preview-${fileName}`); From f51d1286783b9060aae0b6c01c4c10dab8a4f3a6 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Fri, 16 Feb 2024 17:36:30 +0400 Subject: [PATCH 3/6] UIBULKED-210: add space --- src/components/ProgressBar/ProgressBar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ProgressBar/ProgressBar.js b/src/components/ProgressBar/ProgressBar.js index f0aae149..90ed6d25 100644 --- a/src/components/ProgressBar/ProgressBar.js +++ b/src/components/ProgressBar/ProgressBar.js @@ -41,7 +41,7 @@ export const ProgressBar = () => { const swwCallout = () => { callout({ type: 'error', - message:errorMessage?.includes(ERRORS.TOKEN) ? + message: errorMessage?.includes(ERRORS.TOKEN) ? : intl.formatMessage({ id: 'ui-bulk-edit.error.sww' }), }); From 4595a3a3c5f437dc6fdfcd105b1b8e71bc04ad29 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Sun, 18 Feb 2024 18:54:07 +0400 Subject: [PATCH 4/6] UIBULKED-210: add error text for query --- .../ErrorsAccordion/ErrorsAccordion.js | 37 +++++++++++++------ translations/ui-bulk-edit/en.json | 2 + 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js b/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js index 1a244619..f61c235a 100644 --- a/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js +++ b/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.js @@ -8,6 +8,8 @@ import { } from '@folio/stripes/components'; import { useState } from 'react'; import css from '../Preview.css'; +import { useSearchParams } from '../../../../../hooks/useSearchParams'; +import { CRITERIA } from '../../../../../constants'; const visibleColumns = ['key', 'message']; @@ -29,6 +31,7 @@ const ErrorsAccordion = ({ isInitial, }) => { const location = useLocation(); + const { criteria } = useSearchParams(); const fileName = new URLSearchParams(location.search).get('fileName'); const errorLength = errors.length; @@ -36,17 +39,29 @@ const ErrorsAccordion = ({ const headLineTranslateKey = isInitial ? 'info' : 'infoProcessed'; - const headLine = ( - - ); + const headLine = criteria === CRITERIA.QUERY ? + ( + + ) + : + ( + + ); return (
diff --git a/translations/ui-bulk-edit/en.json b/translations/ui-bulk-edit/en.json index d0b57544..26666b27 100644 --- a/translations/ui-bulk-edit/en.json +++ b/translations/ui-bulk-edit/en.json @@ -85,6 +85,8 @@ "list.errors.title": "Errors", "list.errors.info": "{fileName}: {entries, number} entries * {matched, number} records matched * {errors, number} errors", "list.errors.infoProcessed": "{fileName}: {entries, number} entries * {matched, number} records changed * {errors, number} errors", + "list.errors.query.info": "Bulk edit query: {entries, number} entries * {matched, number} records matched * {errors, number} errors", + "list.errors.query.infoProcessed": "Bulk edit query: {entries, number} entries * {matched, number} records changed * {errors, number} errors", "list.errors.table.code": "Record identifier", "list.errors.table.message": "Reason for error", From 3dcd35076fba459634c2d7b607613710f637e97e Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Mon, 19 Feb 2024 11:20:56 +0400 Subject: [PATCH 5/6] UIBULKED-210: add error text for query --- .../BulkEditInAppPreviewModal.test.js | 17 ++++++++++++++--- .../ProgressBar/ProgressBar.test.js | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js index c2af58fa..ef1ae9cf 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js @@ -1,7 +1,12 @@ import { QueryClientProvider } from 'react-query'; import { MemoryRouter } from 'react-router'; -import { act, render, screen, fireEvent } from '@testing-library/react'; +import { + act, + render, + screen, + fireEvent +} from '@testing-library/react'; import { useOkapiKy } from '@folio/stripes/core'; @@ -42,9 +47,9 @@ const defaultProps = { contentUpdates: undefined, }; -const renderPreviewModal = (props = defaultProps) => { +const renderPreviewModal = (props = defaultProps, fileName = 'barcodes.csv') => { return render( - + { expect(onKeepEditing).toHaveBeenCalled(); }); + it('should call all footer handlers without fileName', () => { + renderPreviewModal(defaultProps, ''); + + fireEvent.click(screen.getByText('ui-bulk-edit.previewModal.downloadPreview')); + }); + it('should display preview records when available', async () => { const contentUpdates = [ { diff --git a/src/components/ProgressBar/ProgressBar.test.js b/src/components/ProgressBar/ProgressBar.test.js index 3fc2d512..d68197e2 100644 --- a/src/components/ProgressBar/ProgressBar.test.js +++ b/src/components/ProgressBar/ProgressBar.test.js @@ -5,7 +5,7 @@ import { render, screen } from '@testing-library/react'; import { runAxeTest } from '@folio/stripes-testing'; -import { JOB_STATUSES } from '../../constants'; +import { ERRORS, JOB_STATUSES } from '../../constants'; import { useBulkOperationDetails } from '../../hooks/api'; import { ProgressBar } from './ProgressBar'; @@ -33,6 +33,7 @@ describe('ProgressBar', () => { totalNumOfRecords: 100, status: JOB_STATUSES.APPLY_CHANGES, }; + const clearIntervalAndRedirect = jest.fn(); beforeEach(() => { @@ -108,3 +109,19 @@ describe('ProgressBar', () => { }); }); }); + +describe('test', () => { + const bulkOperationWithError = { + processedNumOfRecords: 50, + totalNumOfRecords: 100, + status: JOB_STATUSES.FAILED, + errorMessage: ERRORS.TOKEN + }; + + it('should render with error', async () => { + useBulkOperationDetails.mockClear().mockReturnValue({ bulkDetails: bulkOperationWithError, + clearIntervalAndRedirect: jest.fn() }); + + renderProgressBar(); + }); +}); From 5991d78580896e935304834960283f0cc22734da Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Mon, 19 Feb 2024 11:30:57 +0400 Subject: [PATCH 6/6] UIBULKED-210: increase test coverage --- .../Preview/ErrorsAccordion/ErrorsAccordion.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.test.js b/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.test.js index b70074bd..f37d7ef1 100644 --- a/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.test.js +++ b/src/components/BulkEditList/BulkEditListResult/Preview/ErrorsAccordion/ErrorsAccordion.test.js @@ -34,6 +34,16 @@ describe('ErrorsAccordion', () => { expect(screen.getByText(errorsPreview.errors[0].message)).toBeVisible(); }); + it('should render preview accordion for bulk edit query', () => { + const mockHistory = ['/bulk-edit/1/preview?criteria=query']; + + renderPreviewAccordion(mockHistory, { ...defaultProps, initial: true }); + + expect(screen.getByText(/errors.query.info/)).toBeVisible(); + expect(screen.getByText(/errors.table.code/)).toBeVisible(); + expect(screen.getByText(errorsPreview.errors[0].message)).toBeVisible(); + }); + it('should render with no axe errors', async () => { const mockHistory = ['/bulk-edit/1/preview'];