ReviewActions re-org and adding ConfirmModals
This commit is contained in:
47
src/components/ConfirmModal.jsx
Normal file
47
src/components/ConfirmModal.jsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { AlertModal, ActionRow, Button } from '@edx/paragon';
|
||||
|
||||
export const ConfirmModal = ({
|
||||
title,
|
||||
isOpen,
|
||||
onCancel,
|
||||
cancelText,
|
||||
onConfirm,
|
||||
confirmText,
|
||||
content,
|
||||
}) => (
|
||||
<AlertModal
|
||||
className="confirm-modal"
|
||||
title={title}
|
||||
isOpen={isOpen}
|
||||
footerNode={(
|
||||
<ActionRow>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
onClick={onCancel}
|
||||
>
|
||||
{cancelText}
|
||||
</Button>
|
||||
<Button variant="primary" onClick={onConfirm}>{confirmText}</Button>
|
||||
</ActionRow>
|
||||
)}
|
||||
>
|
||||
<p>{content}</p>
|
||||
</AlertModal>
|
||||
);
|
||||
ConfirmModal.defaultProps = {
|
||||
isOpen: false,
|
||||
};
|
||||
ConfirmModal.propTypes = {
|
||||
isOpen: PropTypes.bool,
|
||||
title: PropTypes.string.isRequired,
|
||||
cancelText: PropTypes.string.isRequired,
|
||||
onCancel: PropTypes.func.isRequired,
|
||||
onConfirm: PropTypes.func.isRequired,
|
||||
confirmText: PropTypes.string.isRequired,
|
||||
content: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default ConfirmModal;
|
||||
27
src/components/ConfirmModal.test.jsx
Normal file
27
src/components/ConfirmModal.test.jsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { shallow } from 'enzyme';
|
||||
|
||||
import { ConfirmModal } from './ConfirmModal';
|
||||
|
||||
jest.mock('@edx/paragon', () => ({
|
||||
ActionRow: () => 'ActionRow',
|
||||
AlertModal: () => 'AlertModal',
|
||||
Button: () => 'Button',
|
||||
}));
|
||||
|
||||
describe('ConfirmModal', () => {
|
||||
const props = {
|
||||
isOpen: false,
|
||||
title: 'test-title',
|
||||
cancelText: 'test-cancel-text',
|
||||
confirmText: 'test-confirm-text',
|
||||
content: 'test-content',
|
||||
onCancel: jest.fn().mockName('this.props.onCancel'),
|
||||
onConfirm: jest.fn().mockName('this.props.onConfirm'),
|
||||
};
|
||||
test('snapshot: closed', () => {
|
||||
expect(shallow(<ConfirmModal {...props} />)).toMatchSnapshot();
|
||||
});
|
||||
test('snapshot: open', () => {
|
||||
expect(shallow(<ConfirmModal {...props} isOpen />)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
57
src/components/__snapshots__/ConfirmModal.test.jsx.snap
Normal file
57
src/components/__snapshots__/ConfirmModal.test.jsx.snap
Normal file
@@ -0,0 +1,57 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ConfirmModal snapshot: closed 1`] = `
|
||||
<AlertModal
|
||||
className="confirm-modal"
|
||||
footerNode={
|
||||
<ActionRow>
|
||||
<Button
|
||||
onClick={[MockFunction this.props.onCancel]}
|
||||
variant="tertiary"
|
||||
>
|
||||
test-cancel-text
|
||||
</Button>
|
||||
<Button
|
||||
onClick={[MockFunction this.props.onConfirm]}
|
||||
variant="primary"
|
||||
>
|
||||
test-confirm-text
|
||||
</Button>
|
||||
</ActionRow>
|
||||
}
|
||||
isOpen={false}
|
||||
title="test-title"
|
||||
>
|
||||
<p>
|
||||
test-content
|
||||
</p>
|
||||
</AlertModal>
|
||||
`;
|
||||
|
||||
exports[`ConfirmModal snapshot: open 1`] = `
|
||||
<AlertModal
|
||||
className="confirm-modal"
|
||||
footerNode={
|
||||
<ActionRow>
|
||||
<Button
|
||||
onClick={[MockFunction this.props.onCancel]}
|
||||
variant="tertiary"
|
||||
>
|
||||
test-cancel-text
|
||||
</Button>
|
||||
<Button
|
||||
onClick={[MockFunction this.props.onConfirm]}
|
||||
variant="primary"
|
||||
>
|
||||
test-confirm-text
|
||||
</Button>
|
||||
</ActionRow>
|
||||
}
|
||||
isOpen={true}
|
||||
title="test-title"
|
||||
>
|
||||
<p>
|
||||
test-content
|
||||
</p>
|
||||
</AlertModal>
|
||||
`;
|
||||
Reference in New Issue
Block a user