The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 33 lines 1.62 KB
Raw
1 import { FileTree } from "@pierre/trees";
2 import { expect, it, vi } from "vite-plus/test";
3 import { page, userEvent } from "vite-plus/test/browser";
4
5 import { render } from "../../../test/render";
6 import { DiffFileTree, type DiffFileTreeEntry } from "./DiffFileTree";
7
8 const FOLDERS = 300;
9
10 it("expands every folder without asking the tree about all folders for each one", async () => {
11 // Two levels, so flattening empty folders cannot merge them into one.
12 const entries: DiffFileTreeEntry[] = Array.from({ length: FOLDERS }, (_, index) => [
13 { path: `package-${index}/a.ts`, status: "modified" as const },
14 { path: `package-${index}/lib/b.ts`, status: "modified" as const },
15 ]).flat();
16 using getItem = vi.spyOn(FileTree.prototype, "getItem");
17 await using _screen = await render(
18 <div className="flex h-[600px] flex-col">
19 <DiffFileTree entries={entries} onSelectFile={() => {}} ariaLabel="Changed files" />
20 </div>,
21 );
22 const collapseAll = page.getByRole("button", { name: "Collapse all folders" });
23 await expect.element(collapseAll).toBeVisible();
24 await userEvent.click(collapseAll);
25 const expandAll = page.getByRole("button", { name: "Expand all folders" });
26 await expect.element(expandAll).toBeVisible();
27 getItem.mockClear();
28 await userEvent.click(expandAll);
29 await expect.element(page.getByRole("button", { name: "Collapse all folders" })).toBeVisible();
30 // Each of the expansions used to look up the folders again from the first one, so the lookups
31 // grew with the square of the folder count (hundreds of thousands at 600 folders).
32 expect(getItem.mock.calls.length).toBeLessThan(FOLDERS * 2 * 20);
33 });