-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c23fdb
commit 57e7673
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
lib/claiming/components/modals/DelayClaimsModal/DelayClaimsModal.test.js
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,65 @@ | ||
/* Developed collaboratively using AI (GitHub Copilot) */ | ||
|
||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import { dayjs } from '@folio/stripes/components'; | ||
|
||
import DelayClaimsModal from './DelayClaimsModal'; | ||
|
||
const FORMAT = 'MM/DD/YYYY'; | ||
const today = dayjs(); | ||
|
||
const defaultProps = { | ||
claimsCount: 1, | ||
onSubmit: jest.fn(() => console.log('')), | ||
message: 'Test message', | ||
onCancel: jest.fn(), | ||
open: true, | ||
}; | ||
|
||
const renderComponent = (props = {}) => render( | ||
<DelayClaimsModal | ||
{...defaultProps} | ||
{...props} | ||
/>, | ||
{ wrapper: MemoryRouter }, | ||
); | ||
|
||
describe('DelayClaimsModal', () => { | ||
it('should call onCancel when cancel button is clicked', async () => { | ||
renderComponent(); | ||
|
||
await userEvent.click(screen.getByText('stripes-acq-components.FormFooter.cancel')); | ||
|
||
expect(defaultProps.onCancel).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should validate "Delay to" field and call onSubmit when save button is clicked', async () => { | ||
renderComponent(); | ||
|
||
const saveBtn = screen.getByRole('button', { name: 'stripes-acq-components.FormFooter.save' }); | ||
|
||
/* Empty input */ | ||
await userEvent.click(saveBtn); | ||
|
||
expect(screen.getByText('stripes-acq-components.validation.required')).toBeInTheDocument(); | ||
|
||
/* Invalid date input */ | ||
await userEvent.type(screen.getByPlaceholderText(FORMAT), today.format(FORMAT)); | ||
await userEvent.click(saveBtn); | ||
|
||
expect(screen.getByText('stripes-acq-components.validation.dateAfter')).toBeInTheDocument(); | ||
|
||
/* Valid date */ | ||
await userEvent.clear(screen.getByPlaceholderText(FORMAT)); | ||
await userEvent.type(screen.getByPlaceholderText(FORMAT), dayjs().add(5, 'days').format(FORMAT)); | ||
await userEvent.click(saveBtn); | ||
|
||
expect(defaultProps.onSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
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,40 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { PIECE_STATUS } from '../../../constants'; | ||
import { usePiecesStatusBatchUpdate } from '../../../hooks'; | ||
import { useClaimsDelay } from './useClaimsDelay'; | ||
|
||
jest.mock('../../../hooks', () => ({ | ||
usePiecesStatusBatchUpdate: jest.fn(), | ||
})); | ||
|
||
const mockUpdatePiecesStatus = jest.fn(() => Promise.resolve()); | ||
|
||
describe('useClaimsDelay', () => { | ||
beforeEach(() => { | ||
usePiecesStatusBatchUpdate.mockReturnValue({ | ||
isLoading: false, | ||
updatePiecesStatus: mockUpdatePiecesStatus, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call updatePiecesStatus with correct parameters when delayClaims is called', async () => { | ||
const { result } = renderHook(() => useClaimsDelay()); | ||
const claimingInterval = 30; | ||
const pieceIds = ['piece1', 'piece2']; | ||
|
||
await result.current.delayClaims({ claimingInterval, pieceIds }); | ||
|
||
expect(mockUpdatePiecesStatus).toHaveBeenCalledWith({ | ||
data: { | ||
claimingInterval, | ||
pieceIds, | ||
receivingStatus: PIECE_STATUS.claimDelayed, | ||
}, | ||
}); | ||
}); | ||
}); |