test(ai-toolbar): prove textarea paste bypasses global listener

This commit is contained in:
2026-04-22 23:28:22 -04:00
parent c92633e647
commit b048e34891

View File

@@ -333,6 +333,49 @@ describe("AI capture redesign", () => {
expect(onImagesSelect).toHaveBeenCalledWith([image]); expect(onImagesSelect).toHaveBeenCalledWith([image]);
}); });
test("textarea-targeted paste bypasses the document listener and is handled only by the textarea path", async () => {
const onImagesSelect = mock();
const image = new File(["image-bytes"], "clipboard.png", {
type: "image/png",
});
const textareaProps = await renderToolbarBoundary({ onImagesSelect });
const handleCapturePaste = getDocumentListener(
"paste",
(entry) => entry.options?.capture === true,
);
const handleDocumentPaste = getDocumentListener(
"paste",
(entry) => !entry.options?.capture,
);
const preventDefault = mock();
const textareaTarget = {
tagName: "TEXTAREA",
isContentEditable: false,
} as HTMLTextAreaElement;
const pasteEvent = {
target: textareaTarget,
currentTarget: textareaTarget,
clipboardData: createClipboardData([image]),
preventDefault,
};
handleCapturePaste(pasteEvent as unknown as Event);
expect(preventDefault).not.toHaveBeenCalled();
expect(onImagesSelect).not.toHaveBeenCalled();
textareaProps.onPaste?.(
pasteEvent as unknown as React.ClipboardEvent<HTMLTextAreaElement>,
);
expect(preventDefault).toHaveBeenCalledTimes(1);
expect(onImagesSelect).toHaveBeenCalledTimes(1);
expect(onImagesSelect).toHaveBeenCalledWith([image]);
handleDocumentPaste(pasteEvent as unknown as Event);
expect(preventDefault).toHaveBeenCalledTimes(1);
expect(onImagesSelect).toHaveBeenCalledTimes(1);
});
test("document paste forwards clipboard images to onImagesSelect only for non-editable targets", async () => { test("document paste forwards clipboard images to onImagesSelect only for non-editable targets", async () => {
const onImagesSelect = mock(); const onImagesSelect = mock();
const image = new File(["image-bytes"], "clipboard.png", { const image = new File(["image-bytes"], "clipboard.png", {