|
| 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