feat(frontend): NewSessionDialog reduced to question-only

Removes workspace/model/provider/thinking fields. Dialog now posts only { question } to createSession and calls onCreated on success.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 16:22:57 +02:00
co-authored by Claude Opus 4.8
parent fa0f878c97
commit 32d963b43d
2 changed files with 17 additions and 175 deletions
+16 -46
View File
@@ -17,52 +17,19 @@ function renderDialog() {
return { onCreated };
}
beforeEach(() => {
server.use(
http.get("http://localhost:8787/workspaces", () =>
HttpResponse.json([{ name: "default", file: "default.db" }]),
),
http.post("http://localhost:8787/sessions", () =>
HttpResponse.json({ id: "s1" }),
),
);
});
test("§9 degradation: empty models -> model field is a FREE-TEXT input, not a select", async () => {
server.use(
http.get("http://localhost:8787/models", () => HttpResponse.json({ models: [] })),
);
test("the form has only a question field (no workspace/model/provider/thinking)", async () => {
renderDialog();
await userEvent.click(screen.getByRole("button", { name: /nuova/i }));
// Free-text model input present; no model dropdown.
const freetext = await screen.findByTestId("model-freetext");
expect(freetext.tagName).toBe("INPUT");
// The only <select> in the dialog is the workspace one (id nsd-workspace).
expect(screen.queryByRole("combobox", { name: /modello/i })).not.toBeInTheDocument();
expect(await screen.findByLabelText(/domanda/i)).toBeInTheDocument();
expect(screen.queryByLabelText(/workspace/i)).not.toBeInTheDocument();
expect(screen.queryByLabelText(/modello/i)).not.toBeInTheDocument();
expect(screen.queryByLabelText(/provider/i)).not.toBeInTheDocument();
expect(screen.queryByLabelText(/thinking/i)).not.toBeInTheDocument();
});
test("§9: non-empty models -> model field is a dropdown (select), not free text", async () => {
server.use(
http.get("http://localhost:8787/models", () =>
HttpResponse.json({ models: [{ provider: "zai", id: "glm-5.2" }] }),
),
);
renderDialog();
await userEvent.click(screen.getByRole("button", { name: /nuova/i }));
// Model dropdown present; no free-text input.
const modelSelect = await screen.findByRole("combobox", { name: /modello/i });
expect(modelSelect.tagName).toBe("SELECT");
expect(screen.queryByTestId("model-freetext")).not.toBeInTheDocument();
// Option label combines provider/id.
expect(screen.getByRole("option", { name: "zai/glm-5.2" })).toBeInTheDocument();
});
test("submitting calls createSession with the expected body keys", async () => {
test("submitting posts only { question } and calls onCreated", async () => {
let body: unknown = null;
server.use(
http.get("http://localhost:8787/models", () => HttpResponse.json({ models: [] })),
http.post("http://localhost:8787/sessions", async ({ request }) => {
body = await request.json();
return HttpResponse.json({ id: "s1" });
@@ -70,13 +37,16 @@ test("submitting calls createSession with the expected body keys", async () => {
);
const { onCreated } = renderDialog();
await userEvent.click(screen.getByRole("button", { name: /nuova/i }));
const textarea = await screen.findByLabelText(/domanda/i);
await userEvent.type(textarea, "Quante vendite nel 2025?");
await userEvent.type(await screen.findByLabelText(/domanda/i), "Quante vendite nel 2025?");
await userEvent.click(screen.getByRole("button", { name: /^crea$/i }));
await waitFor(() => {
expect(body).toEqual({ workspace: "default", question: "Quante vendite nel 2025?" });
});
await waitFor(() => expect(body).toEqual({ question: "Quante vendite nel 2025?" }));
await waitFor(() => expect(onCreated).toHaveBeenCalledWith("s1"));
});
test("empty question shows a validation error and does not submit", async () => {
renderDialog();
await userEvent.click(screen.getByRole("button", { name: /nuova/i }));
await userEvent.click(screen.getByRole("button", { name: /^crea$/i }));
expect(await screen.findByRole("alert")).toHaveTextContent(/vuota/i);
});