feat: add file edit diff progress view
Capture file edit snapshots through runner tool lifecycle hooks and render unified diffs in the WebUI with folding and truncation controls.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { FilePreviewPanel } from "@/components/FilePreviewPanel";
|
||||
import { fetchFilePreview } from "@/lib/api";
|
||||
|
||||
vi.mock("@/components/CodeBlock", () => ({
|
||||
CodeBlock: ({ code }: { code: string }) => <pre data-testid="mock-code-block">{code}</pre>,
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/api", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@/lib/api")>();
|
||||
return {
|
||||
...actual,
|
||||
fetchFilePreview: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe("FilePreviewPanel", () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(fetchFilePreview).mockReset();
|
||||
});
|
||||
|
||||
it("shows a compact breadcrumb with one file name and a visible close action", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClose = vi.fn();
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
path: "/Users/hr/workspace/quicksort.py",
|
||||
display_path: "quicksort.py",
|
||||
language: "python",
|
||||
content: "print('ok')",
|
||||
truncated: false,
|
||||
});
|
||||
|
||||
render(
|
||||
<FilePreviewPanel
|
||||
sessionKey="websocket:chat-1"
|
||||
path="quicksort.py"
|
||||
token="tok"
|
||||
onClose={onClose}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(await screen.findByTestId("mock-code-block")).toHaveTextContent("print('ok')");
|
||||
expect(screen.getByTestId("file-preview-breadcrumb")).toHaveTextContent("...");
|
||||
expect(screen.getByTestId("file-preview-breadcrumb")).toHaveTextContent("workspace");
|
||||
expect(screen.getByTestId("file-preview-title")).toHaveTextContent("quicksort.py");
|
||||
expect(screen.getAllByText("quicksort.py")).toHaveLength(1);
|
||||
|
||||
const closeButton = screen.getByRole("button", { name: "Close file preview" });
|
||||
expect(closeButton).toBeVisible();
|
||||
|
||||
await user.click(closeButton);
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user