feat(frontend): store lastUserEntry + stepMessages; record user input/choice

This commit is contained in:
2026-06-29 21:39:02 +02:00
parent 3a97ab3b2f
commit 068c6f197d
4 changed files with 45 additions and 3 deletions
+30 -2
View File
@@ -1,3 +1,4 @@
import { test, expect, beforeEach } from "vitest";
import { useSessionStore } from "./sessionStore";
beforeEach(() => useSessionStore.getState().resetSession());
@@ -14,9 +15,9 @@ test("text_delta accumulates into transcript", () => {
expect(useSessionStore.getState().transcript.at(-1)?.text).toBe("Analisi");
});
test("info pushes a toast", () => {
test("info appends to stepMessages", () => {
useSessionStore.getState().applyEvent({ type: "info", level: "warning", text: "attenzione" });
expect(useSessionStore.getState().toasts.at(-1)).toEqual({ level: "warning", text: "attenzione" });
expect(useSessionStore.getState().stepMessages.at(-1)).toEqual({ level: "warning", text: "attenzione" });
});
test("clearPending removes the widget", () => {
@@ -42,3 +43,30 @@ test("pushToast appends an error toast", () => {
useSessionStore.getState().pushToast({ level: "error", text: "boom" });
expect(useSessionStore.getState().toasts.at(-1)).toEqual({ level: "error", text: "boom" });
});
test("info events accumulate in stepMessages", () => {
const { applyEvent } = useSessionStore.getState();
applyEvent({ type: "info", level: "info", text: "found 3 tables" });
applyEvent({ type: "info", level: "warning", text: "ambiguous term" });
expect(useSessionStore.getState().stepMessages).toEqual([
{ level: "info", text: "found 3 tables" },
{ level: "warning", text: "ambiguous term" },
]);
});
test("setLastUserEntry records the entry and clears stepMessages", () => {
const st = useSessionStore.getState();
st.applyEvent({ type: "info", level: "info", text: "x" });
st.setLastUserEntry({ kind: "input", text: "my question" });
expect(useSessionStore.getState().lastUserEntry).toEqual({ kind: "input", text: "my question" });
expect(useSessionStore.getState().stepMessages).toEqual([]);
});
test("resetSession clears lastUserEntry and stepMessages", () => {
const st = useSessionStore.getState();
st.setLastUserEntry({ kind: "choice", text: "promote" });
st.applyEvent({ type: "info", level: "info", text: "y" });
st.resetSession();
expect(useSessionStore.getState().lastUserEntry).toBeNull();
expect(useSessionStore.getState().stepMessages).toEqual([]);
});