diff --git a/frontend/src/lib/person/genealogy/layout/buildLayout.test.ts b/frontend/src/lib/person/genealogy/layout/buildLayout.test.ts index 4920884b..faa8d9ed 100644 --- a/frontend/src/lib/person/genealogy/layout/buildLayout.test.ts +++ b/frontend/src/lib/person/genealogy/layout/buildLayout.test.ts @@ -20,6 +20,20 @@ function node(id: string, displayName: string, generation: number | null = null) : { id, displayName, familyMember: true, generation }; } +// Richer factory than node(): lets ordering tests set birthYear (which the +// sibling/branch comparator sorts on) and generation independently. node() +// never sets birthYear, so every birth-year ordering assertion needs this. +function makeNode( + id: string, + displayName: string, + opts: { birthYear?: number; generation?: number } = {} +): PersonNodeDTO { + const n: PersonNodeDTO = { id, displayName, familyMember: true }; + if (opts.birthYear != null) n.birthYear = opts.birthYear; + if (opts.generation != null) n.generation = opts.generation; + return n; +} + function parentEdge(parentId: string, childId: string, id = parentId + childId): RelationshipDTO { return { id, @@ -48,6 +62,19 @@ function yOf(layout: ReturnType, id: string): number { return p.y; } +describe('makeNode factory', () => { + it('sets birthYear and generation only when provided', () => { + expect(makeNode('a', 'A')).toEqual({ id: 'a', displayName: 'A', familyMember: true }); + expect(makeNode('b', 'B', { birthYear: 1900, generation: 2 })).toEqual({ + id: 'b', + displayName: 'B', + familyMember: true, + birthYear: 1900, + generation: 2 + }); + }); +}); + describe('buildLayout — generation seeding (#689)', () => { it('Herbert Cram regression: two parented G=3 spouses share the same row', () => { // Both Herbert (G 3) and Clara (G 3) are parented children of their respective