diff --git a/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js b/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js index aa149b57..d6b1ddab 100644 --- a/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js +++ b/src/components/BulkEditPane/BulkEditListResult/BulkEditInAppPreviewModal/BulkEditInAppPreviewModal.test.js @@ -2,10 +2,8 @@ import { QueryClientProvider } from 'react-query'; import { MemoryRouter } from 'react-router'; import { - act, render, screen, - fireEvent } from '@testing-library/react'; import { useOkapiKy } from '@folio/stripes/core'; @@ -16,11 +14,7 @@ import { bulkEditLogsData } from '../../../../../test/jest/__mock__/fakeData'; import { queryClient } from '../../../../../test/jest/utils/queryClient'; import { RootContext } from '../../../../context/RootContext'; -import { - ACTIONS, - OPTIONS, - JOB_STATUSES, -} from '../../../../constants'; +import { JOB_STATUSES } from '../../../../constants'; import { useBulkOperationDetails, useRecordsPreview, @@ -37,14 +31,12 @@ const bulkOperation = bulkEditLogsData[0]; const visibleColumns = []; const setVisibleColumns = jest.fn(); const onKeepEditing = jest.fn(); -const onChangesCommited = jest.fn(); const defaultProps = { open: true, - bulkOperationId: bulkOperation.id.toString(), onKeepEditing, - onChangesCommited, - contentUpdates: undefined, + isPreviewLoading: false, + modalFooter:
Footer
, }; const renderPreviewModal = (props = defaultProps, fileName = 'barcodes.csv') => { @@ -92,28 +84,7 @@ describe('BulkEditInAppPreviewModal', () => { }); }); - it('should call all footer handlers', () => { - renderPreviewModal(); - - fireEvent.click(screen.getByText('ui-bulk-edit.previewModal.keepEditing')); - 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 = [ - { - option: OPTIONS.STATUS, - actions: [{ - type: ACTIONS.CLEAR_FIELD, - }], - }, - ]; const uuidColumn = { value: 'uuid', label: 'uuid', @@ -129,12 +100,7 @@ describe('BulkEditInAppPreviewModal', () => { status: JOB_STATUSES.REVIEW_CHANGES, }); - await act(async () => { - renderPreviewModal({ - ...defaultProps, - contentUpdates, - }); - }); + await renderPreviewModal(); expect(screen.getByText('ui-bulk-edit.previewModal.previewToBeChanged')).toBeInTheDocument(); @@ -142,4 +108,10 @@ describe('BulkEditInAppPreviewModal', () => { rootNode: document.body, }); }); + + it('should display footer if provided', async () => { + await renderPreviewModal(); + + expect(screen.getByText('Footer')).toBeInTheDocument(); + }); }); diff --git a/src/hooks/useConfirmChanges.test.js b/src/hooks/useConfirmChanges.test.js index c163c231..3b4efee6 100644 --- a/src/hooks/useConfirmChanges.test.js +++ b/src/hooks/useConfirmChanges.test.js @@ -5,7 +5,7 @@ import { useShowCallout } from '@folio/stripes-acq-components'; import '../../test/jest/__mock__/reactIntl.mock'; -import { useBulkOperationDetails, useBulkOperationStart, useFileDownload } from './api'; +import { useBulkOperationDetails, useBulkOperationStart } from './api'; import { useSearchParams } from './useSearchParams'; import { useConfirmChanges } from './useConfirmChanges'; import { pollForStatus } from '../utils/pollForStatus'; @@ -27,7 +27,6 @@ jest.mock('@folio/stripes-acq-components', () => ({ jest.mock('./api', () => ({ useBulkOperationDetails: jest.fn(), useBulkOperationStart: jest.fn(), - useFileDownload: jest.fn(), })); jest.mock('./useSearchParams', () => ({ @@ -46,7 +45,6 @@ describe('useConfirmChanges', () => { }; const mockBulkOperationDetails = { bulkDetails: { totalNumOfRecords: 100 } }; const mockBulkOperationStart = jest.fn(); - const mockDownloadFile = jest.fn(); beforeEach(() => { useShowCallout.mockReturnValue(mockCallout); @@ -54,7 +52,6 @@ describe('useConfirmChanges', () => { useBulkOperationDetails.mockReturnValue(mockBulkOperationDetails); useBulkOperationStart.mockReturnValue({ bulkOperationStart: mockBulkOperationStart }); useSearchParams.mockReturnValue({ criteria: 'testCriteria', initialFileName: 'initialFileName' }); - useFileDownload.mockReturnValue({ refetch: mockDownloadFile, isFetching: false }); pollForStatus.mockImplementation(() => Promise.resolve()); jest.clearAllMocks(); @@ -129,17 +126,4 @@ describe('useConfirmChanges', () => { expect(result.current.isPreviewLoading).toBe(false); expect(result.current.isPreviewModalOpened).toBe(false); // Modal should close on error }); - - it('should call downloadFile from useFileDownload', () => { - const { result } = renderHook(() => useConfirmChanges({ - queryDownloadKey: 'testKey', - bulkOperationId: '123', - })); - - act(() => { - result.current.downloadFile(); - }); - - expect(mockDownloadFile).toHaveBeenCalled(); - }); }); diff --git a/src/utils/files.test.js b/src/utils/files.test.js index 374cc0a7..b806c61e 100644 --- a/src/utils/files.test.js +++ b/src/utils/files.test.js @@ -57,15 +57,15 @@ describe('files', () => { it('should save the file with the correct name and extension for MARC approach', () => { const bulkOperationId = '123'; const fileData = 'data'; - const initialFileName = 'abc.csv'; - const approach = APPROACHES.MARC; + const initialFileName = 'abc.mrc'; + const extension = 'mrc'; getFormattedFilePrefixDate.mockReturnValue('2024-08-09'); savePreviewFile({ bulkOperationId, fileData, - approach, + extension, initialFileName, }); @@ -79,14 +79,14 @@ describe('files', () => { const bulkOperationId = '123'; const fileData = 'data'; const initialFileName = 'abc.csv'; - const approach = APPROACHES.IN_APP; + const extension = 'csv'; getFormattedFilePrefixDate.mockReturnValue('2024-08-09'); savePreviewFile({ bulkOperationId, fileData, - approach, + extension, initialFileName, }); @@ -100,14 +100,14 @@ describe('files', () => { const bulkOperationId = '123'; const fileData = 'data'; const initialFileName = ''; - const approach = APPROACHES.MARC; + const extension = 'mrc'; getFormattedFilePrefixDate.mockReturnValue('2024-08-09'); savePreviewFile({ bulkOperationId, fileData, - approach, + extension, initialFileName, });