diff --git a/app/src/components/dialog/EditDialog.test.tsx b/app/src/components/dialog/EditDialog.test.tsx new file mode 100644 index 0000000000..453b2017ce --- /dev/null +++ b/app/src/components/dialog/EditDialog.test.tsx @@ -0,0 +1,68 @@ +import { render } from '@testing-library/react'; +import React from 'react'; +import EditDialog from 'components/dialog/EditDialog'; +import { useFormikContext } from 'formik'; +import { TextField } from '@material-ui/core'; +import yup from 'utils/YupSchema'; + +export interface ISampleFormikForm { + testField: string; +} + +export const SampleFormikFormInitialValues: ISampleFormikForm = { + testField: '' +}; + +export const SampleFormikFormYupSchema = yup.object().shape({ + testField: yup + .string() + .max(3000, 'Cannot exceed 3000 characters') + .required('You must provide a test field for the project') +}); + +const SampleFormikForm = () => { + const formikProps = useFormikContext(); + + const { values, handleChange, handleSubmit } = formikProps; + + return ( +
+ + + ); +}; + +describe('EditDialog', () => { + it('matches the snapshot with no error message', () => { + const { baseElement } = render( +
+ , + initialValues: SampleFormikFormInitialValues, + validationSchema: SampleFormikFormYupSchema + }} + onClose={() => jest.fn()} + onCancel={() => jest.fn()} + onSave={() => jest.fn()} + /> +
+ ); + + expect(baseElement).toMatchSnapshot(); + }); +}); diff --git a/app/src/components/dialog/EditDialog.tsx b/app/src/components/dialog/EditDialog.tsx new file mode 100644 index 0000000000..8f44725bb9 --- /dev/null +++ b/app/src/components/dialog/EditDialog.tsx @@ -0,0 +1,104 @@ +import { Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@material-ui/core'; +import React from 'react'; +import { Formik } from 'formik'; + +export interface IEditDialogComponentProps { + element: any; + initialValues: any; + validationSchema: any; +} + +export interface IEditDialogProps { + /** + * The dialog window title text. + * + * @type {string} + * @memberof IEditDialogProps + */ + dialogTitle: string; + /** + * The dialog window body text. + * + * @type {string} + * @memberof IEditDialogProps + */ + dialogText: string; + /** + * Set to `true` to open the dialog, `false` to close the dialog. + * + * @type {boolean} + * @memberof IEditDialogProps + */ + open: boolean; + + /** + * @type {IEditDialogComponentProps} + * @memberof IEditDialogProps + */ + component: IEditDialogComponentProps; + + /** + * Callback fired if the dialog is closed. + * + * @memberof IEditDialogProps + */ + onClose: () => void; + /** + * Callback fired if the 'No' button is clicked. + * + * @memberof IEditDialogProps + */ + onCancel: () => void; + /** + * Callback fired if the 'Yes' button is clicked. + * + * @memberof IEditDialogProps + */ + onSave: (values: any) => void; +} + +/** + * A dialog for displaying a component for editing purposes and giving the user the option to say + * `Yes`(Save) or `No`. + * + * @param {*} props + * @return {*} + */ +export const EditDialog: React.FC = (props) => { + return ( + + { + props.onSave(values); + }}> + {(formikProps) => ( + + {props.dialogTitle} + + {props?.component?.element} + {props.dialogText} + + + + + + + )} + + + ); +}; + +export default EditDialog; diff --git a/app/src/components/dialog/__snapshots__/EditDialog.test.tsx.snap b/app/src/components/dialog/__snapshots__/EditDialog.test.tsx.snap new file mode 100644 index 0000000000..ce018d9c1b --- /dev/null +++ b/app/src/components/dialog/__snapshots__/EditDialog.test.tsx.snap @@ -0,0 +1,159 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`EditDialog matches the snapshot with no error message 1`] = ` + +