Skip to content

Commit

Permalink
UIQM-652 update tests for updating related record version
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed Oct 15, 2024
1 parent 43085a8 commit e90aa56
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/QuickMarcEditor/QuickMarcEditWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ const QuickMarcEditWrapper = ({
marcType,
mutator,
linksCount,
location,
prepareForSubmit,
actualizeLinks,
centralTenantId,
Expand All @@ -250,6 +249,7 @@ const QuickMarcEditWrapper = ({
updateMarcRecord,
isRequestToCentralTenantFromMember,
validationErrorsRef,
relatedRecordVersion,
]);

return (
Expand Down
15 changes: 8 additions & 7 deletions src/QuickMarcEditor/QuickMarcEditWrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,10 @@ const renderQuickMarcEditWrapper = ({
instance,
mutator,
marcType = MARC_TYPES.BIB,
quickMarcContext,
...props
}) => (render(
<Harness>
<Harness quickMarcContext={quickMarcContext}>
<Form
onSubmit={jest.fn()}
mutators={arrayMutators}
Expand Down Expand Up @@ -442,9 +443,7 @@ describe('Given QuickMarcEditWrapper', () => {
isLoading: false,
});

useLocation.mockReturnValue({
search: 'relatedRecordVersion=1',
});
useLocation.mockReturnValue({});

useValidate.mockReturnValue({
validate: mockValidateFetch,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down
37 changes: 0 additions & 37 deletions src/QuickMarcEditor/QuickMarcEditorContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion test/jest/helpers/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ const defaultHistory = createMemoryHistory();

const queryClient = new QueryClient();

const defaultQuickMarcContextValue = {
validationErrorsRef: { current: {} },
setValidationErrors: jest.fn(),
};

const QuickMarcProviderMock = ({ ctxValue, children }) => (
<QuickMarcContext.Provider value={ctxValue}>
<QuickMarcContext.Provider value={{ ...defaultQuickMarcContextValue, ...ctxValue }}>
{children}
</QuickMarcContext.Provider>
);
Expand Down

0 comments on commit e90aa56

Please sign in to comment.