-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
6362 if "enter" is pressed then the page reloads. (#8507)
* added fix * added tests * changed logic to prevent default removed previous prop logic
- Loading branch information
1 parent
937be34
commit 11ba16f
Showing
2 changed files
with
35 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,34 @@ | ||
import React from "react"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
|
||
import SearchInput from "../app/testQueue/addToQueue/SearchInput"; | ||
|
||
describe("SearchInput", () => { | ||
const onInputChange = jest.fn(); | ||
|
||
it("calls onSearchClick and prevents default when onSearchClick calls e.preventDefault", () => { | ||
const preventDefaultSpy = jest.spyOn(Event.prototype, "preventDefault"); | ||
|
||
const onSearchClick = jest.fn((e) => { | ||
e.preventDefault(); | ||
}); | ||
|
||
render( | ||
<SearchInput | ||
onInputChange={onInputChange} | ||
onSearchClick={onSearchClick} | ||
queryString="" | ||
placeholder="Search..." | ||
showSubmitButton={true} | ||
/> | ||
); | ||
|
||
const button = screen.getByRole("button"); | ||
fireEvent.click(button); | ||
|
||
expect(onSearchClick).toHaveBeenCalled(); | ||
expect(preventDefaultSpy).toHaveBeenCalled(); | ||
|
||
preventDefaultSpy.mockRestore(); | ||
}); | ||
}); |
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