feat(frontend): 4-zone shell + F1 loop end-to-end (MSW)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// frontend/src/shell/f1-loop.test.tsx
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { act } from "react";
|
||||
import { server } from "../test/msw";
|
||||
import { FakeEventSource } from "../test/fakeEventSource";
|
||||
import { App } from "../App";
|
||||
import { useSessionStore } from "../store/sessionStore";
|
||||
|
||||
beforeEach(() => {
|
||||
FakeEventSource.instances = [];
|
||||
(globalThis as any).EventSource = FakeEventSource;
|
||||
useSessionStore.getState().resetSession();
|
||||
});
|
||||
|
||||
test("F1: create session -> widget via SSE -> respond -> POST /response", async () => {
|
||||
let responded: any = null;
|
||||
server.use(
|
||||
http.post("http://localhost:8787/sessions", () => HttpResponse.json({ id: "s1" })),
|
||||
http.get("http://localhost:8787/sessions", () => HttpResponse.json([])),
|
||||
http.post("http://localhost:8787/sessions/s1/response", async ({ request }) => {
|
||||
responded = await request.json();
|
||||
return new HttpResponse(null, { status: 204 });
|
||||
}),
|
||||
);
|
||||
render(<App />);
|
||||
await userEvent.click(screen.getByRole("button", { name: /nuova/i })); // start a session (UI affordance)
|
||||
// simulate the backend emitting the F1 widget
|
||||
act(() =>
|
||||
FakeEventSource.instances[0].emit({
|
||||
type: "ui_request",
|
||||
ui_request: {
|
||||
id: "u1",
|
||||
widget: "select",
|
||||
title: "Disambigua",
|
||||
options: [{ id: "a", label: "interpretazione A" }],
|
||||
},
|
||||
})
|
||||
);
|
||||
await userEvent.click(await screen.findByRole("button", { name: /interpretazione A/ }));
|
||||
expect(responded).toEqual({ ui_response: { id: "u1", kind: "select", choices: ["a"] } });
|
||||
});
|
||||
Reference in New Issue
Block a user