diff --git a/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx b/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx index 6707dcd85382b..1104af19a15f3 100644 --- a/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx +++ b/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx @@ -4,7 +4,8 @@ import { describe, expect, it, vi } from "vite-plus/test"; import { cdp, page, userEvent } from "vite-plus/test/browser"; import "~/index.css"; -import { render } from "../../../test/render"; +import { act, fakeTimers, render } from "../../../test/render"; +import { SharedTooltipProvider } from "../ui/shared-tooltip"; import { ExpandedImageDialog } from "./ExpandedImageDialog"; const PIXEL = @@ -344,4 +345,56 @@ describe("ExpandedImageDialog", () => { } }, ); + + it("snapshot actions share tooltip timing with Draw on image", async () => { + const file = new File([await (await fetch(PIXEL)).blob()], "shot.png", { type: "image/png" }); + await using screen = await render( + + null), + }, + onCopySnapshot: vi.fn(async () => {}), + }, + ], + index: 0, + }} + onClose={vi.fn()} + /> + , + // The dialog renders no links and reads no route. + { router: false }, + ); + + const contentsButton = screen.getByRole("button", { name: "No accessibility data" }); + const drawButton = screen.getByRole("button", { name: "Draw on image" }); + const copyButton = screen.getByRole("button", { name: "Copy snapshot" }); + await expect.element(drawButton).toBeVisible(); + + using _timers = fakeTimers(); + await userEvent.hover(drawButton); + await act(() => vi.advanceTimersByTime(600)); + expect(page.getByText("Draw on image").element()).toBeVisible(); + + // Moving across adjacent actions swaps the tooltip at once instead of waiting out the delay again. + await userEvent.hover(copyButton); + await act(() => vi.advanceTimersByTime(1)); + expect(page.getByText("Copy snapshot").element()).toBeVisible(); + expect(page.getByText("Draw on image").query()).toBeNull(); + + await userEvent.hover(contentsButton); + await act(() => vi.advanceTimersByTime(1)); + expect(page.getByText("No accessibility data").element()).toBeVisible(); + expect(page.getByText("Copy snapshot").query()).toBeNull(); + }); }); diff --git a/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx b/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx index 58fae303d963a..09d900de020e1 100644 --- a/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx +++ b/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx @@ -8,7 +8,7 @@ import { cn } from "../../lib/utils"; import { RenderErrorBoundary } from "../RenderErrorBoundary"; import { Button } from "../ui/button"; import { Popover, PopoverPopup, PopoverTitle, PopoverTrigger } from "../ui/popover"; -import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; +import { SharedTooltipTrigger } from "../ui/shared-tooltip"; import { ANCHORED_COPY_TOAST_TIMEOUT_MS, showAnchoredCopyErrorToast, @@ -88,42 +88,39 @@ export function SnapShotCopyButton({ const [copied, setCopied] = useState(false); return ( - - { - event.stopPropagation(); - void onCopy().then( - () => { - setCopied(true); - setTimeout(() => setCopied(false), ANCHORED_COPY_TOAST_TIMEOUT_MS); - }, - (error: unknown) => - showAnchoredCopyErrorToast( - ref, - error instanceof Error ? error : new Error(String(error)), - ), - ); - }} - size="xs" - variant="ghost-muted" - /> - } - > - {copied ? ( - - - Copy snapshot - - + { + event.stopPropagation(); + void onCopy().then( + () => { + setCopied(true); + setTimeout(() => setCopied(false), ANCHORED_COPY_TOAST_TIMEOUT_MS); + }, + (error: unknown) => + showAnchoredCopyErrorToast( + ref, + error instanceof Error ? error : new Error(String(error)), + ), + ); + }} + size="xs" + variant="ghost-muted" + /> + } + label={Copy snapshot} + side={side} + > + {copied ? ( + ); } @@ -146,30 +143,29 @@ export function SnapShotContentsButton({ return ( - - event.stopPropagation()} - size="icon-micro" - variant="overlay" - /> - } - /> - } - > - - {tooltip} - + event.stopPropagation()} + size="icon-micro" + variant="overlay" + /> + } + /> + } + label={tooltip} + side={side} + > +