Skip to content

Commit 26119a5

Browse files
committed
test(mobile): a voice draft keeps the keyboard down after dictation starts
1 parent bfd97e1 commit 26119a5

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

‎apps/mobile/src/features/threads/NewTaskDraftRouteScreen.test.tsx‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const harness = vi.hoisted(() => {
3535
reset: () => undefined,
3636
checkout: vi.fn(),
3737
draftProjectRefs: [] as unknown[],
38+
draftFocus: [] as Array<{ autoFocus?: boolean; takeDictation?: () => boolean }>,
3839
// Hook results stay stable across renders, as the real hooks' are. Only
3940
// main's screen reads these (see the main-comparison mocks below).
4041
layout: { deferThreadSelectionUntil: () => undefined },
@@ -59,8 +60,16 @@ vi.mock("./ThreadScreenHost", () => ({
5960
ThreadScreenFallback: ({ children }: { children: ReactNode }) => <>{children}</>,
6061
}));
6162
vi.mock("./NewTaskDraftScreen", () => ({
62-
NewTaskDraftScreen: (props: { initialProjectRef: { branch?: string | null } }) => {
63+
NewTaskDraftScreen: (props: {
64+
initialProjectRef: { branch?: string | null };
65+
autoFocusComposer?: boolean;
66+
takeDictationRequest?: () => boolean;
67+
}) => {
6368
harness.draftProjectRefs.push(props.initialProjectRef);
69+
harness.draftFocus.push({
70+
autoFocus: props.autoFocusComposer,
71+
takeDictation: props.takeDictationRequest,
72+
});
6473
return <p>draft on {props.initialProjectRef.branch}</p>;
6574
},
6675
}));
@@ -95,6 +104,7 @@ vi.mock("@react-navigation/native", () => ({
95104
}));
96105

97106
import { NewTaskDraftRouteScreen } from "./NewTaskDraftRouteScreen";
107+
import { requestNewTaskComposerFocus } from "./new-task-composer-focus";
98108

99109
const project = { environmentId: "env-1", id: "project-1", workspaceRoot: "/repo" };
100110
const connected: Snapshot["catalog"] = {
@@ -189,3 +199,29 @@ it("hands the draft screen the same project ref across re-renders", async () =>
189199
// one re-renders it with a second ref.
190200
expect(new Set(harness.draftProjectRefs).size).toBe(1);
191201
});
202+
203+
it("keeps the keyboard down after a voice shortcut starts dictating", async () => {
204+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
205+
harness.draftFocus.length = 0;
206+
harness.set({ projects: [project], catalog: connected });
207+
requestNewTaskComposerFocus("voice-request", "dictation");
208+
const draft = { environmentId: "env-1", projectId: "project-1", requestId: "voice-request" };
209+
harness.route = { key: "voice-route", name: "Thread", params: { draft } };
210+
211+
const container = document.createElement("div");
212+
const root = createRoot(container);
213+
using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
214+
act(() =>
215+
root.render(
216+
<NewTaskDraftRouteScreen
217+
route={{ key: "voice-route", name: "Thread", params: draft } as never}
218+
/>,
219+
),
220+
);
221+
await vi.waitFor(() => expect(harness.draftFocus.length).toBeGreaterThan(0));
222+
223+
// The composer takes the request once dictation starts; a later render must not focus the editor.
224+
expect(harness.draftFocus.at(-1)?.takeDictation?.()).toBe(true);
225+
act(() => harness.set({ projects: [{ ...project }], catalog: { ...connected } }));
226+
expect(harness.draftFocus.map((props) => props.autoFocus)).not.toContain(true);
227+
});

0 commit comments

Comments
 (0)