-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIU-2969: change user type confirmation modal (#2627)
* UIU-2969: change user type confirmation modal * tests: fix failing tests * tests: add test coverages * tests: improve test coverage * refactor code * update changelog file * reduce code's Cognitive Complexity
- Loading branch information
1 parent
3454583
commit 74c40df
Showing
8 changed files
with
174 additions
and
10 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
54 changes: 54 additions & 0 deletions
54
...omponents/EditSections/EditUserInfo/components/ChangeUserTypeModal/ChangeUserTypeModal.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,54 @@ | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { | ||
Button, | ||
Modal, | ||
ModalFooter, | ||
} from '@folio/stripes/components'; | ||
|
||
import { USER_TYPES } from '../../../../../constants'; | ||
|
||
const ChangeUserTypeModal = ({ onChange, initialUserType, open }) => { | ||
const userTypeModalFooter = ( | ||
<ModalFooter> | ||
<Button | ||
id="userType-modal-btn" | ||
onClick={() => onChange(USER_TYPES.PATRON)} | ||
> | ||
<FormattedMessage id="ui-users.information.change.userType.modal.confirm" /> | ||
</Button> | ||
<Button | ||
id="userType-modal-cancel-btn" | ||
onClick={() => onChange(initialUserType)} | ||
> | ||
<FormattedMessage id="ui-users.cancel" /> | ||
</Button> | ||
</ModalFooter> | ||
); | ||
|
||
return ( | ||
<Modal | ||
footer={userTypeModalFooter} | ||
id="userType_confirmation_modal" | ||
label={<FormattedMessage id="ui-users.information.change.userType.modal.label" />} | ||
open={open} | ||
> | ||
<div> | ||
<FormattedMessage id="ui-users.information.change.userType.modal.text" /> | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
ChangeUserTypeModal.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
initialUserType: PropTypes.string.isRequired, | ||
open: PropTypes.bool, | ||
}; | ||
|
||
ChangeUserTypeModal.defaultProps = { | ||
open: false, | ||
}; | ||
|
||
export default ChangeUserTypeModal; |
41 changes: 41 additions & 0 deletions
41
...ents/EditSections/EditUserInfo/components/ChangeUserTypeModal/ChangeUserTypeModal.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,41 @@ | ||
import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import { USER_TYPES } from '../../../../../constants'; | ||
import ChangeUserTypeModal from './ChangeUserTypeModal'; | ||
|
||
describe('ChangeUserTypeModal', () => { | ||
it('should cancel modal confirmation', async () => { | ||
const onChange = jest.fn(); | ||
render(<ChangeUserTypeModal | ||
open | ||
onChange={onChange} | ||
initialUserType={USER_TYPES.STAFF} | ||
/>); | ||
|
||
expect(screen.getByText('ui-users.information.change.userType.modal.label')).toBeInTheDocument(); | ||
|
||
const cancelButton = screen.getByText('ui-users.cancel'); | ||
|
||
await userEvent.click(cancelButton); | ||
expect(onChange).toHaveBeenCalledWith(USER_TYPES.STAFF); | ||
}); | ||
|
||
it('should confirm modal confirmation with `patron` user type', async () => { | ||
const onChange = jest.fn(); | ||
const initialUserType = USER_TYPES.STAFF; | ||
|
||
render(<ChangeUserTypeModal | ||
open | ||
onChange={onChange} | ||
initialUserType={initialUserType} | ||
/>); | ||
|
||
expect(screen.getByText('ui-users.information.change.userType.modal.label')).toBeInTheDocument(); | ||
|
||
const cancelButton = screen.getByText('ui-users.information.change.userType.modal.confirm'); | ||
|
||
await userEvent.click(cancelButton); | ||
expect(onChange).toHaveBeenCalledWith(USER_TYPES.PATRON); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
src/components/EditSections/EditUserInfo/components/ChangeUserTypeModal/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 { default } from './ChangeUserTypeModal'; |
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,2 +1,3 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export { default as ProfilePicture } from './ProfilePicture'; | ||
export { default as ChangeUserTypeModal } from './ChangeUserTypeModal'; |
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