| ... | ... | @@ -1,6 +1,14 @@ |
| 1 | 1 | import "../index.css"; |
| 2 | 2 | |
| 3 | 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"; |
| 4 | 12 | import { createRoot, type Root } from "react-dom/client"; |
| 5 | 13 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 6 | 14 | |
| ... | ... | @@ -10,7 +18,6 @@ import { estimateTimelineMessageHeight } from "./timelineHeight"; |
| 10 | 18 | |
| 11 | 19 | const mocks = vi.hoisted(() => { |
| 12 | 20 | return { |
| 13 | | navigate: vi.fn(), |
| 14 | 21 | markThreadVisited: vi.fn(), |
| 15 | 22 | setThreadError: vi.fn(), |
| 16 | 23 | setRuntimeMode: vi.fn(), |
| ... | ... | @@ -67,12 +74,6 @@ const mocks = vi.hoisted(() => { |
| 67 | 74 | }; |
| 68 | 75 | }); |
| 69 | 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 | | |
| 76 | 77 | vi.mock("@tanstack/react-query", async () => { |
| 77 | 78 | const actual = await vi.importActual<typeof import("@tanstack/react-query")>( |
| 78 | 79 | "@tanstack/react-query", |
| ... | ... | @@ -163,6 +164,24 @@ interface RenderMeasureOptions { |
| 163 | 164 | targetMessageId: MessageId; |
| 164 | 165 | } |
| 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 | |
| 166 | 185 | function createThread(messages: ChatMessage[]): Thread { |
| 167 | 186 | return { |
| 168 | 187 | id: THREAD_ID, |
| ... | ... | @@ -315,9 +334,10 @@ async function renderAndMeasureUserRow({ |
| 315 | 334 | document.body.append(host); |
| 316 | 335 | |
| 317 | 336 | mocks.storeState.threads = [createThread(messages)]; |
| 337 | const router = createTestRouter(THREAD_ID); |
| 318 | 338 | |
| 319 | 339 | const root: Root = createRoot(host); |
| 320 | | root.render(<ChatView threadId={THREAD_ID} />); |
| 340 | root.render(<RouterProvider router={router} />); |
| 321 | 341 | await waitForLayout(); |
| 322 | 342 | |
| 323 | 343 | const scrollContainer = host.querySelector("div.overflow-y-auto.overscroll-y-contain"); |