-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UITEN-281: Add Routing service point option with Confirm modal to Ser…
…vice point page(ECS only)
- Loading branch information
1 parent
d0f9fa0
commit 2f0c9e8
Showing
13 changed files
with
437 additions
and
116 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
54 changes: 54 additions & 0 deletions
54
src/settings/ServicePoints/ConfirmEcsRequestRoutingChangeModal.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 React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { | ||
Button, | ||
Modal, | ||
ModalFooter, | ||
} from '@folio/stripes/components'; | ||
|
||
const ConfirmEcsRequestRoutingChangeModal = ({ | ||
open, | ||
targetValue, | ||
onConfirm, | ||
onCancel, | ||
}) => { | ||
const footer = ( | ||
<ModalFooter> | ||
<Button | ||
data-testid="confirmButton" | ||
buttonStyle="primary" | ||
autoFocus | ||
onClick={onConfirm} | ||
> | ||
<FormattedMessage id="ui-tenant-settings.settings.modal.button.confirm" /> | ||
</Button> | ||
<Button | ||
data-testid="cancelButton" | ||
onClick={onCancel} | ||
> | ||
<FormattedMessage id="ui-tenant-settings.settings.modal.button.cancel" /> | ||
</Button> | ||
</ModalFooter> | ||
); | ||
|
||
return ( | ||
<Modal | ||
label={<FormattedMessage id="ui-tenant-settings.settings.confirmEcsRequestRoutingChangeModal.title" />} | ||
open={open} | ||
size="small" | ||
footer={footer} | ||
> | ||
<FormattedMessage id={`ui-tenant-settings.settings.confirmEcsRequestRoutingChangeModal.message${targetValue ? 'NoToYes' : 'YesToNo'}`} /> | ||
</Modal> | ||
); | ||
}; | ||
|
||
ConfirmEcsRequestRoutingChangeModal.propTypes = { | ||
open: PropTypes.bool.isRequired, | ||
targetValue: PropTypes.bool.isRequired, | ||
onConfirm: PropTypes.func.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ConfirmEcsRequestRoutingChangeModal; |
102 changes: 102 additions & 0 deletions
102
src/settings/ServicePoints/ConfirmEcsRequestRoutingChangeModal.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,102 @@ | ||
import { | ||
render, | ||
screen, | ||
fireEvent, | ||
} from '@testing-library/react'; | ||
|
||
import { runAxeTest } from '@folio/stripes-testing'; | ||
|
||
import ConfirmEcsRequestRoutingChangeModal from './ConfirmEcsRequestRoutingChangeModal'; | ||
|
||
const defaultProps = { | ||
open: true, | ||
targetValue: true, | ||
onConfirm: jest.fn(), | ||
onCancel: jest.fn(), | ||
}; | ||
const testIds = { | ||
confirmButton: 'confirmButton', | ||
cancelButton: 'cancelButton', | ||
}; | ||
const messageIds = { | ||
title: 'ui-tenant-settings.settings.confirmEcsRequestRoutingChangeModal.title', | ||
messageNoToYes: 'ui-tenant-settings.settings.confirmEcsRequestRoutingChangeModal.messageNoToYes', | ||
messageYesToNo: 'ui-tenant-settings.settings.confirmEcsRequestRoutingChangeModal.messageYesToNo', | ||
confirmButton: 'ui-tenant-settings.settings.modal.button.confirm', | ||
cancelButton: 'ui-tenant-settings.settings.modal.button.cancel', | ||
}; | ||
|
||
describe('ConfirmEcsRequestRoutingChangeModal', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
render( | ||
<ConfirmEcsRequestRoutingChangeModal {...defaultProps} /> | ||
); | ||
}); | ||
|
||
it('should render with no axe errors', async () => { | ||
await runAxeTest({ | ||
rootNode: document.body, | ||
}); | ||
}); | ||
|
||
it('should render title', () => { | ||
expect(screen.getByText(messageIds.title)).toBeVisible(); | ||
}); | ||
|
||
it('should render message', () => { | ||
expect(screen.getByText(messageIds.messageNoToYes)).toBeVisible(); | ||
}); | ||
|
||
describe('Alternative props', () => { | ||
const props = { | ||
...defaultProps, | ||
targetValue: false, | ||
}; | ||
|
||
beforeEach(() => { | ||
render( | ||
<ConfirmEcsRequestRoutingChangeModal {...props} /> | ||
); | ||
}); | ||
|
||
it('should render message', () => { | ||
expect(screen.getByText(messageIds.messageYesToNo)).toBeVisible(); | ||
}); | ||
}); | ||
|
||
describe('Confirm button', () => { | ||
it('should render confirm button', () => { | ||
expect(screen.getByTestId(testIds.confirmButton)).toBeVisible(); | ||
}); | ||
|
||
it('should render confirm button text', () => { | ||
expect(screen.getByText(messageIds.confirmButton)).toBeVisible(); | ||
}); | ||
|
||
it('should call onConfirm', () => { | ||
fireEvent.click(screen.getByTestId(testIds.confirmButton)); | ||
|
||
expect(defaultProps.onConfirm).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('Cancel button', () => { | ||
it('should render cancel button', () => { | ||
expect(screen.getByTestId(testIds.cancelButton)).toBeVisible(); | ||
}); | ||
|
||
it('should render cancel button text', () => { | ||
expect(screen.getByText(messageIds.cancelButton)).toBeVisible(); | ||
}); | ||
|
||
it('should call onCancel', () => { | ||
fireEvent.click(screen.getByTestId(testIds.cancelButton)); | ||
|
||
expect(defaultProps.onCancel).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
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
Oops, something went wrong.