-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIIN-2669: Jest/RTL: Cover ModalContent components with unit tests
- Loading branch information
1 parent
156cf5a
commit bae2372
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |