Files
fusion/packages/dashboard/app/utils/__tests__/filePathLinkify.test.tsx
Fusion 4de193b847 test(FN-4264): add file path wrapping regression coverage
- Add a dashboard filePathLinkify regression test for long file path buttons
- Verify file path links render with wrapping-friendly computed styles
- Guard against inline-flex rendering that would prevent long paths from wrapping

Fusion-Task-Id: FN-4264
2026-05-12 23:09:38 -07:00

63 lines
2.0 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { FileBrowserProvider } from "../../context/FileBrowserContext";
import { FilePathLink, linkifyFilePaths } from "../filePathLinkify";
describe("filePathLinkify", () => {
it.each([
"packages/dashboard/app/App.tsx",
".fusion/tasks/FN-4227/PROMPT.md",
"Dockerfile",
"src/foo.ts:42",
"src/foo.ts:42:7",
])("matches %s", (value) => {
const result = linkifyFilePaths(`open ${value} now`);
expect(result.some((node) => typeof node !== "string")).toBe(true);
});
it.each([
"https://example.com/foo.md",
"v1.2.3",
"node_modules",
"the literal string it.each should stay plain text",
])("does not match %s", (value) => {
const result = linkifyFilePaths(value);
expect(result).toEqual([value]);
});
it("opens the linked file through context", async () => {
const user = userEvent.setup();
const openFile = vi.fn();
render(
<FileBrowserProvider openFile={openFile}>
<FilePathLink path="src/foo.ts" line={42} col={7}>src/foo.ts:42:7</FilePathLink>
</FileBrowserProvider>,
);
await user.click(screen.getByRole("button", { name: "src/foo.ts:42:7" }));
expect(openFile).toHaveBeenCalledWith("src/foo.ts", { line: 42, col: 7 });
});
it("allows long file path links to wrap", () => {
const openFile = vi.fn();
render(
<FileBrowserProvider openFile={openFile}>
<FilePathLink path="packages/some/very/long/nested/path/file.ts">
packages/some/very/long/nested/path/file.ts
</FilePathLink>
</FileBrowserProvider>,
);
const button = screen.getByRole("button", {
name: "packages/some/very/long/nested/path/file.ts",
});
const styles = getComputedStyle(button);
expect(styles.whiteSpace).toBe("normal");
expect(styles.display).not.toBe("inline-flex");
});
});