mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
fix(frontend): prevent API key from resetting after modal change (#2329)
* remove bottom chatbox fade * Modal wider; fix lint error * settings: attempt to not clear api key for same provider * prevent api key from resetting after changing the model * revert other changes and fix post test tear down error --------- Co-authored-by: amanape <83104063+amanape@users.noreply.github.com>
This commit is contained in:
@@ -3,11 +3,11 @@ import userEvent from "@testing-library/user-event";
|
||||
import { act, render, fireEvent } from "@testing-library/react";
|
||||
import ChatInput from "./ChatInput";
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("ChatInput", () => {
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
const onSendMessage = vi.fn();
|
||||
|
||||
it("should render a textarea", () => {
|
||||
|
||||
@@ -26,6 +26,7 @@ vi.mock("#/services/settings", async (importOriginal) => ({
|
||||
LLM_MODEL: "gpt-4o",
|
||||
AGENT: "MonologueAgent",
|
||||
LANGUAGE: "en",
|
||||
LLM_API_KEY: "sk-...",
|
||||
}),
|
||||
getDefaultSettings: vi.fn().mockReturnValue({
|
||||
LLM_MODEL: "gpt-4o",
|
||||
@@ -139,7 +140,6 @@ describe("SettingsModal", () => {
|
||||
expect(saveSettings).toHaveBeenCalledWith({
|
||||
...initialSettings,
|
||||
LLM_MODEL: "model3",
|
||||
LLM_API_KEY: "", // reset after model change
|
||||
});
|
||||
});
|
||||
|
||||
@@ -196,7 +196,7 @@ describe("SettingsModal", () => {
|
||||
await userEvent.click(saveButton);
|
||||
});
|
||||
|
||||
expect(toastSpy).toHaveBeenCalledTimes(2);
|
||||
expect(toastSpy).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it("should change the language", async () => {
|
||||
|
||||
@@ -66,12 +66,9 @@ function SettingsModal({ isOpen, onOpenChange }: SettingsProps) {
|
||||
}, []);
|
||||
|
||||
const handleModelChange = (model: string) => {
|
||||
// Needs to also reset the API key.
|
||||
const key = localStorage.getItem(`API_KEY_${model}`);
|
||||
setSettings((prev) => ({
|
||||
...prev,
|
||||
LLM_MODEL: model,
|
||||
LLM_API_KEY: key || "",
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user