-
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-2401: Reset BoundWithModal when modal is closed (#2174)
- Loading branch information
Showing
3 changed files
with
70 additions
and
3 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
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,62 @@ | ||
import React from 'react'; | ||
import { screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import '../../../test/jest/__mock__'; | ||
|
||
import { renderWithIntl, translationsProperties } from '../../../test/jest/helpers'; | ||
|
||
|
||
import BoundWithModal from './BoundWithModal'; | ||
|
||
const itemMock = { | ||
hrid: '12345', | ||
barcode: '67890', | ||
}; | ||
|
||
const onOkMock = jest.fn(); | ||
const onCloseMock = jest.fn(); | ||
|
||
const renderBoundWithModal = () => renderWithIntl( | ||
<BoundWithModal | ||
item={itemMock} | ||
open | ||
onClose={onCloseMock} | ||
onOk={onOkMock} | ||
/>, | ||
translationsProperties | ||
); | ||
|
||
describe('BoundWithModal', () => { | ||
beforeEach(() => { | ||
renderBoundWithModal(); | ||
}); | ||
|
||
it('renders without crashing', () => { | ||
expect(screen.getByTestId('bound-with-modal')).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays item details', () => { | ||
expect(screen.getByText(itemMock.hrid)).toBeInTheDocument(); | ||
expect(screen.getByText(itemMock.barcode)).toBeInTheDocument(); | ||
}); | ||
|
||
it('triggers onOk callback with input values when save button is clicked', () => { | ||
const inputs = screen.getAllByTestId('bound-with-modal-input'); | ||
|
||
// fill inputs with values | ||
inputs.forEach((input, i) => { | ||
userEvent.type(input, `Value ${i}`); | ||
}); | ||
|
||
userEvent.click(screen.getByTestId('bound-with-modal-save-button')); | ||
|
||
expect(onOkMock).toHaveBeenCalledWith(['Value 0', 'Value 1', 'Value 2', 'Value 3', 'Value 4', 'Value 5', 'Value 6']); | ||
}); | ||
|
||
it('triggers onClose callback when cancel button is clicked', () => { | ||
userEvent.click(screen.getByTestId('bound-with-modal-cancel-button')); | ||
|
||
expect(onCloseMock).toHaveBeenCalled(); | ||
}); | ||
}); |