The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { expect, it, vi } from "vite-plus/test"; |
| 2 | import { page } from "vite-plus/test/browser"; |
| 3 | |
| 4 | import { render } from "../../test/render"; |
| 5 | import { DiffFilePathCopyButton } from "./DiffFilePathCopyButton"; |
| 6 | import { AnchoredToastProvider } from "./ui/toast"; |
| 7 | |
| 8 | it("explains a denied clipboard write and lets the same path be copied again", async () => { |
| 9 | await using screen = await render( |
| 10 | <AnchoredToastProvider timeout={0}> |
| 11 | <DiffFilePathCopyButton filePath="apps/web/src/index.ts" workspaceRoot="/repo" /> |
| 12 | </AnchoredToastProvider>, |
| 13 | ); |
| 14 | using write = vi |
| 15 | .spyOn(navigator.clipboard, "writeText") |
| 16 | .mockRejectedValueOnce(new DOMException("Clipboard access denied", "NotAllowedError")) |
| 17 | .mockResolvedValue(undefined); |
| 18 | using _console = vi.spyOn(console, "error").mockImplementation(() => undefined); |
| 19 | |
| 20 | const copy = screen.getByRole("button", { name: "Copy file path" }); |
| 21 | await copy.click(); |
| 22 | |
| 23 | await expect.element(page.getByText("Failed to copy text to the clipboard.")).toBeVisible(); |
| 24 | await page.getByRole("button", { name: "Dismiss notification" }).click(); |
| 25 | await copy.click(); |
| 26 | |
| 27 | await expect.element(page.getByText("Copied!", { exact: true })).not.toBeInTheDocument(); |
| 28 | expect(write).toHaveBeenCalledTimes(2); |
| 29 | expect(write).toHaveBeenLastCalledWith("apps/web/src/index.ts"); |
| 30 | }); |
| 31 | |
| 32 | it("copies a Windows workspace's file path with Windows separators", async () => { |
| 33 | await using screen = await render( |
| 34 | <AnchoredToastProvider timeout={0}> |
| 35 | <DiffFilePathCopyButton filePath="apps/web/src/index.ts" workspaceRoot="C:\repo" /> |
| 36 | </AnchoredToastProvider>, |
| 37 | ); |
| 38 | using write = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined); |
| 39 | |
| 40 | await screen.getByRole("button", { name: "Copy file path" }).click(); |
| 41 | |
| 42 | await vi.waitFor(() => expect(write).toHaveBeenCalledWith("apps\\web\\src\\index.ts")); |
| 43 | }); |