fix: surface reviewer response failures
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { act, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { http, HttpResponse } from "msw";
|
||||
import { server } from "../test/msw";
|
||||
import { useSessionStore } from "../store/sessionStore";
|
||||
import { WidgetHost } from "./WidgetHost";
|
||||
|
||||
beforeEach(() => useSessionStore.getState().resetSession());
|
||||
|
||||
test("a gate choice shows progress, prevents duplicate clicks, and confirms delivery", async () => {
|
||||
let release!: () => void;
|
||||
const held = new Promise<void>((resolve) => { release = resolve; });
|
||||
let requests = 0;
|
||||
server.use(http.post("/api/sessions/s1/response", async () => {
|
||||
requests += 1;
|
||||
await held;
|
||||
return new HttpResponse(null, { status: 204 });
|
||||
}));
|
||||
useSessionStore.setState({
|
||||
pendingWidget: {
|
||||
id: "gate-1",
|
||||
widget: "select",
|
||||
options: [{ id: "recommended", label: "Recommended answer" }],
|
||||
},
|
||||
});
|
||||
|
||||
const user = userEvent.setup();
|
||||
render(<WidgetHost sessionId="s1" />);
|
||||
const choice = screen.getByRole("button", { name: "Recommended answer" });
|
||||
await user.click(choice);
|
||||
|
||||
expect(screen.getByRole("status")).toHaveTextContent("Sending response");
|
||||
expect(choice).toBeDisabled();
|
||||
await user.click(choice);
|
||||
expect(requests).toBe(1);
|
||||
|
||||
act(() => release());
|
||||
await waitFor(() => expect(useSessionStore.getState().pendingWidget).toBeNull());
|
||||
expect(useSessionStore.getState().toasts.at(-1)).toEqual({
|
||||
level: "success",
|
||||
text: "Response sent. The model is continuing.",
|
||||
});
|
||||
|
||||
act(() => useSessionStore.setState({
|
||||
pendingWidget: {
|
||||
id: "gate-2",
|
||||
widget: "select",
|
||||
options: [{ id: "next", label: "Next answer" }],
|
||||
},
|
||||
}));
|
||||
expect(screen.getByRole("button", { name: "Next answer" })).toBeEnabled();
|
||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||
});
|
||||
Reference in New Issue
Block a user