fix(files): make dropped-file handling explicit
This commit is contained in:
41
webui/scripts/test-file-drop-zone-structure.mjs
Normal file
41
webui/scripts/test-file-drop-zone-structure.mjs
Normal file
@@ -0,0 +1,41 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
const source = readFileSync(new URL("../src/components/FileDropZone.tsx", import.meta.url), "utf8");
|
||||
const normalized = source.replace(/\s+/g, " ");
|
||||
|
||||
function assertIncludes(fragment, message) {
|
||||
if (!normalized.includes(fragment.replace(/\s+/g, " "))) throw new Error(message);
|
||||
}
|
||||
|
||||
assertIncludes(
|
||||
"function prepareFileDrag(event: ReactDragEvent<HTMLDivElement>) { event.preventDefault(); event.stopPropagation();",
|
||||
"drag enter/over must prevent the browser default and stop propagation"
|
||||
);
|
||||
assertIncludes("onDragEnter={prepareFileDrag}", "drag enter must use the guarded file-drag handler");
|
||||
assertIncludes("onDragOver={prepareFileDrag}", "drag over must use the guarded file-drag handler");
|
||||
assertIncludes(
|
||||
"onDragLeave={(event) => { event.preventDefault(); event.stopPropagation();",
|
||||
"drag leave must prevent the browser default and stop propagation"
|
||||
);
|
||||
assertIncludes(
|
||||
"onDrop={(event) => { event.preventDefault(); event.stopPropagation(); setDragActive(false);",
|
||||
"drop must prevent the browser default and stop propagation before resolving files"
|
||||
);
|
||||
assertIncludes(
|
||||
"if (interactionDisabled) { onRejectedDrop?.(\"disabled\"); return; }",
|
||||
"disabled drops must route the disabled rejection reason"
|
||||
);
|
||||
assertIncludes(
|
||||
"void resolveDroppedFiles(event.dataTransfer).then((files) => {",
|
||||
"drop must route the event DataTransfer through the shared resolver"
|
||||
);
|
||||
assertIncludes(
|
||||
"if (files.length === 0) { onRejectedDrop?.(\"empty\"); return; } void handleFiles(files);",
|
||||
"resolved files and empty drops must be routed through their explicit callbacks"
|
||||
);
|
||||
assertIncludes(
|
||||
".catch(() => onRejectedDrop?.(\"unreadable\"))",
|
||||
"resolver failures must route the unreadable rejection reason"
|
||||
);
|
||||
|
||||
console.log("FileDropZone event and result routing structure is intact.");
|
||||
Reference in New Issue
Block a user