From e90aa56dbe711e452f07d33489409b90eff3f4d4 Mon Sep 17 00:00:00 2001 From: Denys Bohdan Date: Tue, 15 Oct 2024 15:33:28 +0200 Subject: [PATCH] UIQM-652 update tests for updating related record version --- src/QuickMarcEditor/QuickMarcEditWrapper.js | 2 +- .../QuickMarcEditWrapper.test.js | 15 ++++---- .../QuickMarcEditorContainer.test.js | 37 ------------------- test/jest/helpers/harness.js | 7 +++- 4 files changed, 15 insertions(+), 46 deletions(-) diff --git a/src/QuickMarcEditor/QuickMarcEditWrapper.js b/src/QuickMarcEditor/QuickMarcEditWrapper.js index 09e48f2f..85531437 100644 --- a/src/QuickMarcEditor/QuickMarcEditWrapper.js +++ b/src/QuickMarcEditor/QuickMarcEditWrapper.js @@ -241,7 +241,6 @@ const QuickMarcEditWrapper = ({ marcType, mutator, linksCount, - location, prepareForSubmit, actualizeLinks, centralTenantId, @@ -250,6 +249,7 @@ const QuickMarcEditWrapper = ({ updateMarcRecord, isRequestToCentralTenantFromMember, validationErrorsRef, + relatedRecordVersion, ]); return ( diff --git a/src/QuickMarcEditor/QuickMarcEditWrapper.test.js b/src/QuickMarcEditor/QuickMarcEditWrapper.test.js index 18c9926c..d7176c3c 100644 --- a/src/QuickMarcEditor/QuickMarcEditWrapper.test.js +++ b/src/QuickMarcEditor/QuickMarcEditWrapper.test.js @@ -361,9 +361,10 @@ const renderQuickMarcEditWrapper = ({ instance, mutator, marcType = MARC_TYPES.BIB, + quickMarcContext, ...props }) => (render( - +
{ isLoading: false, }); - useLocation.mockReturnValue({ - search: 'relatedRecordVersion=1', - }); + useLocation.mockReturnValue({}); useValidate.mockReturnValue({ validate: mockValidateFetch, @@ -481,13 +480,16 @@ describe('Given QuickMarcEditWrapper', () => { it('should show on save message and redirect on load page', async () => { const mockOnSave = jest.fn(); - const { getByText } = renderQuickMarcEditWrapper({ + const { getByRole } = renderQuickMarcEditWrapper({ instance, mutator, onSave: mockOnSave, + quickMarcContext: { + relatedRecordVersion: 1, + }, }); - await act(async () => { fireEvent.click(getByText('stripes-acq-components.FormFooter.save')); }); + await act(async () => { fireEvent.click(getByRole('button', { name: 'stripes-acq-components.FormFooter.save' })); }); expect(mutator.quickMarcEditInstance.GET).toHaveBeenCalled(); expect(mockUpdateMarcRecord).toHaveBeenCalled(); @@ -620,7 +622,6 @@ describe('Given QuickMarcEditWrapper', () => { 'parsedRecordDtoId': '1bf159d9-4da8-4c3f-9aac-c83e68356bbf', 'parsedRecordId': '1bf159d9-4da8-4c3f-9aac-c83e68356bbf', 'records': undefined, - 'relatedRecordVersion': '1', 'suppressDiscovery': false, 'updateInfo': { 'recordState': 'NEW', diff --git a/src/QuickMarcEditor/QuickMarcEditorContainer.test.js b/src/QuickMarcEditor/QuickMarcEditorContainer.test.js index f3e42556..673eab97 100644 --- a/src/QuickMarcEditor/QuickMarcEditorContainer.test.js +++ b/src/QuickMarcEditor/QuickMarcEditorContainer.test.js @@ -226,43 +226,6 @@ describe('Given Quick Marc Editor Container', () => { expect(getByText(instance.title)).toBeDefined(); }); - describe('when the action is not CREATE', () => { - it('should append the relatedRecordVersion parameter to URL', async () => { - const spyHistory = jest.spyOn(mockHistory, 'replace'); - - await act(async () => { - await renderQuickMarcEditorContainer({ - mutator, - onClose: jest.fn(), - action: QUICK_MARC_ACTIONS.EDIT, - wrapper: QuickMarcEditWrapper, - }); - }); - - expect(spyHistory).toHaveBeenCalledWith({ search: expect.stringContaining('relatedRecordVersion=1') }); - }); - }); - - describe('when the action is CREATE', () => { - it('should not append the relatedRecordVersion parameter to URL', async () => { - const history = createMemoryHistory(); - - history.replace = jest.fn(); - - await act(async () => { - await renderQuickMarcEditorContainer({ - mutator, - onClose: jest.fn(), - action: QUICK_MARC_ACTIONS.CREATE, - wrapper: QuickMarcEditWrapper, - history, - }); - }); - - expect(history.replace).not.toHaveBeenCalled(); - }); - }); - describe('Leader field', () => { describe('when the action is CREATE a bib record', () => { let recordLengthField; diff --git a/test/jest/helpers/harness.js b/test/jest/helpers/harness.js index 9ad48cd9..abf84ce4 100644 --- a/test/jest/helpers/harness.js +++ b/test/jest/helpers/harness.js @@ -20,8 +20,13 @@ const defaultHistory = createMemoryHistory(); const queryClient = new QueryClient(); +const defaultQuickMarcContextValue = { + validationErrorsRef: { current: {} }, + setValidationErrors: jest.fn(), +}; + const QuickMarcProviderMock = ({ ctxValue, children }) => ( - + {children} );