fix(ai-toolbar): tighten modifier and clipboard fallback guards
This commit is contained in:
@@ -488,6 +488,24 @@ describe("AI toolbar paste capture", () => {
|
||||
expect(onAiCreate).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("Mod+Enter ignores extra modifiers so Shift+Ctrl+Enter does not generate", async () => {
|
||||
const onAiCreate = mock();
|
||||
|
||||
const { textareaProps } = await renderToolbarBoundary({
|
||||
aiPrompt: "Draft a kickoff",
|
||||
onAiCreate,
|
||||
});
|
||||
const event = createTextareaKeydownEvent({
|
||||
ctrlKey: true,
|
||||
shiftKey: true,
|
||||
});
|
||||
|
||||
textareaProps.onKeyDown?.(event);
|
||||
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
expect(onAiCreate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("Mod+Enter does not trigger AI generation while loading", async () => {
|
||||
const onAiCreate = mock();
|
||||
|
||||
@@ -630,6 +648,41 @@ describe("AI toolbar paste capture", () => {
|
||||
expect(onImagesSelect.mock.calls[0]?.[0][0]?.type).toBe("image/png");
|
||||
});
|
||||
|
||||
test("clipboard fallback creates distinct files for same-sized clipboard images", async () => {
|
||||
const onImagesSelect = mock();
|
||||
const clipboardRead = mock(async () => [
|
||||
{
|
||||
types: ["image/png"],
|
||||
getType: async () => new Blob(["abcd"], { type: "image/png" }),
|
||||
},
|
||||
{
|
||||
types: ["image/png"],
|
||||
getType: async () => new Blob(["wxyz"], { type: "image/png" }),
|
||||
},
|
||||
]);
|
||||
|
||||
(globalThis as { navigator?: Navigator }).navigator = {
|
||||
clipboard: { read: clipboardRead },
|
||||
} as Navigator;
|
||||
|
||||
await renderToolbar({ onImagesSelect });
|
||||
|
||||
const handleDocumentKeydown = getDocumentListener("keydown");
|
||||
|
||||
await handleDocumentKeydown(
|
||||
createDocumentKeydownEvent({ ctrlKey: true }),
|
||||
);
|
||||
|
||||
expect(onImagesSelect).toHaveBeenCalledTimes(1);
|
||||
expect(onImagesSelect.mock.calls[0]?.[0]).toHaveLength(2);
|
||||
expect(onImagesSelect.mock.calls[0]?.[0][0]?.name).not.toBe(
|
||||
onImagesSelect.mock.calls[0]?.[0][1]?.name,
|
||||
);
|
||||
expect(onImagesSelect.mock.calls[0]?.[0][0]?.size).toBe(
|
||||
onImagesSelect.mock.calls[0]?.[0][1]?.size,
|
||||
);
|
||||
});
|
||||
|
||||
test("async clipboard fallback does not double-handle a paste already handled by the synchronous document paste flow", async () => {
|
||||
const onImagesSelect = mock();
|
||||
const clipboardRead = mock(async () => [
|
||||
|
||||
Reference in New Issue
Block a user