Skip to content

Commit

Permalink
test: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Nov 13, 2024
1 parent 708df0b commit cf1d71b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/invoices/VersionHistory/VersionHistory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const kyMock = {

const queryClient = new QueryClient();

// eslint-disable-next-line react/prop-types
const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
<MemoryRouter
Expand Down
2 changes: 1 addition & 1 deletion src/invoices/VersionHistory/VersionView.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { memo, useMemo } from 'react';
import { FormattedMessage } from 'react-intl';
import { useParams } from 'react-router';
import { useParams } from 'react-router-dom';

import {
Layout,
Expand Down
41 changes: 41 additions & 0 deletions src/invoices/VersionHistory/VersionView.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useParams } from 'react-router-dom';

import {
render,
screen,
} from '@folio/jest-config-stripes/testing-library/react';

import VersionView from './VersionView';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn(() => ({ versionId: 'versionId' })),
}));

jest.mock('@folio/stripes/components', () => ({
...jest.requireActual('@folio/stripes/components'),
LoadingPane: jest.fn().mockReturnValue('Loading'),
}));

describe('VersionView', () => {
it('should display loading pane when isLoading is true', () => {
render(<VersionView isLoading />);
expect(screen.getByText('Loading')).toBeInTheDocument();
});

it('should display children when isLoading is false and versionId exists', () => {
render(
<VersionView isLoading={false}>
<div>Children</div>
</VersionView>,
);
expect(screen.getByText('Children')).toBeInTheDocument();
});

it('should display no version message when isLoading is false and versionId does not exist', () => {
useParams.mockReturnValue({ versionId: null });

render(<VersionView isLoading={false} />);
expect(screen.getByText('ui-invoice.invoice.versionHistory.noVersion')).toBeInTheDocument();
});
});

0 comments on commit cf1d71b

Please sign in to comment.