-
Notifications
You must be signed in to change notification settings - Fork 936
feat: have user type name of thing to delete for extra safety #4080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
614fc86
Add info and text field to delete dialog
presleyp 0dc2717
Format
presleyp cf53085
Use DeleteDialog for Users, nix info except for Workspaces
presleyp d52354a
Format
presleyp a8a78f0
Update storybook
presleyp b8a6c53
Add and update tests
presleyp ce02bed
Merge branch 'main' into presleyp/destructive-dialog
presleyp 06e6e65
Fix the worst of the UsersPage test bugs
presleyp 2a85c53
Merge branch 'main' into presleyp/destructive-dialog
presleyp 0ac54d7
Fix users page tests
presleyp c787fbb
Fix workspace tests
presleyp b629274
Format
presleyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add and update tests
- Loading branch information
commit b8a6c53df62ab68f090fbc74e5a129dd84d22154
There are no files selected for viewing
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
site/src/components/Dialogs/DeleteDialog/DeleteDialog.test.tsx
This file contains hidden or 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,57 @@ | ||
import { screen } from "@testing-library/react" | ||
import userEvent from "@testing-library/user-event" | ||
import i18next from "i18next" | ||
import { render } from "testHelpers/renderHelpers" | ||
import { DeleteDialog } from "./DeleteDialog" | ||
|
||
describe("DeleteDialog", () => { | ||
it("disables confirm button when the text field is empty", () => { | ||
render( | ||
<DeleteDialog | ||
isOpen | ||
onConfirm={jest.fn()} | ||
onCancel={jest.fn()} | ||
entity="template" | ||
name="MyTemplate" | ||
/>, | ||
) | ||
const confirmButton = screen.getByRole("button", { name: "Delete" }) | ||
expect(confirmButton).toBeDisabled() | ||
}) | ||
|
||
it("disables confirm button when the text field is filled incorrectly", async () => { | ||
const { t } = i18next | ||
render( | ||
<DeleteDialog | ||
isOpen | ||
onConfirm={jest.fn()} | ||
onCancel={jest.fn()} | ||
entity="template" | ||
name="MyTemplate" | ||
/>, | ||
) | ||
const labelText = t("deleteDialog.confirmLabel", { ns: "common", entity: "template" }) | ||
const textField = screen.getByLabelText(labelText) | ||
await userEvent.type(textField, "MyTemplateWrong") | ||
const confirmButton = screen.getByRole("button", { name: "Delete" }) | ||
expect(confirmButton).toBeDisabled() | ||
}) | ||
|
||
it("enables confirm button when the text field is filled correctly", async () => { | ||
const { t } = i18next | ||
render( | ||
<DeleteDialog | ||
isOpen | ||
onConfirm={jest.fn()} | ||
onCancel={jest.fn()} | ||
entity="template" | ||
name="MyTemplate" | ||
/>, | ||
) | ||
const labelText = t("deleteDialog.confirmLabel", { ns: "common", entity: "template" }) | ||
const textField = screen.getByLabelText(labelText) | ||
await userEvent.type(textField, "MyTemplate") | ||
const confirmButton = screen.getByRole("button", { name: "Delete" }) | ||
expect(confirmButton).not.toBeDisabled() | ||
}) | ||
}) |
This file contains hidden or 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 |
---|---|---|
|
@@ -43,7 +43,14 @@ export const DeleteDialog: React.FC<React.PropsWithChildren<DeleteDialogProps>> | |
</Maybe> | ||
<Typography>{t("deleteDialog.confirm", { entity })}</Typography> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love how we're not passing whole strings in so that the language will stay consistent. |
||
<Stack spacing={1}> | ||
<TextField placeholder={name} value={nameValue} onChange={handleChange} /> | ||
<TextField | ||
name="confirmation" | ||
id="confirmation" | ||
placeholder={name} | ||
value={nameValue} | ||
onChange={handleChange} | ||
label={t("deleteDialog.confirmLabel", { entity })} | ||
/> | ||
<Maybe condition={nameValue.length > 0 && !confirmed}> | ||
<FormHelperText error>{t("deleteDialog.incorrectName", { entity })}</FormHelperText> | ||
</Maybe> | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️