Skip to content

Commit

Permalink
UIIN-2896 added tests for new edit marc record shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanDenis committed May 10, 2024
1 parent 54f4d9c commit f2c31ed
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/ViewHoldingsRecord.test.js
Expand Up @@ -43,10 +43,11 @@ const spyOncollapseAllSections = jest.spyOn(require('@folio/stripes/components')
const spyOnexpandAllSections = jest.spyOn(require('@folio/stripes/components'), 'expandAllSections');

const mockData = jest.fn().mockResolvedValue({ id: 'testId' });
const mockGoTo = jest.fn();

const defaultProps = {
id: 'id',
goTo: jest.fn(),
goTo: mockGoTo,
holdingsrecordid: 'holdingId',
referenceTables: {
holdingsSources: [{ id: 'sourceId', name: 'MARC' }],
Expand All @@ -57,7 +58,12 @@ const defaultProps = {
resources: {
holdingsRecords: {
records: [
{ sourceId: 'sourceId', temporaryLocationId: 'inactiveLocation' }
{
sourceId: 'sourceId',
temporaryLocationId: 'inactiveLocation',
id: 'holdingId',
_version: 1,
}
],
},
instances1: { records: [{ id: 'instanceId' }], hasLoaded: true },
Expand Down Expand Up @@ -270,4 +276,14 @@ describe('ViewHoldingsRecord actions', () => {
expect(spyOnexpandAllSections).toHaveBeenCalled();
});
});

describe('when using an editMARC shortcut', () => {
it('should redirect to marc edit page', async () => {
await act(async () => { renderViewHoldingsRecord(); });

fireEvent.click(screen.getByRole('button', { name: 'editMARC' }));

expect(mockGoTo).toHaveBeenLastCalledWith(`/inventory/quick-marc/edit-holdings/instanceId/${defaultProps.holdingsrecordid}?%2F=&relatedRecordVersion=1`);
});
});
});
15 changes: 15 additions & 0 deletions src/ViewInstance.test.js
Expand Up @@ -1162,4 +1162,19 @@ describe('ViewInstance', () => {
expect(spyOnexpandAllSections).toBeCalled();
});
});

describe('when using an editMARC shortcut', () => {
it('should redirect to marc edit page', () => {
renderViewInstance({
isShared: true,
});

fireEvent.click(screen.getByRole('button', { name: 'editMARC' }));

expect(mockPush).toHaveBeenLastCalledWith({
pathname: `/inventory/quick-marc/edit-bib/${instance.id}`,
search: 'filters=test1&query=test2&sort=test3&qindex=test&shared=true',
});
});
});
});
32 changes: 31 additions & 1 deletion src/components/ViewSource/ViewSource.test.js
@@ -1,5 +1,8 @@
import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import {
BrowserRouter as Router,
useHistory,
} from 'react-router-dom';
import { act } from 'react-dom/test-utils';

import {
Expand All @@ -18,6 +21,12 @@ import { CONSORTIUM_PREFIX } from '../../constants';
import MARC_TYPES from './marcTypes';

jest.mock('../../common/hooks/useGoBack', () => jest.fn());
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: jest.fn().mockReturnValue({
push: jest.fn(),
}),
}));

const mutator = {
marcRecord: {
Expand All @@ -26,6 +35,7 @@ const mutator = {
};

const mockGoBack = jest.fn();
const mockPush = jest.fn();
const mockInstance = {
id: 'instance-id',
title: 'Instance title',
Expand All @@ -49,6 +59,9 @@ const getViewSource = (props = {}) => (

describe('ViewSource', () => {
beforeEach(() => {
useHistory.mockClear().mockReturnValue({
push: mockPush,
});
useGoBack.mockReturnValue(mockGoBack);
});

Expand Down Expand Up @@ -153,4 +166,21 @@ describe('ViewSource', () => {
expect(screen.getByText('Local MARC bibliographic record')).toBeInTheDocument();
});
});

describe('when using an editMARC shortcut', () => {
beforeEach(async () => {
await act(async () => {
await renderWithIntl(getViewSource(), translations);
});
});

it('should redirect to marc edit page', () => {
fireEvent.click(screen.getByRole('button', { name: 'editMARC' }));

expect(mockPush).toHaveBeenLastCalledWith({
pathname: `/inventory/quick-marc/edit-bib/${mockInstance.id}`,
search: 'shared=false',
});
});
});
});

0 comments on commit f2c31ed

Please sign in to comment.