Files
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

74 lines
2.3 KiB
TypeScript

import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ConversationImageContextMenu } from "./ConversationImageContextMenu";
const { copyImageToClipboardMock } = vi.hoisted(() => ({
copyImageToClipboardMock: vi.fn()
}));
vi.mock("../lib/copyImageToClipboard", () => ({
copyImageToClipboard: copyImageToClipboardMock
}));
describe("ConversationImageContextMenu", () => {
afterEach(() => {
copyImageToClipboardMock.mockReset();
});
it("wraps children in a trigger element by default", () => {
render(
<ConversationImageContextMenu src="blob:preview">
<img data-testid="image" alt="" />
</ConversationImageContextMenu>
);
const trigger = document.querySelector(
'[data-slot="context-menu-trigger"]'
);
expect(trigger).not.toBeNull();
// The image is nested inside the wrapper trigger, not the trigger itself.
expect(screen.getByTestId("image").getAttribute("data-slot")).not.toBe(
"context-menu-trigger"
);
expect(trigger?.querySelector('[data-testid="image"]')).not.toBeNull();
});
it("attaches the trigger directly to the child when asChild is set", () => {
render(
<ConversationImageContextMenu src="blob:preview" asChild>
<img data-testid="image" alt="" />
</ConversationImageContextMenu>
);
// No extra wrapper: the image element itself becomes the trigger. This is
// what lets the zoomed image keep its library-managed positioning.
expect(screen.getByTestId("image").getAttribute("data-slot")).toBe(
"context-menu-trigger"
);
});
it("copies and closes the menu on pointer down", async () => {
copyImageToClipboardMock.mockResolvedValue(true);
render(
<ConversationImageContextMenu src="blob:preview">
<img data-testid="image" alt="" />
</ConversationImageContextMenu>
);
fireEvent.contextMenu(screen.getByTestId("image"));
const copyItem = await screen.findByText("Copy image");
fireEvent.pointerDown(copyItem, { button: 0 });
expect(copyImageToClipboardMock).toHaveBeenCalledWith(
"blob:preview",
expect.anything()
);
await waitFor(() => {
expect(screen.queryByText("Copy image")).toBeNull();
});
});
});