-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove hidden commands from feedback (#4597)
Co-authored-by: Xingyao Wang <[email protected]> Co-authored-by: Xingyao Wang <[email protected]> Co-authored-by: Graham Neubig <[email protected]>
- Loading branch information
1 parent
ce6939f
commit e17f7b2
Showing
9 changed files
with
123 additions
and
255 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 |
---|---|---|
|
@@ -5,15 +5,14 @@ import { FeedbackForm } from "#/components/feedback-form"; | |
|
||
describe("FeedbackForm", () => { | ||
const user = userEvent.setup(); | ||
const onSubmitMock = vi.fn(); | ||
const onCloseMock = vi.fn(); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("should render correctly", () => { | ||
render(<FeedbackForm onSubmit={onSubmitMock} onClose={onCloseMock} />); | ||
render(<FeedbackForm polarity="positive" onClose={onCloseMock} />); | ||
|
||
screen.getByLabelText("Email"); | ||
screen.getByLabelText("Private"); | ||
|
@@ -24,7 +23,7 @@ describe("FeedbackForm", () => { | |
}); | ||
|
||
it("should switch between private and public permissions", async () => { | ||
render(<FeedbackForm onSubmit={onSubmitMock} onClose={onCloseMock} />); | ||
render(<FeedbackForm polarity="positive" onClose={onCloseMock} />); | ||
const privateRadio = screen.getByLabelText("Private"); | ||
const publicRadio = screen.getByLabelText("Public"); | ||
|
||
|
@@ -40,69 +39,11 @@ describe("FeedbackForm", () => { | |
expect(publicRadio).not.toBeChecked(); | ||
}); | ||
|
||
it("should call onSubmit when the form is submitted", async () => { | ||
render(<FeedbackForm onSubmit={onSubmitMock} onClose={onCloseMock} />); | ||
const email = screen.getByLabelText("Email"); | ||
|
||
await user.type(email, "[email protected]"); | ||
await user.click(screen.getByRole("button", { name: "Submit" })); | ||
|
||
expect(onSubmitMock).toHaveBeenCalledWith("private", "[email protected]"); // private is the default value | ||
}); | ||
|
||
it("should not call onSubmit when the email is invalid", async () => { | ||
render(<FeedbackForm onSubmit={onSubmitMock} onClose={onCloseMock} />); | ||
const email = screen.getByLabelText("Email"); | ||
const submitButton = screen.getByRole("button", { name: "Submit" }); | ||
|
||
await user.click(submitButton); | ||
|
||
expect(onSubmitMock).not.toHaveBeenCalled(); | ||
|
||
await user.type(email, "test"); | ||
await user.click(submitButton); | ||
|
||
expect(onSubmitMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should submit public permissions when the public radio is checked", async () => { | ||
render(<FeedbackForm onSubmit={onSubmitMock} onClose={onCloseMock} />); | ||
const email = screen.getByLabelText("Email"); | ||
const publicRadio = screen.getByLabelText("Public"); | ||
|
||
await user.type(email, "[email protected]"); | ||
await user.click(publicRadio); | ||
await user.click(screen.getByRole("button", { name: "Submit" })); | ||
|
||
expect(onSubmitMock).toHaveBeenCalledWith("public", "[email protected]"); | ||
}); | ||
|
||
it("should call onClose when the close button is clicked", async () => { | ||
render(<FeedbackForm onSubmit={onSubmitMock} onClose={onCloseMock} />); | ||
render(<FeedbackForm polarity="positive" onClose={onCloseMock} />); | ||
await user.click(screen.getByRole("button", { name: "Cancel" })); | ||
|
||
expect(onSubmitMock).not.toHaveBeenCalled(); | ||
expect(onCloseMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should disable the buttons if isSubmitting is true", () => { | ||
const { rerender } = render( | ||
<FeedbackForm onSubmit={onSubmitMock} onClose={onCloseMock} />, | ||
); | ||
const submitButton = screen.getByRole("button", { name: "Submit" }); | ||
const cancelButton = screen.getByRole("button", { name: "Cancel" }); | ||
|
||
expect(submitButton).not.toBeDisabled(); | ||
expect(cancelButton).not.toBeDisabled(); | ||
|
||
rerender( | ||
<FeedbackForm | ||
onSubmit={onSubmitMock} | ||
onClose={onCloseMock} | ||
isSubmitting | ||
/>, | ||
); | ||
expect(submitButton).toBeDisabled(); | ||
expect(cancelButton).toBeDisabled(); | ||
}); | ||
}); |
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.