fix(builder): correct move and sortable behavior
This commit is contained in:
1 parent
0bd2a6860d
commit
edccf06658
5 files changed
+70
-5
No files matched your search
@@ -137,4 +137,36 @@ describe("dynamic blocks engine", () => {
|
||||
expect(decoded.ok && decoded.value.roots[0]?.id).not.toBe(node.id);
|
||||
expect(duplicateNodes([node], id)[0]?.props).toEqual(node.props);
|
||||
});
|
||||
|
||||
test("moves forward within one slot without an off-by-one error", () => {
|
||||
const document = doc();
|
||||
document.root.slots.content = ["a", "b", "c"].map((nodeId) => ({
|
||||
...text.create({ id: () => nodeId }),
|
||||
props: { text: nodeId },
|
||||
}));
|
||||
const moved = applyCommand(document, {
|
||||
type: "move",
|
||||
intent: {
|
||||
nodeIds: ["a"],
|
||||
from: [{ parentId: "root", slot: "content", index: 0 }],
|
||||
to: { parentId: "root", slot: "content", index: 3 },
|
||||
},
|
||||
}, kind, registry);
|
||||
expect(moved.ok && moved.value.document.root.slots.content.map((node) => node.id)).toEqual([
|
||||
"b", "c", "a",
|
||||
]);
|
||||
});
|
||||
|
||||
test("duplicates blocks with deterministic injected ids", () => {
|
||||
const document = doc();
|
||||
document.root.slots.content = [{ ...text.create({ id: () => "a" }), props: { text: "A" } }];
|
||||
const duplicated = applyCommand(document, {
|
||||
type: "duplicate",
|
||||
nodeIds: ["a"],
|
||||
ids: ["a-copy"],
|
||||
}, kind, registry);
|
||||
expect(duplicated.ok && duplicated.value.document.root.slots.content.map((node) => node.id)).toEqual([
|
||||
"a", "a-copy",
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user