-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54d2134
commit 6d8ff61
Showing
121 changed files
with
2,769 additions
and
2,383 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
49 changes: 49 additions & 0 deletions
49
src/app/base/components/ModelDeleteForm/ModelDeleteForm.test.tsx
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,49 @@ | ||
import ModelDeleteForm from "./ModelDeleteForm"; | ||
|
||
import { renderWithBrowserRouter, screen, userEvent } from "testing/utils"; | ||
|
||
it("renders", () => { | ||
renderWithBrowserRouter( | ||
<ModelDeleteForm | ||
initialValues={{}} | ||
modelType="machine" | ||
onSubmit={jest.fn()} | ||
submitLabel="Delete" | ||
/> | ||
); | ||
expect( | ||
screen.getByText("Are you sure you want to delete this machine?") | ||
).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: "Delete" })).toBeInTheDocument(); | ||
}); | ||
|
||
it("can confirm", async () => { | ||
const onSubmit = jest.fn(); | ||
renderWithBrowserRouter( | ||
<ModelDeleteForm | ||
initialValues={{}} | ||
modelType="machine" | ||
onSubmit={onSubmit} | ||
submitLabel="Delete" | ||
/> | ||
); | ||
const submitBtn = screen.getByRole("button", { name: /delete/i }); | ||
await userEvent.click(submitBtn); | ||
expect(onSubmit).toHaveBeenCalled(); | ||
}); | ||
|
||
it("can cancel", async () => { | ||
const onCancel = jest.fn(); | ||
renderWithBrowserRouter( | ||
<ModelDeleteForm | ||
cancelLabel="Cancel" | ||
initialValues={{}} | ||
modelType="machine" | ||
onCancel={onCancel} | ||
onSubmit={jest.fn()} | ||
/> | ||
); | ||
const cancelBtn = screen.getByRole("button", { name: /cancel/i }); | ||
await userEvent.click(cancelBtn); | ||
expect(onCancel).toHaveBeenCalled(); | ||
}); |
43 changes: 43 additions & 0 deletions
43
src/app/base/components/ModelDeleteForm/ModelDeleteForm.tsx
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,43 @@ | ||
import { Col, Row } from "@canonical/react-components"; | ||
|
||
import type { Props as FormikFormProps } from "app/base/components/FormikForm/FormikForm"; | ||
import FormikForm from "app/base/components/FormikForm/FormikForm"; | ||
import type { EmptyObject } from "app/base/types"; | ||
|
||
type Props = { | ||
modelType: string; | ||
message?: string; | ||
} & FormikFormProps<EmptyObject>; | ||
|
||
const ModelDeleteForm = ({ | ||
modelType, | ||
message, | ||
submitAppearance = "negative", | ||
submitLabel = "Delete", | ||
initialValues = {}, | ||
...props | ||
}: Props) => { | ||
return ( | ||
<FormikForm | ||
initialValues={initialValues} | ||
submitAppearance={submitAppearance} | ||
submitLabel={submitLabel} | ||
{...props} | ||
> | ||
<Row> | ||
<Col size={12}> | ||
<p className="u-nudge-down--small"> | ||
{message | ||
? message | ||
: `Are you sure you want to delete this ${modelType}?`} | ||
</p> | ||
<span className="u-text--light"> | ||
This action is permanent and can not be undone. | ||
</span> | ||
</Col> | ||
</Row> | ||
</FormikForm> | ||
); | ||
}; | ||
|
||
export default ModelDeleteForm; |
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 "./ModelDeleteForm"; |
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
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.