Files
ObsiGate/tests/frontend/upload.test.mjs
T
bruno 1db3e0ad2f
CI / lint (push) Successful in 1m20s
CI / security (push) Successful in 50s
CI / test (push) Successful in 2m42s
CI / build (push) Successful in 51s
CI / e2e (push) Successful in 10m29s
feat(dragdrop): drag & drop complet de fichiers/dossiers & intégration IA (#89)
2026-09-14 15:31:12 -04:00

56 lines
1.6 KiB
JavaScript

/**
* Frontend tests for Upload & Drag-and-Drop modules (#89).
*/
import { strict as assert } from "node:assert";
import { JSDOM } from "jsdom";
// JSDOM bootstrap
const dom = new JSDOM(`<!DOCTYPE html><html><body><div id="vault-tree"></div></body></html>`, {
url: "http://localhost:2020/",
});
const w = dom.window;
globalThis.window = w;
globalThis.document = w.document;
globalThis.File = w.File;
globalThis.FileReader = w.FileReader;
Object.defineProperty(globalThis, "navigator", {
value: w.navigator,
configurable: true,
writable: true,
});
const { readDataTransferEntries } = await import("../../frontend/js/upload.js");
async function runTests() {
console.log("Testing readDataTransferEntries empty input...");
const resNull = await readDataTransferEntries(null);
assert.deepEqual(resNull, []);
const resEmpty = await readDataTransferEntries([]);
assert.deepEqual(resEmpty, []);
console.log("Testing readDataTransferEntries plain files...");
const fakeFile1 = { name: "note1.md", webkitRelativePath: "folder/note1.md" };
const fakeFile2 = { name: "logo.png", webkitRelativePath: "" };
const fakeItems = [
{ getAsFile: () => fakeFile1 },
{ getAsFile: () => fakeFile2 },
];
const results = await readDataTransferEntries(fakeItems);
assert.equal(results.length, 2);
assert.equal(results[0].path, "folder/note1.md");
assert.equal(results[0].isDir, false);
assert.equal(results[1].path, "logo.png");
assert.equal(results[1].isDir, false);
console.log("✅ All upload tests passed successfully!");
}
runTests().catch((err) => {
console.error("❌ Test failed:", err);
process.exit(1);
});