import type { ReactNode } from "react"; import { afterEach, describe, expect, mock, test } from "bun:test"; import { HttpResponse, http, server } from "~/test/msw/server"; import { cleanup, render, screen, waitFor } from "~/test/test-utils"; import { fromAny } from "@total-typescript/shoehorn"; await mock.module("@tanstack/react-router", () => ({ Link: ({ children }: { children?: ReactNode }) => {children}, })); await mock.module("~/client/lib/datetime", () => ({ useTimeFormat: () => ({ formatDateTime: () => "2026-03-26 00:00", }), })); import { SnapshotFileBrowser } from "../snapshot-file-browser"; afterEach(() => { cleanup(); }); describe("SnapshotFileBrowser", () => { test("uses the snapshot common ancestor as query root while keeping a broader display root", async () => { const requests: string[] = []; server.use( http.get("/api/v1/repositories/:shortId/snapshots/:snapshotId/files", ({ request }) => { const url = new URL(request.url); requests.push(url.searchParams.get("path") ?? ""); return HttpResponse.json({ files: [ { name: "subdir", path: "/mnt/project/subdir", type: "dir" }, { name: "a.txt", path: "/mnt/project/subdir/a.txt", type: "file" }, ], }); }), ); render( , ); await waitFor(() => { expect(requests[0]).toBe("/mnt/project/subdir"); }); expect(await screen.findByRole("button", { name: "project" })).toBeTruthy(); }); });