The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts"; |
| 2 | import type { ReactNode } from "react"; |
| 3 | import { expect, it, vi } from "vite-plus/test"; |
| 4 | import { userEvent } from "vite-plus/test/browser"; |
| 5 | |
| 6 | import { render } from "../../../test/render"; |
| 7 | import type { PendingUserInput } from "../../session-logic"; |
| 8 | import { Select, SelectTrigger } from "../ui/select"; |
| 9 | import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel"; |
| 10 | |
| 11 | const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") }; |
| 12 | |
| 13 | const prompt: PendingUserInput = { |
| 14 | requestId: RuntimeRequestId.make("question-shortcuts"), |
| 15 | createdAt: "2026-10-31T00:00:00.000Z", |
| 16 | dismissible: false, |
| 17 | responseCapability: "live", |
| 18 | questions: [ |
| 19 | { |
| 20 | id: "question", |
| 21 | header: "Rollout", |
| 22 | question: "How should this ship?", |
| 23 | options: [{ label: "Incremental", description: "One module at a time" }], |
| 24 | multiSelect: true, |
| 25 | }, |
| 26 | ], |
| 27 | }; |
| 28 | |
| 29 | it.each<{ focus: string; control: ReactNode; toggles: boolean }>([ |
| 30 | { focus: "a page button", control: <button type="button" aria-label="Focused" />, toggles: true }, |
| 31 | { |
| 32 | focus: "a dialog", |
| 33 | control: ( |
| 34 | <div role="dialog"> |
| 35 | <button type="button" aria-label="Focused" /> |
| 36 | </div> |
| 37 | ), |
| 38 | toggles: false, |
| 39 | }, |
| 40 | { |
| 41 | focus: "a popup", |
| 42 | control: ( |
| 43 | <div data-slot="menu-popup"> |
| 44 | <button type="button" aria-label="Focused" /> |
| 45 | </div> |
| 46 | ), |
| 47 | toggles: false, |
| 48 | }, |
| 49 | { |
| 50 | focus: "a menu", |
| 51 | control: ( |
| 52 | <div role="menu"> |
| 53 | <button type="button" role="menuitem" aria-label="Focused" /> |
| 54 | </div> |
| 55 | ), |
| 56 | toggles: false, |
| 57 | }, |
| 58 | { |
| 59 | focus: "a select", |
| 60 | control: ( |
| 61 | <select aria-label="Focused"> |
| 62 | <option>One</option> |
| 63 | </select> |
| 64 | ), |
| 65 | toggles: false, |
| 66 | }, |
| 67 | { |
| 68 | focus: "a closed select menu", |
| 69 | control: ( |
| 70 | <Select> |
| 71 | <SelectTrigger aria-label="Focused" /> |
| 72 | </Select> |
| 73 | ), |
| 74 | toggles: false, |
| 75 | }, |
| 76 | { |
| 77 | focus: "a device screen that takes the key", |
| 78 | control: ( |
| 79 | <div |
| 80 | role="application" |
| 81 | aria-label="Focused" |
| 82 | tabIndex={0} |
| 83 | onKeyDown={(event) => event.preventDefault()} |
| 84 | /> |
| 85 | ), |
| 86 | toggles: false, |
| 87 | }, |
| 88 | ])( |
| 89 | "digit shortcut with focus in $focus toggles an option: $toggles", |
| 90 | async ({ control, toggles }) => { |
| 91 | const onToggleOption = vi.fn(); |
| 92 | await using screen = await render( |
| 93 | <> |
| 94 | {control} |
| 95 | <ComposerPendingUserInputPanel |
| 96 | pendingUserInputs={[prompt]} |
| 97 | cwd={undefined} |
| 98 | threadRef={threadRef} |
| 99 | respondingRequestIds={[]} |
| 100 | answers={{}} |
| 101 | questionIndex={0} |
| 102 | onToggleOption={onToggleOption} |
| 103 | onAdvance={vi.fn()} |
| 104 | onDismiss={vi.fn()} |
| 105 | /> |
| 106 | </>, |
| 107 | ); |
| 108 | await expect.element(screen.getByText("Incremental")).toBeVisible(); |
| 109 | screen.getByLabelText("Focused").element().focus(); |
| 110 | |
| 111 | await userEvent.keyboard("1"); |
| 112 | |
| 113 | expect(onToggleOption.mock.calls).toEqual(toggles ? [["question", "Incremental"]] : []); |
| 114 | }, |
| 115 | ); |