Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3
4import { buildThreadFilesNavigation, buildThreadFilesRoutePath } from "./routes";
5
6const thread = {
7 environmentId: EnvironmentId.make("environment-1"),
8 threadId: ThreadId.make("thread-1"),
9};
10
11describe("thread file routes", () => {
12 it("includes an optional source line in string routes", () => {
13 expect(buildThreadFilesRoutePath(thread, "src/main.ts", 42)).toBe(
14 "/threads/environment-1/thread-1/files/src/main.ts?line=42",
15 );
16 });
17
18 it("encodes each file path segment without encoding separators", () => {
19 expect(buildThreadFilesRoutePath(thread, "docs/My File#1.md")).toBe(
20 "/threads/environment-1/thread-1/files/docs/My%20File%231.md",
21 );
22 });
23
24 it("builds typed navigation params for a file and source line", () => {
25 expect(buildThreadFilesNavigation(thread, "src/main.ts", 42)).toEqual({
26 pathname: "/threads/[environmentId]/[threadId]/files/[...path]",
27 params: {
28 environmentId: "environment-1",
29 threadId: "thread-1",
30 path: ["src", "main.ts"],
31 line: "42",
32 },
33 });
34 });
35
36 it("targets the files index when no file path is provided", () => {
37 expect(buildThreadFilesNavigation(thread)).toEqual({
38 pathname: "/threads/[environmentId]/[threadId]/files",
39 params: {
40 environmentId: "environment-1",
41 threadId: "thread-1",
42 },
43 });
44 });
45});