From 11ba16fc77fce57f94c55656fdcba9eec01e5fd9 Mon Sep 17 00:00:00 2001
From: Arin Kulshi <158501719+arinkulshi-skylight@users.noreply.github.com>
Date: Wed, 19 Feb 2025 12:13:12 -0800
Subject: [PATCH] 6362 if "enter" is pressed then the page reloads. (#8507)
* added fix
* added tests
* changed logic to prevent default removed previous prop logic
---
frontend/src/app/SearchInput.test.tsx | 34 +++++++++++++++++++
.../testQueue/addToQueue/AddToQueueSearch.tsx | 1 +
2 files changed, 35 insertions(+)
create mode 100644 frontend/src/app/SearchInput.test.tsx
diff --git a/frontend/src/app/SearchInput.test.tsx b/frontend/src/app/SearchInput.test.tsx
new file mode 100644
index 0000000000..fcac5d3ddd
--- /dev/null
+++ b/frontend/src/app/SearchInput.test.tsx
@@ -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(
+
+ );
+
+ const button = screen.getByRole("button");
+ fireEvent.click(button);
+
+ expect(onSearchClick).toHaveBeenCalled();
+ expect(preventDefaultSpy).toHaveBeenCalled();
+
+ preventDefaultSpy.mockRestore();
+ });
+});
diff --git a/frontend/src/app/testQueue/addToQueue/AddToQueueSearch.tsx b/frontend/src/app/testQueue/addToQueue/AddToQueueSearch.tsx
index b5c7e4a8db..ad48649b43 100644
--- a/frontend/src/app/testQueue/addToQueue/AddToQueueSearch.tsx
+++ b/frontend/src/app/testQueue/addToQueue/AddToQueueSearch.tsx
@@ -175,6 +175,7 @@ const AddToQueueSearchBox = ({
return (
e.preventDefault()}
onInputChange={onInputChange}
queryString={debounced}
disabled={!allowQuery}