@devries-cameron20 / t3code Mirror · read-only
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 21, 04:45 UTC

main
ts 44 lines 1.6 KB
Raw
1 import {
2 createMemoryHistory,
3 createRootRoute,
4 createRoute,
5 createRouter,
6 } from "@tanstack/react-router";
7 import { describe, expect, it } from "vite-plus/test";
8
9 import { Route as PullRequestsRoute } from "../../routes/_chat.pull-requests";
10
11 function matchedSearch(url: string) {
12 const root = createRootRoute();
13 const chat = createRoute({ getParentRoute: () => root, id: "_chat" });
14 const pullRequests = createRoute({
15 getParentRoute: () => chat,
16 path: "pull-requests",
17 validateSearch: PullRequestsRoute.options.validateSearch,
18 });
19 const router = createRouter({
20 routeTree: root.addChildren([chat.addChildren([pullRequests])]),
21 history: createMemoryHistory({ initialEntries: [url] }),
22 });
23 // useSearch reads matched-route search, which can differ from URL search.
24 return router.matchRoutes(router.latestLocation).at(-1)?.search as
25 | Record<string, unknown>
26 | undefined;
27 }
28
29 describe("pull requests route search", () => {
30 it("drops a q the URL parser turned into a number", () => {
31 expect(matchedSearch("/pull-requests?q=4089")?.q).toBeUndefined();
32 expect(matchedSearch("/pull-requests?q=true")?.q).toBeUndefined();
33 });
34
35 it("keeps a q that is text, including quoted digits", () => {
36 expect(matchedSearch("/pull-requests?q=fix")?.q).toBe("fix");
37 expect(matchedSearch("/pull-requests?q=%224089%22")?.q).toBe("4089");
38 });
39
40 it("drops an author or labels the URL parser turned into a number", () => {
41 expect(matchedSearch("/pull-requests?author=4089")?.author).toBeUndefined();
42 expect(matchedSearch("/pull-requests?labels=4089")?.labels).toBeUndefined();
43 });
44 });