Limit and label task hierarchy
This commit is contained in:
+21
-4
@@ -415,7 +415,7 @@ test("enforces per-mutation and per-session task limits atomically", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("accepts eight task levels and rejects deeper trees atomically", () => {
|
||||
test("allows three stored levels beneath the virtual root and rejects deeper task trees atomically", () => {
|
||||
const nested = (depth: number) => {
|
||||
let task: { name: string; children?: Array<{ name: string; children?: unknown[] }> } = { name: `Level ${depth}` };
|
||||
for (let level = depth - 1; level >= 1; level -= 1) {
|
||||
@@ -425,10 +425,27 @@ test("accepts eight task levels and rejects deeper trees atomically", () => {
|
||||
};
|
||||
|
||||
const state = new TaskState();
|
||||
state.add([nested(8) as never]);
|
||||
assert.equal(state.list().length, 8);
|
||||
state.add([nested(3) as never, { name: "Other category" }]);
|
||||
assert.equal(state.list().length, 4);
|
||||
const before = state.snapshot();
|
||||
assert.throws(() => state.add([nested(9) as never]), /depth must not exceed 8 levels/);
|
||||
assert.throws(() => state.add([nested(4) as never]), /depth must not exceed 3 levels/);
|
||||
assert.deepEqual(state.snapshot(), before);
|
||||
assert.throws(() => state.update([{ id: 4, parentId: 3 }]), /depth must not exceed 3 levels/);
|
||||
assert.deepEqual(state.snapshot(), before);
|
||||
|
||||
assert.throws(
|
||||
() =>
|
||||
state.restore({
|
||||
tasks: [
|
||||
{ id: 1, name: "Category", status: "pending", parentId: null, childrenIds: [2] },
|
||||
{ id: 2, name: "Item", status: "pending", parentId: 1, childrenIds: [3] },
|
||||
{ id: 3, name: "Leaf", status: "pending", parentId: 2, childrenIds: [4] },
|
||||
{ id: 4, name: "Too deep", status: "pending", parentId: 3, childrenIds: [] },
|
||||
],
|
||||
nextId: 5,
|
||||
}),
|
||||
/depth must not exceed 3 levels/,
|
||||
);
|
||||
assert.deepEqual(state.snapshot(), before);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user