diff --git a/apps/web/src/components/settings/TextGeneratorsSettings.browser.test.tsx b/apps/web/src/components/settings/TextGeneratorsSettings.browser.test.tsx index 7427f0d2bcdde..d4f68e467b77d 100644 --- a/apps/web/src/components/settings/TextGeneratorsSettings.browser.test.tsx +++ b/apps/web/src/components/settings/TextGeneratorsSettings.browser.test.tsx @@ -7,6 +7,12 @@ import "~/index.css"; import { act, render } from "../../../test/render"; import { TextGeneratorsSettings } from "./TextGeneratorsSettings"; +const checkTextGeneratorConfig = vi.hoisted(() => + vi.fn(async () => ({ + models: [{ id: "demo-model", name: "Demo model" }], + })), +); + vi.mock("../../hooks/useSettings", async (importOriginal) => ({ ...(await importOriginal()), useEnvironmentSettings: () => ({ @@ -25,6 +31,7 @@ vi.mock("../../hooks/useSettings", async (importOriginal) => ({ vi.mock("../../textGenerators", async (importOriginal) => ({ ...(await importOriginal()), + checkTextGeneratorConfig, useTextGeneratorModels: () => AsyncResult.success( Array.from({ length: 9 }, (_, index) => ({ id: `model-${index}`, name: `Model ${index}` })), @@ -74,3 +81,29 @@ it("clears the model search on Escape without closing the models dialog", async await userEvent.keyboard("{Escape}"); await expect.element(dialog).not.toBeInTheDocument(); }); + +it("submits step 1 of the text generator wizard on Enter when Connect is enabled", async () => { + checkTextGeneratorConfig.mockClear(); + await using _screen = await render( + , + ); + await userEvent.click(page.getByRole("button", { name: "Add generator" })); + await userEvent.click(page.getByRole("radio", { name: "Custom" })); + + const baseUrl = page.getByLabelText("Base URL"); + await expect.element(page.getByRole("button", { name: "Connect" })).toBeDisabled(); + await userEvent.click(baseUrl); + await userEvent.keyboard("{Enter}"); + expect(checkTextGeneratorConfig).not.toHaveBeenCalled(); + + await userEvent.type(baseUrl, "http://localhost:11434/v1{Enter}"); + expect(checkTextGeneratorConfig).toHaveBeenCalledOnce(); + await expect + .element(page.getByText(/localhost:11434 is connected and lists 1 model\./)) + .toBeVisible(); +}); diff --git a/apps/web/src/components/settings/TextGeneratorsSettings.tsx b/apps/web/src/components/settings/TextGeneratorsSettings.tsx index 90bc0be6b0a6c..8655c0718c07b 100644 --- a/apps/web/src/components/settings/TextGeneratorsSettings.tsx +++ b/apps/web/src/components/settings/TextGeneratorsSettings.tsx @@ -12,7 +12,7 @@ import { AsyncResult } from "effect/reactivity"; import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; import { CheckIcon, MoreVertical, PlusIcon, ServerIcon } from "lucide-react"; -import { useState } from "react"; +import { useId, useState } from "react"; import { msg, T, useGT, useMessages, Var } from "gt-react"; import { useEnvironmentSettings, useUpdateEnvironmentSettings } from "../../hooks/useSettings"; @@ -280,6 +280,7 @@ function TextGeneratorWizard({ }) { const messages = useMessages(); const gt = useGT(); + const formId = useId(); const existing = editing === "new" ? null : editing.config; const [step, setStep] = useState(0); const [preset, setPreset] = useState(TEXT_GENERATOR_PRESETS[0]!); @@ -366,6 +367,7 @@ function TextGeneratorWizard({ {step === 0 ? (
{ event.preventDefault(); @@ -516,7 +518,7 @@ function TextGeneratorWizard({ -