sokko-g/tests/toolbox-image-actions.test.mjs
Shinuwa 22b397ebfa Document Sokko G's architecture and folders, and move JavaScript file headers to JSDoc @file blocks
Add ARCHITECTURE.md (layers, flows, folder map, glossary), CONTRIBUTING.md
(setup and step-by-step recipes) and a README in each main folder, with an
index of docs/. Convert the 511 JavaScript headers from "// Rôle :" lines to
JSDoc @file blocks, define a three-level header template in website/AGENTS.md
and check the header in tests/file-headers.test.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 09:42:13 +01:00

44 lines
1.9 KiB
JavaScript

/**
* @file Vérifie la fusion des ajouts d'images pendant une compression asynchrone.
*/
import { test } from "node:test";
import assert from "node:assert/strict";
import { useToolboxActions } from "../website/src/features/toolboxes/useToolboxActions.js";
test("concurrent image batches preserve intervening edits and completed additions", async (t) => {
const descriptors = Object.fromEntries(["document", "createImageBitmap"].map((key) => [
key, Object.getOwnPropertyDescriptor(globalThis, key)
]));
t.after(() => {
for (const [key, descriptor] of Object.entries(descriptors)) {
if (descriptor) Object.defineProperty(globalThis, key, descriptor);
else delete globalThis[key];
}
});
const pending = new Map();
globalThis.createImageBitmap = (file) => new Promise((resolve) => pending.set(file.name, resolve));
globalThis.document = {
createElement: () => ({
getContext: () => ({ drawImage() {} }),
toDataURL: () => "data:image/jpeg;base64,dGVzdA=="
})
};
let current = { images: [{ id: "old", label: "Old" }] };
const actions = useToolboxActions({
store: {
getModuleData: () => current,
updateModuleData: (_toolboxId, _moduleId, value) => { current = value; return true; }
}
});
const first = actions.addImageFiles("toolbox", "images", [{ name: "First.png", type: "image/png" }]);
const second = actions.addImageFiles("toolbox", "images", [{ name: "Second.png", type: "image/png" }]);
current = { images: [{ id: "old", label: "Renamed" }], annotation: "Keep me" };
pending.get("Second.png")({ width: 10, height: 10 });
assert.equal(await second, true);
pending.get("First.png")({ width: 10, height: 10 });
assert.equal(await first, true);
assert.deepEqual(current.images.map((image) => image.label), ["First", "Second", "Renamed"]);
assert.equal(current.annotation, "Keep me");
assert.equal(await actions.addImageFiles("toolbox", "images", [{ type: "text/plain" }]), false);
});