Skip to content

Commit 3bd0ee5

Browse files
only21milclaude
andcommitted
test(web): cover denied diff path copy and retry
DiffFilePathCopyButton has its own clipboard hook call, so the message button test does not cover it. Check that a denied write shows the error, dismissal works, and a second copy of the same path succeeds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fbad0b4 commit 3bd0ee5

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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" />
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 })).toBeVisible();
28+
expect(write).toHaveBeenCalledTimes(2);
29+
expect(write).toHaveBeenLastCalledWith("apps/web/src/index.ts");
30+
});

0 commit comments

Comments
 (0)