-
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.
Move reusable claiming code from ui-receiving to the shared library (#…
…841) * Move reusable claiming code from ui-receiving to the shared library * move send and delay claims modals to shared lib * add gutter for modal message * ignore empty records for all selected display * fix broken test * add unit tests * add tests * move GH related files to .github folder * update useRecordsSelect hook to add more functionality * reset forms on cancel * sonar warnings
- Loading branch information
1 parent
8b8428d
commit 76fa627
Showing
45 changed files
with
1,069 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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './FindRecords'; | ||
export { useRecordsSelect } from './hooks'; |
42 changes: 42 additions & 0 deletions
42
lib/claiming/components/FieldClaimingDate/FieldClaimingDate.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,42 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { FieldDatepickerFinal } from '../../../FieldDatepicker'; | ||
import { validateRequired } from '../../../utils'; | ||
import { | ||
excludePreviousDays, | ||
validateClaimingDate, | ||
} from './utils'; | ||
|
||
export const FieldClaimingDate = ({ | ||
name, | ||
required, | ||
...props | ||
}) => { | ||
const validate = (value) => { | ||
return ( | ||
(required && validateRequired(value)) | ||
|| validateClaimingDate(value) | ||
); | ||
}; | ||
|
||
return ( | ||
<FieldDatepickerFinal | ||
usePortal | ||
name={name} | ||
required={required} | ||
validate={validate} | ||
exclude={excludePreviousDays} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
FieldClaimingDate.propTypes = { | ||
name: PropTypes.string, | ||
required: PropTypes.bool, | ||
}; | ||
|
||
FieldClaimingDate.defaultProps = { | ||
name: 'claimingDate', | ||
required: true, | ||
}; |
38 changes: 38 additions & 0 deletions
38
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Developed collaboratively using AI (GitHub Copilot) */ | ||
|
||
import { | ||
render, | ||
screen, | ||
} from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
import stripesFinalForm from '@folio/stripes/final-form'; | ||
|
||
import { FieldClaimingDate } from './FieldClaimingDate'; | ||
|
||
const defaultProps = { | ||
label: 'Label', | ||
}; | ||
|
||
const FormComponent = stripesFinalForm({})(({ children }) => <form>{children}</form>); | ||
|
||
const renderFieldClaimingDate = (props = {}, formProps = {}) => render( | ||
<FormComponent | ||
onSubmit={jest.fn} | ||
{...formProps} | ||
> | ||
<FieldClaimingDate | ||
{...defaultProps} | ||
{...props} | ||
/> | ||
</FormComponent>, | ||
{ wrapper: MemoryRouter }, | ||
); | ||
|
||
describe('FieldClaimingDate', () => { | ||
it('should render field', () => { | ||
renderFieldClaimingDate(); | ||
|
||
expect(screen.getByText(defaultProps.label)).toBeInTheDocument(); | ||
}); | ||
}); |
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 @@ | ||
export { FieldClaimingDate } from './FieldClaimingDate'; |
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,19 @@ | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { dayjs } from '@folio/stripes/components'; | ||
|
||
const isSameOrBeforeDay = (day) => { | ||
const today = dayjs().startOf('day'); | ||
|
||
return day.isSameOrBefore(today, 'day'); | ||
}; | ||
|
||
export const validateClaimingDate = (value) => { | ||
return isSameOrBeforeDay(dayjs(value)) | ||
? <FormattedMessage id="stripes-acq-components.validation.dateAfter" /> | ||
: undefined; | ||
}; | ||
|
||
export const excludePreviousDays = (day) => { | ||
return isSameOrBeforeDay(day); | ||
}; |
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,2 @@ | ||
export * from './menu-items'; | ||
export * from './modals'; |
30 changes: 30 additions & 0 deletions
30
lib/claiming/components/menu-items/DelayClaimActionMenuItem/DelayClaimActionMenuItem.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,30 @@ | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { | ||
Button, | ||
Icon, | ||
} from '@folio/stripes/components'; | ||
|
||
export const DelayClaimActionMenuItem = ({ | ||
disabled, | ||
onClick, | ||
}) => { | ||
return ( | ||
<Button | ||
data-testid="delay-claim-button" | ||
disabled={disabled} | ||
buttonStyle="dropdownItem" | ||
onClick={onClick} | ||
> | ||
<Icon icon="calendar"> | ||
<FormattedMessage id="stripes-acq-components.claiming.action.delayClaim" /> | ||
</Icon> | ||
</Button> | ||
); | ||
}; | ||
|
||
DelayClaimActionMenuItem.propTypes = { | ||
disabled: PropTypes.bool, | ||
onClick: PropTypes.func.isRequired, | ||
}; |
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(); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
lib/claiming/components/menu-items/DelayClaimActionMenuItem/index.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 @@ | ||
export { DelayClaimActionMenuItem } from './DelayClaimActionMenuItem'; |
30 changes: 30 additions & 0 deletions
30
...ng/components/menu-items/MarkUnreceivableActionMenuItem/MarkUnreceivableActionMenuItem.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,30 @@ | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { | ||
Button, | ||
Icon, | ||
} from '@folio/stripes/components'; | ||
|
||
export const MarkUnreceivableActionMenuItem = ({ | ||
disabled, | ||
onClick, | ||
}) => { | ||
return ( | ||
<Button | ||
data-testid="unreceivable-button" | ||
disabled={disabled} | ||
buttonStyle="dropdownItem" | ||
onClick={onClick} | ||
> | ||
<Icon icon="cancel"> | ||
<FormattedMessage id="stripes-acq-components.claiming.action.unreceivable" /> | ||
</Icon> | ||
</Button> | ||
); | ||
}; | ||
|
||
MarkUnreceivableActionMenuItem.propTypes = { | ||
disabled: PropTypes.bool, | ||
onClick: PropTypes.func.isRequired, | ||
}; |
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(); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
lib/claiming/components/menu-items/MarkUnreceivableActionMenuItem/index.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 @@ | ||
export { MarkUnreceivableActionMenuItem } from './MarkUnreceivableActionMenuItem'; |
Oops, something went wrong.