|
|
@@ -6,8 +6,6 @@ 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();
|
|
|
@@ -21,21 +19,17 @@ const renderSettingsForm = (settings?: Settings) => {
|
|
|
settings={
|
|
|
settings || {
|
|
|
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",
|
|
|
+ CONFIRMATION_MODE: false,
|
|
|
+ SECURITY_ANALYZER: "",
|
|
|
}
|
|
|
}
|
|
|
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}
|
|
|
@@ -49,50 +43,38 @@ describe("SettingsForm", () => {
|
|
|
it("should display the first values in the array by default", () => {
|
|
|
renderSettingsForm();
|
|
|
|
|
|
- const providerInput = screen.getByRole("combobox", { name: "Provider" });
|
|
|
- const modelInput = screen.getByRole("combobox", { name: "Model" });
|
|
|
- const agentInput = screen.getByRole("combobox", { name: "agent" });
|
|
|
+ const providerInput = screen.getByRole("combobox", {
|
|
|
+ name: "LLM Provider",
|
|
|
+ });
|
|
|
+ const modelInput = screen.getByRole("combobox", { name: "LLM Model" });
|
|
|
const languageInput = screen.getByRole("combobox", { name: "language" });
|
|
|
const apiKeyInput = screen.getByTestId("apikey");
|
|
|
- const confirmationModeInput = screen.getByTestId("confirmationmode");
|
|
|
- const securityAnalyzerInput = screen.getByRole("combobox", {
|
|
|
- name: "securityanalyzer",
|
|
|
- });
|
|
|
|
|
|
expect(providerInput).toHaveValue("OpenAI");
|
|
|
expect(modelInput).toHaveValue("gpt-4o");
|
|
|
- expect(agentInput).toHaveValue("agent1");
|
|
|
expect(languageInput).toHaveValue("English");
|
|
|
expect(apiKeyInput).toHaveValue("sk-...");
|
|
|
- expect(confirmationModeInput).toHaveAttribute("data-selected", "true");
|
|
|
- expect(securityAnalyzerInput).toHaveValue("analyzer1");
|
|
|
});
|
|
|
|
|
|
it("should display the existing values if they are present", () => {
|
|
|
renderSettingsForm({
|
|
|
LLM_MODEL: "gpt-3.5-turbo",
|
|
|
- CUSTOM_LLM_MODEL: "",
|
|
|
- USING_CUSTOM_MODEL: false,
|
|
|
AGENT: "agent2",
|
|
|
LANGUAGE: "es",
|
|
|
LLM_API_KEY: "sk-...",
|
|
|
- CONFIRMATION_MODE: true,
|
|
|
- SECURITY_ANALYZER: "analyzer2",
|
|
|
+ CONFIRMATION_MODE: false,
|
|
|
+ SECURITY_ANALYZER: "",
|
|
|
});
|
|
|
|
|
|
- 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",
|
|
|
+ const providerInput = screen.getByRole("combobox", {
|
|
|
+ name: "LLM Provider",
|
|
|
});
|
|
|
+ const modelInput = screen.getByRole("combobox", { name: "LLM Model" });
|
|
|
+ const languageInput = screen.getByRole("combobox", { name: "language" });
|
|
|
|
|
|
expect(providerInput).toHaveValue("OpenAI");
|
|
|
expect(modelInput).toHaveValue("gpt-3.5-turbo");
|
|
|
- expect(agentInput).toHaveValue("agent2");
|
|
|
expect(languageInput).toHaveValue("Español");
|
|
|
- expect(securityAnalyzerInput).toHaveValue("analyzer2");
|
|
|
});
|
|
|
|
|
|
it("should disable settings when disabled is true", () => {
|
|
|
@@ -100,21 +82,17 @@ describe("SettingsForm", () => {
|
|
|
<SettingsForm
|
|
|
settings={{
|
|
|
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",
|
|
|
+ CONFIRMATION_MODE: false,
|
|
|
+ SECURITY_ANALYZER: "",
|
|
|
}}
|
|
|
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}
|
|
|
@@ -123,21 +101,15 @@ describe("SettingsForm", () => {
|
|
|
/>,
|
|
|
);
|
|
|
|
|
|
- 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");
|
|
|
- const securityAnalyzerInput = screen.getByRole("combobox", {
|
|
|
- name: "securityanalyzer",
|
|
|
+ const providerInput = screen.getByRole("combobox", {
|
|
|
+ name: "LLM Provider",
|
|
|
});
|
|
|
+ const modelInput = screen.getByRole("combobox", { name: "LLM Model" });
|
|
|
+ const languageInput = screen.getByRole("combobox", { name: "language" });
|
|
|
|
|
|
expect(providerInput).toBeDisabled();
|
|
|
expect(modelInput).toBeDisabled();
|
|
|
- expect(agentInput).toBeDisabled();
|
|
|
expect(languageInput).toBeDisabled();
|
|
|
- expect(confirmationModeInput).toHaveAttribute("data-disabled", "true");
|
|
|
- expect(securityAnalyzerInput).toBeDisabled();
|
|
|
});
|
|
|
|
|
|
describe("onChange handlers", () => {
|
|
|
@@ -146,7 +118,7 @@ describe("SettingsForm", () => {
|
|
|
renderSettingsForm();
|
|
|
|
|
|
// We need to enable the agent select
|
|
|
- const agentSwitch = screen.getByTestId("enableagentselect");
|
|
|
+ const agentSwitch = screen.getByTestId("advanced-options-toggle");
|
|
|
await user.click(agentSwitch);
|
|
|
|
|
|
const agentInput = screen.getByRole("combobox", { name: "agent" });
|
|
|
@@ -201,8 +173,8 @@ describe("SettingsForm", () => {
|
|
|
const user = userEvent.setup();
|
|
|
renderSettingsForm();
|
|
|
|
|
|
- const customModelToggle = screen.getByTestId("custom-model-toggle");
|
|
|
- await user.click(customModelToggle);
|
|
|
+ const advancedToggle = screen.getByTestId("advanced-options-toggle");
|
|
|
+ await user.click(advancedToggle);
|
|
|
|
|
|
const modelSelector = screen.queryByTestId("model-selector");
|
|
|
expect(modelSelector).not.toBeInTheDocument();
|
|
|
@@ -215,23 +187,21 @@ describe("SettingsForm", () => {
|
|
|
const user = userEvent.setup();
|
|
|
renderSettingsForm();
|
|
|
|
|
|
- const customModelToggle = screen.getByTestId("custom-model-toggle");
|
|
|
- await user.click(customModelToggle);
|
|
|
+ const advancedToggle = screen.getByTestId("advanced-options-toggle");
|
|
|
+ await user.click(advancedToggle);
|
|
|
|
|
|
const customModelInput = screen.getByTestId("custom-model-input");
|
|
|
+ await userEvent.clear(customModelInput);
|
|
|
await userEvent.type(customModelInput, "my/custom-model");
|
|
|
|
|
|
- expect(onCustomModelChangeMock).toHaveBeenCalledWith("my/custom-model");
|
|
|
- expect(onModelTypeChangeMock).toHaveBeenCalledWith("custom");
|
|
|
+ expect(onModelChangeMock).toHaveBeenCalledWith("my/custom-model");
|
|
|
});
|
|
|
|
|
|
- it("should have custom model switched if using custom model", () => {
|
|
|
+ it("should have advanced options switched if using advanced options", () => {
|
|
|
renderWithProviders(
|
|
|
<SettingsForm
|
|
|
settings={{
|
|
|
LLM_MODEL: "gpt-4o",
|
|
|
- CUSTOM_LLM_MODEL: "CUSTOM_MODEL",
|
|
|
- USING_CUSTOM_MODEL: true,
|
|
|
AGENT: "agent1",
|
|
|
LANGUAGE: "en",
|
|
|
LLM_API_KEY: "sk-...",
|
|
|
@@ -243,8 +213,6 @@ describe("SettingsForm", () => {
|
|
|
securityAnalyzers={["analyzer1", "analyzer2", "analyzer3"]}
|
|
|
disabled
|
|
|
onModelChange={onModelChangeMock}
|
|
|
- onCustomModelChange={onCustomModelChangeMock}
|
|
|
- onModelTypeChange={onModelTypeChangeMock}
|
|
|
onAgentChange={onAgentChangeMock}
|
|
|
onLanguageChange={onLanguageChangeMock}
|
|
|
onAPIKeyChange={onAPIKeyChangeMock}
|
|
|
@@ -253,8 +221,8 @@ describe("SettingsForm", () => {
|
|
|
/>,
|
|
|
);
|
|
|
|
|
|
- const customModelToggle = screen.getByTestId("custom-model-toggle");
|
|
|
- expect(customModelToggle).toHaveAttribute("aria-checked", "true");
|
|
|
+ const advancedToggle = screen.getByTestId("advanced-options-toggle");
|
|
|
+ expect(advancedToggle).toHaveAttribute("aria-checked", "true");
|
|
|
});
|
|
|
});
|
|
|
});
|