-
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.
Merge branch 'UISACQCOMP-236' of https://github.com/folio-org/stripes…
…-acq-components into UISACQCOMP-236
- Loading branch information
Showing
12 changed files
with
388 additions
and
6 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
* @folio-org/acquisitions-ui |
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
7 changes: 6 additions & 1 deletion
7
lib/claiming/components/FieldClaimingDate/FieldClaimingDate.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
48 changes: 48 additions & 0 deletions
48
lib/claiming/components/menu-items/DelayClaimActionMenuItem/DelayClaimActionMenuItem.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,48 @@ | ||
/* Developed collaboratively using AI (GitHub Copilot) */ | ||
|
||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { DelayClaimActionMenuItem } from './DelayClaimActionMenuItem'; | ||
|
||
const defaultProps = { | ||
onClick: jest.fn(), | ||
}; | ||
|
||
const renderComponent = (props = {}) => render( | ||
<DelayClaimActionMenuItem | ||
{...defaultProps} | ||
{...props} | ||
/>, | ||
); | ||
|
||
describe('DelayClaimActionMenuItem', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call onClick when button is clicked', async () => { | ||
renderComponent(); | ||
|
||
await userEvent.click(screen.getByTestId('delay-claim-button')); | ||
|
||
expect(defaultProps.onClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should be disabled when disabled prop is true', () => { | ||
renderComponent({ disabled: true }); | ||
|
||
expect(screen.getByTestId('delay-claim-button')).toBeDisabled(); | ||
}); | ||
|
||
it('should not call onClick when button is disabled and clicked', async () => { | ||
renderComponent({ disabled: true }); | ||
|
||
await userEvent.click(screen.getByTestId('delay-claim-button')); | ||
|
||
expect(defaultProps.onClick).not.toHaveBeenCalled(); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
...mponents/menu-items/MarkUnreceivableActionMenuItem/MarkUnreceivableActionMenuItem.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,53 @@ | ||
/* Developed collaboratively using AI (GitHub Copilot) */ | ||
|
||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { MarkUnreceivableActionMenuItem } from './MarkUnreceivableActionMenuItem'; | ||
|
||
const defaultProps = { | ||
onClick: jest.fn(), | ||
disabled: false, | ||
}; | ||
|
||
const renderComponent = (props = {}) => render( | ||
<MarkUnreceivableActionMenuItem | ||
{...defaultProps} | ||
{...props} | ||
/>, | ||
); | ||
|
||
describe('MarkUnreceivableActionMenuItem', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should render the button', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByTestId('unreceivable-button')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onClick when button is clicked', async () => { | ||
renderComponent(); | ||
|
||
await userEvent.click(screen.getByTestId('unreceivable-button')); | ||
|
||
expect(defaultProps.onClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should disable the button when disabled prop is true', () => { | ||
renderComponent({ disabled: true }); | ||
|
||
expect(screen.getByTestId('unreceivable-button')).toBeDisabled(); | ||
}); | ||
|
||
it('should enable the button when disabled prop is false', () => { | ||
renderComponent({ disabled: false }); | ||
|
||
expect(screen.getByTestId('unreceivable-button')).toBeEnabled(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
lib/claiming/components/menu-items/SendClaimActionMenuItem/SendClaimActionMenuItem.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,48 @@ | ||
/* Developed collaboratively using AI (GitHub Copilot) */ | ||
|
||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { SendClaimActionMenuItem } from './SendClaimActionMenuItem'; | ||
|
||
const defaultProps = { | ||
onClick: jest.fn(), | ||
}; | ||
|
||
const renderComponent = (props = {}) => render( | ||
<SendClaimActionMenuItem | ||
{...defaultProps} | ||
{...props} | ||
/>, | ||
); | ||
|
||
describe('SendClaimActionMenuItem', () => { | ||
it('should render the button', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByTestId('send-claim-button')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call onClick when button is clicked', async () => { | ||
renderComponent(); | ||
|
||
await userEvent.click(screen.getByTestId('send-claim-button')); | ||
|
||
expect(defaultProps.onClick).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should disable the button when disabled prop is true', () => { | ||
renderComponent({ disabled: true }); | ||
|
||
expect(screen.getByTestId('send-claim-button')).toBeDisabled(); | ||
}); | ||
|
||
it('should enable the button when disabled prop is false', () => { | ||
renderComponent({ disabled: false }); | ||
|
||
expect(screen.getByTestId('send-claim-button')).not.toBeDisabled(); | ||
}); | ||
}); |
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
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, | ||
}, | ||
}); | ||
}); | ||
}); |
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,59 @@ | ||
/* Developed collaboratively using AI (GitHub Copilot) */ | ||
|
||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { | ||
QueryClient, | ||
QueryClientProvider, | ||
} from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { SEND_CLAIMS_API } from '../../../constants'; | ||
import { useClaimsSend } from './useClaimsSend'; | ||
|
||
const queryClient = new QueryClient(); | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('useClaimsSend', () => { | ||
const kyPostMock = jest.fn(); | ||
|
||
beforeEach(() => { | ||
useOkapiKy.mockReturnValue({ | ||
post: kyPostMock, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call ky.post with correct arguments when sendClaims is called', async () => { | ||
const { result } = renderHook(() => useClaimsSend(), { wrapper }); | ||
const data = { claim: 'test' }; | ||
|
||
kyPostMock.mockReturnValue({ | ||
json: jest.fn().mockResolvedValue({}), | ||
}); | ||
|
||
await result.current.sendClaims({ data }); | ||
|
||
expect(kyPostMock).toHaveBeenCalledWith(SEND_CLAIMS_API, { json: data }); | ||
}); | ||
|
||
it('should handle errors when sendClaims is called', async () => { | ||
const { result } = renderHook(() => useClaimsSend(), { wrapper }); | ||
|
||
const data = { claim: 'test' }; | ||
const error = new Error('Failed to send claims'); | ||
|
||
kyPostMock.mockReturnValue({ | ||
json: jest.fn().mockRejectedValue(error), | ||
}); | ||
|
||
await expect(result.current.sendClaims({ data })).rejects.toThrow(error); | ||
}); | ||
}); |
Oops, something went wrong.