diff --git a/frontend/src/lib/person/genealogy/layout/tidyTree.test.ts b/frontend/src/lib/person/genealogy/layout/tidyTree.test.ts index 75f045b8..a7d274ea 100644 --- a/frontend/src/lib/person/genealogy/layout/tidyTree.test.ts +++ b/frontend/src/lib/person/genealogy/layout/tidyTree.test.ts @@ -97,3 +97,22 @@ describe('tidyTree — contour nesting', () => { ); }); }); + +describe('tidyTree — multi-root packing', () => { + it('packs multiple roots left-to-right with no overlap', () => { + // A real Stammbaum is a forest of ~50 roots, not a single tree — this is + // the dominant compactness win. Three roots of differing shapes. + const r1 = node('r1', [leaf('r1a'), leaf('r1b')]); + const r2 = leaf('r2'); + const r3 = node('r3', [leaf('r3a')]); + const roots = [r1, r2, r3]; + const x = layoutForest(roots, GAP); + + expectNoOverlap(x, roots, GAP); + // Roots keep input order left-to-right. + expect(x.get('r1')!).toBeLessThan(x.get('r2')!); + expect(x.get('r2')!).toBeLessThan(x.get('r3')!); + // Forest is normalised so the leftmost edge is at 0. + expect(Math.min(...x.values())).toBe(0); + }); +});