Skip to content

Commit fbad0b4

Browse files
only21milcodex
andcommitted
fix(web): failed message and diff path copies show an error toast
Use the existing error notification so failed message and diff-path copies show their clipboard error message and the normal dismissal time. Co-Authored-By: GPT-6.1 Sol <[email protected]>
1 parent 5ffe045 commit fbad0b4

2 files changed

Lines changed: 31 additions & 4 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 { AnchoredToastProvider } from "../ui/toast";
6+
import { MessageCopyButton } from "./MessageCopyButton";
7+
8+
it("explains a denied clipboard write and lets the same message be copied again", async () => {
9+
await using screen = await render(
10+
<AnchoredToastProvider timeout={0}>
11+
<MessageCopyButton text="A message to copy" />
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 message" });
21+
await copy.click();
22+
23+
await expect.element(page.getByText("Failed to copy text to the clipboard.")).toBeVisible();
24+
await expect.element(copy).toBeEnabled();
25+
await page.getByRole("button", { name: "Dismiss notification" }).click();
26+
await copy.click();
27+
28+
await expect.element(page.getByText("Copied!", { exact: true })).toBeVisible();
29+
await expect.element(copy).toBeDisabled();
30+
});

‎apps/web/src/components/ui/anchoredCopyToast.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ export function showAnchoredCopySuccessToast(ref: RefObject<HTMLButtonElement |
2020
export function showAnchoredCopyErrorToast(ref: RefObject<HTMLButtonElement | null>, error: Error) {
2121
if (!ref.current) return;
2222
anchoredToastManager.add({
23-
data: {
24-
tooltipStyle: true,
25-
},
23+
type: "error",
2624
positionerProps: {
2725
anchor: ref.current,
2826
},
29-
timeout: ANCHORED_COPY_TOAST_TIMEOUT_MS,
3027
title: "Failed to copy",
3128
description: error.message,
3229
});

0 commit comments

Comments
 (0)