zerobyte/app/client/modules/backups/components/__tests__/snapshot-file-browser.test.tsx
Nico 611640b32b
fix: split display path and query base path (#714)
* fix: split display path and query base path

#709

* test(frontend): shared render utils

* fix(file-tree): add missing path segments

* chore: bump Bun version

* fix: select kind for synthetic folders
2026-03-29 12:30:35 +02:00

60 lines
1.7 KiB
TypeScript

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 }) => <a href="/">{children}</a>,
}));
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(
<SnapshotFileBrowser
snapshot={fromAny({
short_id: "snap-1",
time: "2026-03-26T00:00:00.000Z",
paths: ["/mnt/project/subdir/a.txt", "/mnt/project/subdir/b.txt"],
})}
repositoryId="repo-1"
backupId="backup-1"
displayBasePath="/mnt"
/>,
);
await waitFor(() => {
expect(requests[0]).toBe("/mnt/project/subdir");
});
expect(await screen.findByRole("button", { name: "project" })).toBeTruthy();
});
});