@devries-cameron20 / t3code Mirror · read-only / commits / 2d8ca48175
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 25, 10:00 UTC

Use real TanStack router in ChatView browser tests

- Replace mocked router hooks with a memory router + RouterProvider - Render ChatView through a test route to exercise attachment height layout in realistic routing context

Julius Marminge committed Mar 4, 2026 at 13:00 UTC 2d8ca4817593c2fda1ce0b16849fc9920591538f
1 file changed +28 -8
apps/web/src/components/ChatView.browser.tsx
+28 -8
@@ -1,6 +1,14 @@
1 import "../index.css";
2
3 import { type MessageId, type ThreadId } from "@t3tools/contracts";
4 +import {
5 + Outlet,
6 + RouterProvider,
7 + createMemoryHistory,
8 + createRootRoute,
9 + createRoute,
10 + createRouter,
11 +} from "@tanstack/react-router";
12 import { createRoot, type Root } from "react-dom/client";
13 import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
14
@@ -10,7 +18,6 @@ import { estimateTimelineMessageHeight } from "./timelineHeight";
18
19 const mocks = vi.hoisted(() => {
20 return {
13 - navigate: vi.fn(),
21 markThreadVisited: vi.fn(),
22 setThreadError: vi.fn(),
23 setRuntimeMode: vi.fn(),
@@ -67,12 +74,6 @@ const mocks = vi.hoisted(() => {
74 };
75 });
76
70 -vi.mock("@tanstack/react-router", () => ({
71 - useNavigate: () => mocks.navigate,
72 - useSearch: (options?: { select?: (params: Record<string, unknown>) => unknown }) =>
73 - options?.select ? options.select({}) : {},
74 -}));
75 -
77 vi.mock("@tanstack/react-query", async () => {
78 const actual = await vi.importActual<typeof import("@tanstack/react-query")>(
79 "@tanstack/react-query",
@@ -163,6 +164,24 @@ interface RenderMeasureOptions {
164 targetMessageId: MessageId;
165 }
166
167 +function createTestRouter(threadId: ThreadId) {
168 + const rootRoute = createRootRoute({
169 + component: () => <Outlet />,
170 + });
171 + const threadRoute = createRoute({
172 + getParentRoute: () => rootRoute,
173 + path: "/$threadId",
174 + component: () => <ChatView threadId={threadId} />,
175 + });
176 + return createRouter({
177 + routeTree: rootRoute.addChildren([threadRoute]),
178 + history: createMemoryHistory({
179 + initialEntries: [`/${threadId}`],
180 + }),
181 + context: {},
182 + });
183 +}
184 +
185 function createThread(messages: ChatMessage[]): Thread {
186 return {
187 id: THREAD_ID,
@@ -315,9 +334,10 @@ async function renderAndMeasureUserRow({
334 document.body.append(host);
335
336 mocks.storeState.threads = [createThread(messages)];
337 + const router = createTestRouter(THREAD_ID);
338
339 const root: Root = createRoot(host);
320 - root.render(<ChatView threadId={THREAD_ID} />);
340 + root.render(<RouterProvider router={router} />);
341 await waitForLayout();
342
343 const scrollContainer = host.querySelector("div.overflow-y-auto.overscroll-y-contain");