feat(frontend): Zustand session store + applyEvent

This commit is contained in:
2026-06-28 12:17:16 +02:00
parent 913ac30137
commit ebd3988634
2 changed files with 70 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import { useSessionStore } from "./sessionStore";
beforeEach(() => useSessionStore.getState().resetSession());
test("ui_request sets pendingWidget", () => {
useSessionStore.getState().applyEvent({ type: "ui_request", ui_request: { id: "u1", widget: "select" } });
expect(useSessionStore.getState().pendingWidget?.id).toBe("u1");
});
test("text_delta accumulates into transcript", () => {
const s = useSessionStore.getState();
s.applyEvent({ type: "text_delta", text: "Ana" });
s.applyEvent({ type: "text_delta", text: "lisi" });
expect(useSessionStore.getState().transcript.at(-1)?.text).toBe("Analisi");
});
test("info pushes a toast", () => {
useSessionStore.getState().applyEvent({ type: "info", level: "warning", text: "attenzione" });
expect(useSessionStore.getState().toasts.at(-1)).toEqual({ level: "warning", text: "attenzione" });
});
test("clearPending removes the widget", () => {
useSessionStore.getState().applyEvent({ type: "ui_request", ui_request: { id: "u1", widget: "select" } });
useSessionStore.getState().clearPending();
expect(useSessionStore.getState().pendingWidget).toBeNull();
});