import { act, fireEvent, render, screen, waitFor, } from "@testing-library/react"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { DEFAULT_FILE_TREE_WIDTH, resetWorkspace, setFileTreeWidth, toggleWorkspace, useWorkspace, } from "../workspace"; import { Workspace } from "./Workspace"; vi.mock("../api", () => ({ listFiles: vi.fn().mockResolvedValue({ path: "/w", entries: [] }), readFile: vi.fn().mockResolvedValue({ path: "/w/x", content: "" }), writeFile: vi.fn().mockResolvedValue(undefined), rawFileUrl: (path: string) => `/api/raw?path=${encodeURIComponent(path)}`, })); // The real terminal drags xterm and a WebSocket along; a stub is enough here. vi.mock("./TerminalPane", () => ({ TerminalPane: () =>
, })); /** Waits for the (mocked) file listing to settle so React stays quiet. */ function treeLoaded() { return waitFor(() => expect(screen.queryByText("loading…")).toBeNull()); } describe("Workspace", () => { beforeEach(() => { localStorage.clear(); resetWorkspace(); toggleWorkspace(); }); it("applies the file tree width as a CSS custom property", async () => { render(