|
|
@@ -6,6 +6,8 @@ import { Settings } from "#/services/settings";
|
|
|
import SettingsForm from "./SettingsForm";
|
|
|
|
|
|
const onModelChangeMock = vi.fn();
|
|
|
+const onCustomModelChangeMock = vi.fn();
|
|
|
+const onModelTypeChangeMock = vi.fn();
|
|
|
const onAgentChangeMock = vi.fn();
|
|
|
const onLanguageChangeMock = vi.fn();
|
|
|
const onAPIKeyChangeMock = vi.fn();
|
|
|
@@ -18,7 +20,9 @@ const renderSettingsForm = (settings?: Settings) => {
|
|
|
disabled={false}
|
|
|
settings={
|
|
|
settings || {
|
|
|
- LLM_MODEL: "model1",
|
|
|
+ LLM_MODEL: "gpt-4o",
|
|
|
+ CUSTOM_LLM_MODEL: "",
|
|
|
+ USING_CUSTOM_MODEL: false,
|
|
|
AGENT: "agent1",
|
|
|
LANGUAGE: "en",
|
|
|
LLM_API_KEY: "sk-...",
|
|
|
@@ -26,10 +30,12 @@ const renderSettingsForm = (settings?: Settings) => {
|
|
|
SECURITY_ANALYZER: "analyzer1",
|
|
|
}
|
|
|
}
|
|
|
- models={["model1", "model2", "model3"]}
|
|
|
+ models={["gpt-4o", "gpt-3.5-turbo", "azure/ada"]}
|
|
|
agents={["agent1", "agent2", "agent3"]}
|
|
|
securityAnalyzers={["analyzer1", "analyzer2", "analyzer3"]}
|
|
|
onModelChange={onModelChangeMock}
|
|
|
+ onCustomModelChange={onCustomModelChangeMock}
|
|
|
+ onModelTypeChange={onModelTypeChangeMock}
|
|
|
onAgentChange={onAgentChangeMock}
|
|
|
onLanguageChange={onLanguageChangeMock}
|
|
|
onAPIKeyChange={onAPIKeyChangeMock}
|
|
|
@@ -43,7 +49,8 @@ describe("SettingsForm", () => {
|
|
|
it("should display the first values in the array by default", () => {
|
|
|
renderSettingsForm();
|
|
|
|
|
|
- const modelInput = screen.getByRole("combobox", { name: "model" });
|
|
|
+ const providerInput = screen.getByRole("combobox", { name: "Provider" });
|
|
|
+ const modelInput = screen.getByRole("combobox", { name: "Model" });
|
|
|
const agentInput = screen.getByRole("combobox", { name: "agent" });
|
|
|
const languageInput = screen.getByRole("combobox", { name: "language" });
|
|
|
const apiKeyInput = screen.getByTestId("apikey");
|
|
|
@@ -52,7 +59,8 @@ describe("SettingsForm", () => {
|
|
|
name: "securityanalyzer",
|
|
|
});
|
|
|
|
|
|
- expect(modelInput).toHaveValue("model1");
|
|
|
+ expect(providerInput).toHaveValue("OpenAI");
|
|
|
+ expect(modelInput).toHaveValue("gpt-4o");
|
|
|
expect(agentInput).toHaveValue("agent1");
|
|
|
expect(languageInput).toHaveValue("English");
|
|
|
expect(apiKeyInput).toHaveValue("sk-...");
|
|
|
@@ -62,7 +70,9 @@ describe("SettingsForm", () => {
|
|
|
|
|
|
it("should display the existing values if they are present", () => {
|
|
|
renderSettingsForm({
|
|
|
- LLM_MODEL: "model2",
|
|
|
+ LLM_MODEL: "gpt-3.5-turbo",
|
|
|
+ CUSTOM_LLM_MODEL: "",
|
|
|
+ USING_CUSTOM_MODEL: false,
|
|
|
AGENT: "agent2",
|
|
|
LANGUAGE: "es",
|
|
|
LLM_API_KEY: "sk-...",
|
|
|
@@ -70,14 +80,16 @@ describe("SettingsForm", () => {
|
|
|
SECURITY_ANALYZER: "analyzer2",
|
|
|
});
|
|
|
|
|
|
- const modelInput = screen.getByRole("combobox", { name: "model" });
|
|
|
+ const providerInput = screen.getByRole("combobox", { name: "Provider" });
|
|
|
+ const modelInput = screen.getByRole("combobox", { name: "Model" });
|
|
|
const agentInput = screen.getByRole("combobox", { name: "agent" });
|
|
|
const languageInput = screen.getByRole("combobox", { name: "language" });
|
|
|
const securityAnalyzerInput = screen.getByRole("combobox", {
|
|
|
name: "securityanalyzer",
|
|
|
});
|
|
|
|
|
|
- expect(modelInput).toHaveValue("model2");
|
|
|
+ expect(providerInput).toHaveValue("OpenAI");
|
|
|
+ expect(modelInput).toHaveValue("gpt-3.5-turbo");
|
|
|
expect(agentInput).toHaveValue("agent2");
|
|
|
expect(languageInput).toHaveValue("Español");
|
|
|
expect(securityAnalyzerInput).toHaveValue("analyzer2");
|
|
|
@@ -87,18 +99,22 @@ describe("SettingsForm", () => {
|
|
|
renderWithProviders(
|
|
|
<SettingsForm
|
|
|
settings={{
|
|
|
- LLM_MODEL: "model1",
|
|
|
+ LLM_MODEL: "gpt-4o",
|
|
|
+ CUSTOM_LLM_MODEL: "",
|
|
|
+ USING_CUSTOM_MODEL: false,
|
|
|
AGENT: "agent1",
|
|
|
LANGUAGE: "en",
|
|
|
LLM_API_KEY: "sk-...",
|
|
|
CONFIRMATION_MODE: true,
|
|
|
SECURITY_ANALYZER: "analyzer1",
|
|
|
}}
|
|
|
- models={["model1", "model2", "model3"]}
|
|
|
+ models={["gpt-4o", "gpt-3.5-turbo", "azure/ada"]}
|
|
|
agents={["agent1", "agent2", "agent3"]}
|
|
|
securityAnalyzers={["analyzer1", "analyzer2", "analyzer3"]}
|
|
|
disabled
|
|
|
onModelChange={onModelChangeMock}
|
|
|
+ onCustomModelChange={onCustomModelChangeMock}
|
|
|
+ onModelTypeChange={onModelTypeChangeMock}
|
|
|
onAgentChange={onAgentChangeMock}
|
|
|
onLanguageChange={onLanguageChangeMock}
|
|
|
onAPIKeyChange={onAPIKeyChangeMock}
|
|
|
@@ -106,7 +122,9 @@ describe("SettingsForm", () => {
|
|
|
onSecurityAnalyzerChange={onSecurityAnalyzerChangeMock}
|
|
|
/>,
|
|
|
);
|
|
|
- const modelInput = screen.getByRole("combobox", { name: "model" });
|
|
|
+
|
|
|
+ const providerInput = screen.getByRole("combobox", { name: "Provider" });
|
|
|
+ const modelInput = screen.getByRole("combobox", { name: "Model" });
|
|
|
const agentInput = screen.getByRole("combobox", { name: "agent" });
|
|
|
const languageInput = screen.getByRole("combobox", { name: "language" });
|
|
|
const confirmationModeInput = screen.getByTestId("confirmationmode");
|
|
|
@@ -114,6 +132,7 @@ describe("SettingsForm", () => {
|
|
|
name: "securityanalyzer",
|
|
|
});
|
|
|
|
|
|
+ expect(providerInput).toBeDisabled();
|
|
|
expect(modelInput).toBeDisabled();
|
|
|
expect(agentInput).toBeDisabled();
|
|
|
expect(languageInput).toBeDisabled();
|
|
|
@@ -122,22 +141,6 @@ describe("SettingsForm", () => {
|
|
|
});
|
|
|
|
|
|
describe("onChange handlers", () => {
|
|
|
- it("should call the onModelChange handler when the model changes", async () => {
|
|
|
- renderSettingsForm();
|
|
|
-
|
|
|
- const modelInput = screen.getByRole("combobox", { name: "model" });
|
|
|
- await act(async () => {
|
|
|
- await userEvent.click(modelInput);
|
|
|
- });
|
|
|
-
|
|
|
- const model3 = screen.getByText("model3");
|
|
|
- await act(async () => {
|
|
|
- await userEvent.click(model3);
|
|
|
- });
|
|
|
-
|
|
|
- expect(onModelChangeMock).toHaveBeenCalledWith("model3");
|
|
|
- });
|
|
|
-
|
|
|
it("should call the onAgentChange handler when the agent changes", async () => {
|
|
|
const user = userEvent.setup();
|
|
|
renderSettingsForm();
|
|
|
@@ -182,4 +185,76 @@ describe("SettingsForm", () => {
|
|
|
expect(onAPIKeyChangeMock).toHaveBeenCalledWith("sk-...x");
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe("Setting a custom LLM model", () => {
|
|
|
+ it("should display the fetched models by default", () => {
|
|
|
+ renderSettingsForm();
|
|
|
+
|
|
|
+ const modelSelector = screen.getByTestId("model-selector");
|
|
|
+ expect(modelSelector).toBeInTheDocument();
|
|
|
+
|
|
|
+ const customModelInput = screen.queryByTestId("custom-model-input");
|
|
|
+ expect(customModelInput).not.toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should switch to the custom model input when the custom model toggle is clicked", async () => {
|
|
|
+ const user = userEvent.setup();
|
|
|
+ renderSettingsForm();
|
|
|
+
|
|
|
+ const customModelToggle = screen.getByTestId("custom-model-toggle");
|
|
|
+ await user.click(customModelToggle);
|
|
|
+
|
|
|
+ const modelSelector = screen.queryByTestId("model-selector");
|
|
|
+ expect(modelSelector).not.toBeInTheDocument();
|
|
|
+
|
|
|
+ const customModelInput = screen.getByTestId("custom-model-input");
|
|
|
+ expect(customModelInput).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should call the onCustomModelChange handler when the custom model input changes", async () => {
|
|
|
+ const user = userEvent.setup();
|
|
|
+ renderSettingsForm();
|
|
|
+
|
|
|
+ const customModelToggle = screen.getByTestId("custom-model-toggle");
|
|
|
+ await user.click(customModelToggle);
|
|
|
+
|
|
|
+ const customModelInput = screen.getByTestId("custom-model-input");
|
|
|
+ await userEvent.type(customModelInput, "my/custom-model");
|
|
|
+
|
|
|
+ expect(onCustomModelChangeMock).toHaveBeenCalledWith("my/custom-model");
|
|
|
+ expect(onModelTypeChangeMock).toHaveBeenCalledWith("custom");
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should have custom model switched if using custom model", () => {
|
|
|
+ renderWithProviders(
|
|
|
+ <SettingsForm
|
|
|
+ settings={{
|
|
|
+ LLM_MODEL: "gpt-4o",
|
|
|
+ CUSTOM_LLM_MODEL: "CUSTOM_MODEL",
|
|
|
+ USING_CUSTOM_MODEL: true,
|
|
|
+ AGENT: "agent1",
|
|
|
+ LANGUAGE: "en",
|
|
|
+ LLM_API_KEY: "sk-...",
|
|
|
+ CONFIRMATION_MODE: true,
|
|
|
+ SECURITY_ANALYZER: "analyzer1",
|
|
|
+ }}
|
|
|
+ models={["gpt-4o", "gpt-3.5-turbo", "azure/ada"]}
|
|
|
+ agents={["agent1", "agent2", "agent3"]}
|
|
|
+ securityAnalyzers={["analyzer1", "analyzer2", "analyzer3"]}
|
|
|
+ disabled
|
|
|
+ onModelChange={onModelChangeMock}
|
|
|
+ onCustomModelChange={onCustomModelChangeMock}
|
|
|
+ onModelTypeChange={onModelTypeChangeMock}
|
|
|
+ onAgentChange={onAgentChangeMock}
|
|
|
+ onLanguageChange={onLanguageChangeMock}
|
|
|
+ onAPIKeyChange={onAPIKeyChangeMock}
|
|
|
+ onConfirmationModeChange={onConfirmationModeChangeMock}
|
|
|
+ onSecurityAnalyzerChange={onSecurityAnalyzerChangeMock}
|
|
|
+ />,
|
|
|
+ );
|
|
|
+
|
|
|
+ const customModelToggle = screen.getByTestId("custom-model-toggle");
|
|
|
+ expect(customModelToggle).toHaveAttribute("aria-checked", "true");
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|