Skip to content

Commit

Permalink
UIIN-2669: Jest/RTL: Cover ModalContent components with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
UladzislauKutarkin committed May 6, 2024
1 parent 156cf5a commit bae2372
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Jest/RTL: Cover ImportRecord component with unit test. Refs UIIN-2667.
* Jest/RTL: Cover MoveHoldingContext component with unit tests. Refs UIIN-2664.
* Use consolidated locations endpoint to fetch all locations when in central tenant context. Refs UIIN-2811.
* Jest/RTL: Cover ModalContent components with unit tests. Refs UIIN-2669.

## [11.0.4](https://github.com/folio-org/ui-inventory/tree/v11.0.4) (2024-04-30)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v11.0.3...v11.0.4)
Expand Down
54 changes: 54 additions & 0 deletions src/components/ModalContent/ModalContent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { fireEvent } from '@folio/jest-config-stripes/testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import ModalContent from './ModalContent';
import { renderWithIntl } from '../../../test/jest/helpers';
import '../../../test/jest/__mock__';

const stripesMock = {
hasPerm: jest.fn().mockReturnValue(true),
};

const itemMock = {
title: 'Sample Title',
barcode: '123456789',
materialType: {
name: 'Book',
},
};

describe('ModalContent', () => {
it('renders with correct props and messages', () => {
const onCancelMock = jest.fn();
const onConfirmMock = jest.fn();
const requestsUrl = '/requests';
const itemRequestCount = 2;
const status = 'Available';

const { getByText, getByRole } = renderWithIntl(
<MemoryRouter>
<ModalContent
stripes={stripesMock}
item={itemMock}
status={status}
requestsUrl={requestsUrl}
onCancel={onCancelMock}
onConfirm={onConfirmMock}
itemRequestCount={itemRequestCount}
/>
</MemoryRouter>
);

expect(getByText(/confirmModal.message/)).toBeInTheDocument();
expect(getByText(/confirmModal.requestMessage/)).toBeInTheDocument();

const cancelButton = getByRole('button', { name: /cancel/i });
const confirmButton = getByRole('button', { name: /confirm/i });

fireEvent.click(cancelButton);
expect(onCancelMock).toHaveBeenCalledTimes(1);

fireEvent.click(confirmButton);
expect(onConfirmMock).toHaveBeenCalledTimes(1);
});
});

0 comments on commit bae2372

Please sign in to comment.