test(ai-toolbar): cover normalized clipboard paste paths
This commit is contained in:
@@ -52,15 +52,18 @@ async function getClipboardBlobIdentity(blob: Blob): Promise<string> {
|
||||
return (hash >>> 0).toString(16).padStart(8, "0");
|
||||
}
|
||||
|
||||
async function createClipboardFallbackFile(blob: Blob): Promise<File> {
|
||||
async function normalizeClipboardImageFile(blob: Blob): Promise<File> {
|
||||
const identity = await getClipboardBlobIdentity(blob);
|
||||
const extension = blob.type.split("/")[1] || "png";
|
||||
return new File([blob], `clipboard-image-${identity}.${extension}`, {
|
||||
return new File([blob], `clipboard-image-${identity}`, {
|
||||
type: blob.type,
|
||||
lastModified: 0,
|
||||
});
|
||||
}
|
||||
|
||||
async function normalizeClipboardImageFiles(files: File[]): Promise<File[]> {
|
||||
return Promise.all(files.map((file) => normalizeClipboardImageFile(file)));
|
||||
}
|
||||
|
||||
// ─── Shared shortcuts list (rendered in both HoverCard and Popover) ───────────
|
||||
|
||||
function ShortcutsList({ os }: { os: Os }) {
|
||||
@@ -194,7 +197,9 @@ export const AIToolbar = ({
|
||||
const images = extractAllImagesFromClipboard(e.clipboardData ?? null);
|
||||
if (images.length > 0) {
|
||||
e.preventDefault();
|
||||
onImagesSelectRef.current(images);
|
||||
void normalizeClipboardImageFiles(images).then((normalizedImages) => {
|
||||
onImagesSelectRef.current(normalizedImages);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -241,7 +246,7 @@ export const AIToolbar = ({
|
||||
for (const mimeType of typesToTry) {
|
||||
try {
|
||||
const blob = await clipboardItem.getType(mimeType);
|
||||
files.push(await createClipboardFallbackFile(blob));
|
||||
files.push(await normalizeClipboardImageFile(blob));
|
||||
break; // got this item, move to next clipboardItem
|
||||
} catch {
|
||||
// NotFoundError — type not present, try next
|
||||
@@ -359,7 +364,11 @@ export const AIToolbar = ({
|
||||
);
|
||||
if (images.length > 0) {
|
||||
e.preventDefault();
|
||||
onImagesSelect(images);
|
||||
void normalizeClipboardImageFiles(images).then(
|
||||
(normalizedImages) => {
|
||||
onImagesSelect(normalizedImages);
|
||||
},
|
||||
);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user