feat(frontend): Zustand session store + applyEvent
This commit is contained in:
@@ -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();
|
||||
});
|
||||
Reference in New Issue
Block a user