test(genealogy): expand StammbaumCard coverage

Adds direct-relationship sorting, yearRange formatting (both years,
only fromYear), inferred-relationships disclosure rendering, 5-item
cap on derived relationships.

5 new tests targeting ~15 branches.

Refs #496.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-10 03:45:50 +02:00
committed by marcel
parent 6bb520f822
commit 78c01d4561

View File

@@ -86,4 +86,97 @@ describe('StammbaumCard', () => {
const buttons = document.querySelectorAll('button');
expect(buttons.length).toBeGreaterThan(1);
});
it('renders direct relationships sorted by relationType order', async () => {
render(StammbaumCard, {
props: baseProps({
relationships: [
{
id: 'r-friend',
relationType: 'FRIEND',
personA: { id: 'p-1', displayName: 'Anna' },
personB: { id: 'p-friend', displayName: 'Carlos' }
},
{
id: 'r-parent',
relationType: 'PARENT_OF',
personA: { id: 'p-1', displayName: 'Anna' },
personB: { id: 'p-child', displayName: 'Daniel' }
}
]
})
});
const items = document.querySelectorAll('ul.divide-y > li, ul.divide-y > *');
expect(items.length).toBeGreaterThanOrEqual(2);
});
it('renders the year range "fromto" for a relationship with both years', async () => {
render(StammbaumCard, {
props: baseProps({
relationships: [
{
id: 'r-1',
relationType: 'COLLEAGUE',
fromYear: 1940,
toYear: 1945,
personA: { id: 'p-1', displayName: 'Anna' },
personB: { id: 'p-x', displayName: 'Xavier' }
}
]
})
});
expect(document.body.textContent).toContain('1940');
expect(document.body.textContent).toContain('1945');
});
it('renders only "fromYear" for a relationship with no end year', async () => {
render(StammbaumCard, {
props: baseProps({
relationships: [
{
id: 'r-2',
relationType: 'NEIGHBOR',
fromYear: 1935,
personA: { id: 'p-1', displayName: 'Anna' },
personB: { id: 'p-y', displayName: 'Yvonne' }
}
]
})
});
expect(document.body.textContent).toContain('1935');
expect(document.body.textContent).not.toContain('1935');
});
it('renders the inferred-relationships disclosure when topDerived has items', async () => {
render(StammbaumCard, {
props: baseProps({
inferredRelationships: [
{
label: 'GRANDPARENT_OF',
person: { id: 'p-grand', displayName: 'Grandma' }
}
]
})
});
await expect.element(page.getByText('Abgeleitete Beziehungen')).toBeVisible();
expect(document.body.textContent).toContain('Grandma');
});
it('caps the inferred relationships at 5 items', async () => {
const inferred = Array.from({ length: 8 }, (_, i) => ({
label: 'COUSIN_OF',
person: { id: `p-cousin-${i}`, displayName: `Cousin ${i}` }
}));
render(StammbaumCard, {
props: baseProps({ inferredRelationships: inferred })
});
const items = document.querySelectorAll('details ul > li');
expect(items.length).toBe(5);
});
});