From c4465dee8a0fbc2813a982a0f00193fa69e99d7a Mon Sep 17 00:00:00 2001 From: System233 Date: Mon, 17 Feb 2025 22:27:35 +0800 Subject: [PATCH] Revert "Make sure to blur fields when user hits Done in settings" This reverts commit 2caa320face244728530229f4a4a58b2e66f5493. --- .../src/components/settings/SettingsView.tsx | 8 +--- .../settings/__tests__/SettingsView.test.tsx | 47 +++++++++---------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index b866561adf..829df5258f 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -70,13 +70,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => { const [modelIdErrorMessage, setModelIdErrorMessage] = useState(undefined) const [commandInput, setCommandInput] = useState("") - const handleSubmit = async () => { - // Focus the active element's parent to trigger blur - document.activeElement?.parentElement?.focus() - - // Small delay to let blur events complete - await new Promise((resolve) => setTimeout(resolve, 50)) - + const handleSubmit = () => { const apiValidationResult = validateApiConfiguration(apiConfiguration) const modelIdValidationResult = validateModelId(apiConfiguration, glamaModels, openRouterModels) diff --git a/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx b/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx index e9242f7be6..3765432610 100644 --- a/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx +++ b/webview-ui/src/components/settings/__tests__/SettingsView.test.tsx @@ -1,4 +1,5 @@ -import { render, screen, fireEvent, waitFor } from "@testing-library/react" +import React from "react" +import { render, screen, fireEvent } from "@testing-library/react" import SettingsView from "../SettingsView" import { ExtensionStateContextProvider } from "../../../context/ExtensionStateContext" import { vscode } from "../../../utils/vscode" @@ -126,7 +127,7 @@ describe("SettingsView - Sound Settings", () => { expect(screen.queryByRole("slider", { name: /volume/i })).not.toBeInTheDocument() }) - it("toggles sound setting and sends message to VSCode", async () => { + it("toggles sound setting and sends message to VSCode", () => { renderSettingsView() const soundCheckbox = screen.getByRole("checkbox", { @@ -141,14 +142,12 @@ describe("SettingsView - Sound Settings", () => { const doneButton = screen.getByText("Done") fireEvent.click(doneButton) - await waitFor(() => { - expect(vscode.postMessage).toHaveBeenCalledWith( - expect.objectContaining({ - type: "soundEnabled", - bool: true, - }), - ) - }) + expect(vscode.postMessage).toHaveBeenCalledWith( + expect.objectContaining({ + type: "soundEnabled", + bool: true, + }), + ) }) it("shows volume slider when sound is enabled", () => { @@ -166,7 +165,7 @@ describe("SettingsView - Sound Settings", () => { expect(volumeSlider).toHaveValue("0.5") }) - it("updates volume and sends message to VSCode when slider changes", async () => { + it("updates volume and sends message to VSCode when slider changes", () => { renderSettingsView() // Enable sound @@ -184,11 +183,9 @@ describe("SettingsView - Sound Settings", () => { fireEvent.click(doneButton) // Verify message sent to VSCode - await waitFor(() => { - expect(vscode.postMessage).toHaveBeenCalledWith({ - type: "soundVolume", - value: 0.75, - }) + expect(vscode.postMessage).toHaveBeenCalledWith({ + type: "soundVolume", + value: 0.75, }) }) }) @@ -305,7 +302,7 @@ describe("SettingsView - Allowed Commands", () => { expect(commands).toHaveLength(1) }) - it("saves allowed commands when clicking Done", async () => { + it("saves allowed commands when clicking Done", () => { const { onDone } = renderSettingsView() // Enable always allow execute @@ -325,14 +322,12 @@ describe("SettingsView - Allowed Commands", () => { fireEvent.click(doneButton) // Verify VSCode messages were sent - await waitFor(() => { - expect(vscode.postMessage).toHaveBeenCalledWith( - expect.objectContaining({ - type: "allowedCommands", - commands: ["npm test"], - }), - ) - expect(onDone).toHaveBeenCalled() - }) + expect(vscode.postMessage).toHaveBeenCalledWith( + expect.objectContaining({ + type: "allowedCommands", + commands: ["npm test"], + }), + ) + expect(onDone).toHaveBeenCalled() }) })