Skip to content

Commit 1f9837d

Browse files
committed
test(web): verify displaced-answer notices with the real toast manager
1 parent a903856 commit 1f9837d

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@ vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
1515
default: (({ text }: { text: string }) => <p>{text}</p>) as never,
1616
}));
1717

18-
const toasts = vi.hoisted(() => ({ add: vi.fn() }));
19-
vi.mock(import("../ui/toast"), async (importOriginal) => {
20-
const actual = await importOriginal();
21-
return { ...actual, toastManager: { ...actual.toastManager, add: toasts.add } as never };
22-
});
23-
2418
import { act, fakeTimers, render } from "../../../test/render";
2519
import { useComposerDraftStore } from "../../composerDraftStore";
2620
import { makeThreadProjectionFixture } from "../../test-fixtures";
21+
import { toastManager } from "../ui/toast";
2722
import { usePendingThreadRequests } from "./usePendingThreadRequests";
2823

2924
const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
@@ -151,7 +146,7 @@ it("tells the user when an option click moves their typed answer into the hidden
151146
const environmentId = EnvironmentId.make("displaced-environment");
152147
const draftTarget = { environmentId, threadId: threadRef.threadId };
153148
const draftPrompt = () => useComposerDraftStore.getState().getComposerDraft(draftTarget)?.prompt;
154-
toasts.add.mockClear();
149+
using toast = vi.spyOn(toastManager, "add");
155150
await using _screen = await render(
156151
<PendingRequestsProbe
157152
environmentId={environmentId}
@@ -160,23 +155,27 @@ it("tells the user when an option click moves their typed answer into the hidden
160155
);
161156

162157
await act(() => requests.onSelectActivePendingUserInputOption("question-0", "Incremental"));
163-
expect(toasts.add).not.toHaveBeenCalled();
158+
expect(toast).not.toHaveBeenCalled();
164159

165160
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", "first try"));
166161
await act(() => requests.onSelectActivePendingUserInputOption("question-0", "Incremental"));
167162
expect(draftPrompt()).toBe("first try");
168-
expect(toasts.add).toHaveBeenCalledTimes(1);
169-
expect(toasts.add).toHaveBeenCalledWith(
170-
expect.objectContaining({ data: { threadRef: draftTarget } }),
163+
expect(toast).toHaveBeenCalledTimes(1);
164+
expect(toast).toHaveBeenCalledWith(
165+
expect.objectContaining({
166+
type: "info",
167+
title: "Your typed text was set aside",
168+
description: "It will be back in the composer once the question is answered.",
169+
data: { threadRef: draftTarget },
170+
}),
171171
);
172172

173-
// Typing again replaces the option as the answer; the moved text stays put and is not announced twice.
174173
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", "second try"));
175174
expect(draftPrompt()).toBe("first try");
176175
expect(requests.activePendingDraftAnswers["question-0"]).toMatchObject({
177176
customAnswer: "second try",
178177
});
179-
expect(toasts.add).toHaveBeenCalledTimes(1);
178+
expect(toast).toHaveBeenCalledTimes(1);
180179
});
181180

182181
it("isolates drafts by environment, thread and request and discards only resolved requests", async () => {

‎apps/web/src/components/chat/usePendingThreadRequests.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { threadEnvironment } from "../../state/threads";
4949
import { useAtomCommand } from "../../state/use-atom-command";
5050
import { useOrchestrationCommand } from "../../state/use-orchestration-command";
5151
import { toastManager } from "../ui/toast";
52+
5253
import type { ChatComposerHandle } from "./ChatComposer";
5354

5455
const EMPTY_PENDING_USER_INPUT_ANSWERS: Record<string, PendingUserInputDraftAnswer> = {};
@@ -402,7 +403,6 @@ export function usePendingThreadRequests(input: {
402403
const nextPrompt = carryDisplacedCustomAnswerIntoPrompt(currentPrompt, displacedAnswer);
403404
if (nextPrompt !== currentPrompt) {
404405
setComposerDraftPrompt(composerDraftTarget, nextPrompt);
405-
// The question owns the box, so the draft (thread or queued edit) is out of sight until it resolves.
406406
toastManager.add({
407407
type: "info",
408408
title: "Your typed text was set aside",

0 commit comments

Comments
 (0)