test(stammbaum): add makeNode factory for birth-year ordering tests (#724)
The existing node() factory never sets birthYear, but the new sibling/branch
comparator (birthYear ASC NULLS LAST) needs it. Add makeNode(id, name,
{birthYear, generation}) alongside it; unblocks every ordering test.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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<typeof buildLayout>, 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
|
||||
|
||||
Reference in New Issue
Block a user