Clean partial editor mounts and failed refreshes
This commit is contained in:
1 parent
3da88510df
commit
d41eda7050
3 files changed
+39
-10
No files matched your search
@@ -9,6 +9,28 @@ const code = new Bun.Transpiler({ loader: "ts" })
|
||||
.replace(/^import .*;\s*$/gm, "")
|
||||
.replace("export function mountBlockEditor", "function mountBlockEditor");
|
||||
|
||||
test("partial registration failure cleans the backend and live region on mount and refresh", () => {
|
||||
for (const failingMount of [1, 2]) {
|
||||
const window = new Window(), root = window.document.createElement("div");
|
||||
window.document.body.append(root);
|
||||
root.innerHTML = '<div data-block-id="a" data-block-parent="root" data-block-slot="content"></div><div data-block-id="b" data-block-parent="root" data-block-slot="content"></div>';
|
||||
let mounts = 0, destroyed = 0, cleaned = 0;
|
||||
const mount = new Function("createDndManager", code + ";return mountBlockEditor;")(() => {
|
||||
const number = ++mounts; let registrations = 0;
|
||||
return { registerSortable() { if (++registrations === 2 && number === failingMount) throw new Error("registration failed"); return () => { cleaned++; }; }, destroy() { destroyed++; } };
|
||||
});
|
||||
let editor: MountedEditor | undefined;
|
||||
if (failingMount === 1) expect(() => mount(root, { onMove() {} })).toThrow("registration failed");
|
||||
else { editor = mount(root, { onMove() {} }); expect(() => editor!.refresh()).toThrow("registration failed"); }
|
||||
expect(root.querySelector('[role="status"]')).toBeNull();
|
||||
expect(root.querySelectorAll('[data-block-id]')).toHaveLength(2);
|
||||
expect(destroyed).toBe(failingMount);
|
||||
expect(cleaned).toBe(failingMount === 1 ? 1 : 3);
|
||||
editor?.destroy(); editor?.refresh();
|
||||
expect(destroyed).toBe(failingMount);
|
||||
}
|
||||
});
|
||||
|
||||
function fixture(onMove: MountEditorOptions["onMove"] = () => false) {
|
||||
const window = new Window();
|
||||
const document = window.document;
|
||||
|
||||
Reference in new issue
Block a user