The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 45 lines 1.72 KB
Raw
1 import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2 import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3 import { useRef, useState } from "react";
4 import { expect, it, vi } from "vite-plus/test";
5
6 import { act, fakeTimers, render } from "../../../test/render";
7 import { useFocusComposerOnThreadOpen } from "./useFocusComposerOnThreadOpen";
8
9 function ThreadProbe(props: { threadId: string }) {
10 const composerRef = useRef<HTMLTextAreaElement>(null);
11 const [root, setRoot] = useState<HTMLDivElement | null>(null);
12 useFocusComposerOnThreadOpen(
13 scopeThreadRef(EnvironmentId.make("rename"), ThreadId.make(props.threadId)),
14 root,
15 true,
16 false,
17 () => composerRef.current?.focus(),
18 );
19 return (
20 <div ref={setRoot}>
21 <div data-sidebar-row="thread:beta">
22 <input aria-label="Thread title" />
23 </div>
24 <textarea aria-label="Message" ref={composerRef} />
25 </div>
26 );
27 }
28
29 // regression: #27195 double-clicking another thread's row lost its rename field to the composer
30 it("keeps the sidebar rename input when a double-click opens another thread", async () => {
31 // The first render schedules the frame.
32 using _frames = fakeTimers();
33 await using screen = await render(<ThreadProbe threadId="alpha" />, {
34 // A bare hook probe; nothing here navigates.
35 router: false,
36 });
37 await act(() => vi.advanceTimersToNextFrame());
38 await expect.element(screen.getByRole("textbox", { name: "Message" })).toHaveFocus();
39
40 const renameInput = screen.getByRole("textbox", { name: "Thread title" });
41 renameInput.element().focus();
42 await screen.rerender(<ThreadProbe threadId="beta" />);
43 await act(() => vi.advanceTimersToNextFrame());
44 await expect.element(renameInput).toHaveFocus();
45 });