Open History to see the last commit
1import { useRef } from "react";
2import { expect, it, vi } from "vite-plus/test";
3
4import { act, fakeTimers, render } from "../../../test/render";
5import { useFocusComposerOnThreadOpen } from "./useFocusComposerOnThreadOpen";
6
7function ThreadProbe(props: { threadId: string }) {
8 const composerRef = useRef<HTMLTextAreaElement>(null);
9 useFocusComposerOnThreadOpen(props.threadId, true, () => composerRef.current?.focus());
10 return (
11 <>
12 <div data-sidebar-row="thread:beta">
13 <input aria-label="Thread title" />
14 </div>
15 <textarea aria-label="Message" ref={composerRef} />
16 </>
17 );
18}
19
20// regression: #27195 double-clicking another thread's row lost its rename field to the composer
21it("keeps the sidebar rename input when a double-click opens another thread", async () => {
22 // The first render schedules the frame.
23 using _frames = fakeTimers();
24 await using screen = await render(<ThreadProbe threadId="alpha" />, {
25 // A bare hook probe; nothing here navigates.
26 router: false,
27 });
28 await act(() => vi.advanceTimersToNextFrame());
29 await expect.element(screen.getByRole("textbox", { name: "Message" })).toHaveFocus();
30
31 const renameInput = screen.getByRole("textbox", { name: "Thread title" });
32 renameInput.element().focus();
33 await screen.rerender(<ThreadProbe threadId="beta" />);
34 await act(() => vi.advanceTimersToNextFrame());
35 await expect.element(renameInput).toHaveFocus();
36});