Skip to content

Commit

Permalink
6362 if "enter" is pressed then the page reloads. (#8507)
Browse files Browse the repository at this point in the history
* added fix

* added tests

* changed logic to prevent default removed previous prop logic
  • Loading branch information
arinkulshi-skylight authored Feb 19, 2025
1 parent 937be34 commit 11ba16f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frontend/src/app/SearchInput.test.tsx
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();
});
});
1 change: 1 addition & 0 deletions frontend/src/app/testQueue/addToQueue/AddToQueueSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const AddToQueueSearchBox = ({
return (
<React.Fragment>
<SearchInput
onSearchClick={(e) => e.preventDefault()}
onInputChange={onInputChange}
queryString={debounced}
disabled={!allowQuery}
Expand Down

0 comments on commit 11ba16f

Please sign in to comment.