import "../index.css"; import { page } from "vitest/browser"; import { afterEach, describe, expect, it, vi } from "vitest"; import { render } from "vitest-browser-react"; const { openInPreferredEditorMock, readLocalApiMock } = vi.hoisted(() => ({ openInPreferredEditorMock: vi.fn(async () => "vscode"), readLocalApiMock: vi.fn(() => ({ server: { getConfig: vi.fn(async () => ({ availableEditors: ["vscode"] })) }, shell: { openInEditor: vi.fn(async () => undefined) }, })), })); vi.mock("../editorPreferences", () => ({ openInPreferredEditor: openInPreferredEditorMock, })); vi.mock("../localApi", () => ({ ensureLocalApi: vi.fn(() => { throw new Error("ensureLocalApi not implemented in browser test"); }), readLocalApi: readLocalApiMock, })); import ChatMarkdown from "./ChatMarkdown"; describe("ChatMarkdown", () => { afterEach(() => { openInPreferredEditorMock.mockClear(); readLocalApiMock.mockClear(); localStorage.clear(); document.body.innerHTML = ""; }); it("rewrites file uri hrefs into direct paths before rendering", async () => { const filePath = "/Users/yashsingh/p/sco/claude-code-extract/src/utils/permissions/PermissionRule.ts"; const screen = await render( , ); try { const link = page.getByRole("link", { name: "PermissionRule.ts" }); await expect.element(link).toBeInTheDocument(); await expect.element(link).toHaveAttribute("href", filePath); await link.click(); await vi.waitFor(() => { expect(openInPreferredEditorMock).toHaveBeenCalledWith(expect.anything(), filePath); }); } finally { await screen.unmount(); } }); it("keeps line anchors working after rewriting file uri hrefs", async () => { const filePath = "/Users/yashsingh/p/sco/claude-code-extract/src/utils/permissions/PermissionRule.ts"; const screen = await render( , ); try { const link = page.getByRole("link", { name: "PermissionRule.ts:1" }); await expect.element(link).toBeInTheDocument(); await expect.element(link).toHaveAttribute("href", `${filePath}#L1`); await link.click(); await vi.waitFor(() => { expect(openInPreferredEditorMock).toHaveBeenCalledWith(expect.anything(), `${filePath}:1`); }); } finally { await screen.unmount(); } }); });