Share toolbox components and fix image and calendar updates
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
865a4ffd97
commit
34524d2961
13 changed files with 117 additions and 93 deletions
41
tests/toolbox-image-actions.test.mjs
Normal file
41
tests/toolbox-image-actions.test.mjs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// Rôle : 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);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue