Side
',
);
const persist = createMemoryAdapter();
await persist.write("compositions/leaf.html", leaf);
const comp = await openComposition(leaf, { persist, persistPath: "compositions/leaf.html" });
await persist.write("index.html", INDEX_REFERRING_LEAF);
comp.removeElement(idOf(comp, "nested"));
comp.removeElement(idOf(comp, "side"));
await comp.flush();
expect(comp.serialize()).not.toContain('id="side"');
expect((await persist.read("compositions/leaf.html")) ?? "").not.toContain('id="side"');
comp.dispose();
});
// fails without the fix: a listing that failed while saving put the saved file back over a newer edit and its undo.
it("keeps a newer edit and its undo when the project listing fails while it saves", async () => {
const inner = createMemoryAdapter();
await inner.write("compositions/leaf.html", LEAF_HTML);
let failing = false;
const persist = listingBy(inner, async () => {
if (failing) throw new Error("listing failed");
return inner.listFiles!();
});
const comp = await openComposition(LEAF_HTML, {
persist,
persistPath: "compositions/leaf.html",
});
failing = true;
comp.removeElement(idOf(comp, "clip"));
comp.undo();
comp.setText(idOf(comp, "clip"), "Newer");
await comp.flush();
expect(comp.serialize()).toContain("Newer");
expect((await inner.read("compositions/leaf.html")) ?? "").toContain("Newer");
expect(comp.canUndo()).toBe(true);
comp.dispose();
});
// Property check through the outermost SDK door: every can()=ok deletion keeps page root + project refs usable.
it("preserves page root and referenced templates for every SDK-permitted deletion across placement table", async () => {
const scenarios: Array<{
name: string;
targetPath: string;
files: Record
;
mustKeepTemplates?: string[];
}> = [
{
name: "plain document root",
targetPath: "index.html",
files: {
"index.html": ``,
},
},
{
name: "template carrying its own composition id",
targetPath: "compositions/scene.html",
files: {
"compositions/scene.html": ``,
},
mustKeepTemplates: ["scene-template"],
},
{
name: "two-file direct reference to locally mounted template",
targetPath: "compositions/a.html",
files: {
"index.html": ``,
"compositions/a.html": LEAF_HTML,
},
mustKeepTemplates: ["child-template"],
},
{
name: "three-file nested project-root reference",
targetPath: "compositions/leaf.html",
files: {
"index.html": ``,
"compositions/middle.html": ``,
"compositions/leaf.html": LEAF_HTML,
},
mustKeepTemplates: ["child-template"],
},
{
name: "shared bundle inline mount across two sub-compositions",
targetPath: "compositions/a.html",
files: {
"index.html": ``,
"compositions/b.html": ``,
"compositions/a.html": ``,
},
mustKeepTemplates: ["a-template", "child-template"],
},
];
for (const scenario of scenarios) await assertScenarioPermittedDeletes(scenario);
});
});