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