|
| 1 | +import { |
| 2 | + createMemoryHistory, |
| 3 | + createRootRoute, |
| 4 | + createRoute, |
| 5 | + createRouter, |
| 6 | +} from "@tanstack/react-router"; |
1 | 7 | import { describe, expect, it } from "vite-plus/test"; |
2 | 8 | import { scopeThreadRef } from "@t3tools/client-runtime/environment"; |
3 | 9 | import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/threads"; |
@@ -25,6 +31,43 @@ describe("threadRoutes", () => { |
25 | 31 | expect(isThreadRoutePathname("/env-2/thread-1", ref)).toBe(false); |
26 | 32 | expect(isThreadRoutePathname("/draft/thread-1", ref)).toBe(false); |
27 | 33 | expect(isThreadRoutePathname("/env-1/thread-1/extra", ref)).toBe(false); |
| 34 | + |
| 35 | + const encodedRef = scopeThreadRef("env space" as never, ThreadId.make("mcp:example/part")); |
| 36 | + expect(isThreadRoutePathname("/env%20space/mcp%3Aexample%2Fpart", encodedRef)).toBe(true); |
| 37 | + expect(isThreadRoutePathname("/env%20space/mcp%3Aexample%2Fpart/", encodedRef)).toBe(true); |
| 38 | + expect(isThreadRoutePathname("/env%20space/mcp%3Aexample/part", encodedRef)).toBe(false); |
| 39 | + expect(isThreadRoutePathname("/env%20space/mcp%253Aexample%2Fpart", encodedRef)).toBe(false); |
| 40 | + expect(isThreadRoutePathname("/env%20space/mcp%ZZexample", encodedRef)).toBe(false); |
| 41 | + expect(isThreadRoutePathname("/env%20space/mcp%3Aexample%2Fpart/extra", encodedRef)).toBe( |
| 42 | + false, |
| 43 | + ); |
| 44 | + expect( |
| 45 | + isThreadRoutePathname( |
| 46 | + "/env-1/mcp%253Aexample", |
| 47 | + scopeThreadRef("env-1" as never, ThreadId.make("mcp%3Aexample")), |
| 48 | + ), |
| 49 | + ).toBe(true); |
| 50 | + }); |
| 51 | + |
| 52 | + it("matches encoded MCP thread IDs from router navigation", async () => { |
| 53 | + const root = createRootRoute(); |
| 54 | + const thread = createRoute({ getParentRoute: () => root, path: "$environmentId/$threadId" }); |
| 55 | + const newThread = createRoute({ getParentRoute: () => root, path: "new" }); |
| 56 | + const router = createRouter({ |
| 57 | + routeTree: root.addChildren([thread, newThread]), |
| 58 | + history: createMemoryHistory({ initialEntries: ["/new"] }), |
| 59 | + }); |
| 60 | + await router.load(); |
| 61 | + const ref = scopeThreadRef("local" as never, ThreadId.make("mcp:example")); |
| 62 | + await router.navigate({ |
| 63 | + to: "/$environmentId/$threadId", |
| 64 | + params: { environmentId: ref.environmentId, threadId: ref.threadId }, |
| 65 | + }); |
| 66 | + expect(router.state.location.pathname).toBe("/local/mcp%3Aexample"); |
| 67 | + expect(router.state.matches.at(-1)?.params).toEqual(ref); |
| 68 | + expect(isThreadRoutePathname(router.state.location.pathname, ref)).toBe(true); |
| 69 | + await router.navigate({ to: "/new" }); |
| 70 | + expect(isThreadRoutePathname(router.state.location.pathname, ref)).toBe(false); |
28 | 71 | }); |
29 | 72 |
|
30 | 73 | it("resolves the backing thread while a draft route is being promoted", () => { |
|
0 commit comments