forked from Khan/perseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add confirmation before deleting a hint (Khan#896)
## Summary: Adds a simple confirmation before proceeding with the hint is deleted. This will hopefully prevent alot of frustration by avoiding losing work. Issue: LC-1591 ## Test plan: Author: jeremywiebe Reviewers: handeyeco, nixterrimus, jeremywiebe, SonicScrewdriver, nedredmond Required Reviewers: Approved By: handeyeco, nixterrimus Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage, ✅ gerald, ✅ Jest Coverage (ubuntu-latest, 20.x), ⏭ Publish npm snapshot, ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Extract i18n strings (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ gerald, ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x) Pull Request URL: Khan#896
- Loading branch information
1 parent
49d5c82
commit 0498106
Showing
3 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus-editor": minor | ||
--- | ||
|
||
Add a confirmation before deleting a hint in the Exercise Editor |
83 changes: 83 additions & 0 deletions
83
packages/perseus-editor/src/__tests__/hint-editor.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,83 @@ | ||
import "@testing-library/jest-dom"; | ||
import {render, screen} from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import * as React from "react"; | ||
|
||
import CombinedHintsEditor from "../hint-editor"; | ||
|
||
describe("CombinedHintsEditor", () => { | ||
it("should render", () => { | ||
render( | ||
<CombinedHintsEditor deviceType="phone" previewURL="about:blank" />, | ||
); | ||
}); | ||
|
||
it("should confirm before removing a hint", () => { | ||
// Arrange | ||
const comfirmSpy = jest.spyOn(window, "confirm").mockReturnValue(false); | ||
render( | ||
<CombinedHintsEditor | ||
deviceType="phone" | ||
previewURL="about:blank" | ||
hints={[ | ||
{content: "You know this one!", widgets: {}, images: {}}, | ||
{content: "Ok, the answer is 3", widgets: {}, images: {}}, | ||
]} | ||
/>, | ||
); | ||
|
||
// Act | ||
userEvent.click(screen.getAllByText("Remove this hint")[0]); | ||
|
||
// Assert | ||
expect(comfirmSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should not remove the hint if not confirmed", () => { | ||
// Arrange | ||
jest.spyOn(window, "confirm").mockReturnValue(false); | ||
const onChangeMock = jest.fn(); | ||
render( | ||
<CombinedHintsEditor | ||
deviceType="phone" | ||
previewURL="about:blank" | ||
hints={[ | ||
{content: "You know this one!", widgets: {}, images: {}}, | ||
{content: "Ok, the answer is 3", widgets: {}, images: {}}, | ||
]} | ||
onChange={onChangeMock} | ||
/>, | ||
); | ||
|
||
// Act | ||
userEvent.click(screen.getAllByText("Remove this hint")[0]); | ||
|
||
// Assert | ||
expect(onChangeMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should remove the hint if confirmed", () => { | ||
// Arrange | ||
jest.spyOn(window, "confirm").mockReturnValue(true); | ||
const onChangeMock = jest.fn(); | ||
render( | ||
<CombinedHintsEditor | ||
deviceType="phone" | ||
previewURL="about:blank" | ||
hints={[ | ||
{content: "You know this one!", widgets: {}, images: {}}, | ||
{content: "Ok, the answer is 3", widgets: {}, images: {}}, | ||
]} | ||
onChange={onChangeMock} | ||
/>, | ||
); | ||
|
||
// Act | ||
userEvent.click(screen.getAllByText("Remove this hint")[0]); | ||
|
||
// Assert | ||
expect(onChangeMock).toHaveBeenCalledWith({ | ||
hints: [{content: "Ok, the answer is 3", widgets: {}, images: {}}], | ||
}); | ||
}); | ||
}); |
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