CEC-425 Added Delete Verification Prompt (#198)

Co-authored-by: Alexander Andrews <aandrews@fiskerinc.com>
This commit is contained in:
Alexander Andrews
2022-09-20 09:40:28 -04:00
committed by GitHub
parent 9c7a2b4577
commit 618cc68196
22 changed files with 692 additions and 392 deletions

View File

@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Delete Confirmation Modal Should render 1`] = `
<div
aria-hidden="true"
>
<div />
</div>
`;

View File

@@ -0,0 +1,36 @@
import React from "react";
import PropTypes from "prop-types";
import {Dialog, DialogTitle, DialogContentText, Button, DialogActions, DialogContent} from '@material-ui/core';
const DeleteConfirmation = (props) => {
return (
<div>
<Dialog open={props.open}
onClose={props.close}>
<DialogTitle id="alert-dialog-title">
{"Delete Resource?"}
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{"Are you sure you want to delete: " + props.message}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={props.close}>Cancel</Button>
<Button variant="contained" color="secondary" onClick={() => { props.close(); props.deleteFunction()}} autoFocus>
Delete
</Button>
</DialogActions>
</Dialog>
</div>
)
}
DeleteConfirmation.propTypes={
open: PropTypes.bool.isRequired, // Boolean that determines if the modal should be open
close: PropTypes.func.isRequired, // Function that sets the open state to false i.e. () => setOpen(false)
message: PropTypes.any.isRequired, // What the user will see if being confirmed to be deleted
deleteFunction: PropTypes.func.isRequired, // Function that runs when user clicks delete
}
export default DeleteConfirmation;

View File

@@ -0,0 +1,20 @@
jest.mock("../Contexts/UserContext");
import React from "react";
import { render, cleanup } from "@testing-library/react";
import DeleteConfirmation from "./index";
import addSnapshotSerializer from "../../utils/snapshot";
describe("Delete Confirmation Modal", () => {
beforeAll(() => {
addSnapshotSerializer(expect);
});
it("Should render", () => {
const { container } = render(
<DeleteConfirmation open={true} close={()=>{}} message="Test Message" deleteFunction={()=>{}}/>
);
expect(container).toMatchSnapshot();
cleanup();
});
});