fix(stammbaum): import chipLabel/otherName from shared relationshipLabels in PersonRelationshipsCard

Removes local duplicates of the switch-statement label logic already
exported from $lib/relationshipLabels.ts. Adds two direction-sensitive
tests proving the Elternteil-von / Kind-von branch is covered.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-28 12:25:34 +02:00
parent 9b750a0698
commit e0e237509d
2 changed files with 42 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { m } from '$lib/paraglide/messages.js';
import { inferredRelationshipLabel } from '$lib/relationshipLabels';
import { chipLabel, otherName, inferredRelationshipLabel } from '$lib/relationshipLabels';
import type { components } from '$lib/generated/api';
type RelationshipDTO = components['schemas']['RelationshipDTO'];
@@ -19,37 +19,9 @@ const topDerived = $derived(
inferredRelationships.filter((d) => !directOtherIds.has(d.person.id)).slice(0, 5)
);
function chipLabel(rel: RelationshipDTO): string {
const viewpointIsSubject = rel.personId === personId;
switch (rel.relationType) {
case 'PARENT_OF':
return viewpointIsSubject ? m.relation_parent_of() : m.relation_child_of();
case 'SPOUSE_OF':
return m.relation_spouse_of();
case 'SIBLING_OF':
return m.relation_sibling_of();
case 'FRIEND':
return m.relation_friend();
case 'COLLEAGUE':
return m.relation_colleague();
case 'EMPLOYER':
return m.relation_employer();
case 'DOCTOR':
return m.relation_doctor();
case 'NEIGHBOR':
return m.relation_neighbor();
default:
return m.relation_other();
}
}
function otherId(rel: RelationshipDTO): string {
return rel.personId === personId ? rel.relatedPersonId : rel.personId;
}
function otherName(rel: RelationshipDTO): string {
return rel.personId === personId ? rel.relatedPersonDisplayName : rel.personDisplayName;
}
</script>
<div class="rounded-sm border border-line bg-surface p-6 shadow-sm">
@@ -67,13 +39,13 @@ function otherName(rel: RelationshipDTO): string {
<span
class="inline-flex shrink-0 items-center rounded-full border border-accent/40 bg-accent/15 px-2 py-0.5 font-sans text-[10px] font-bold tracking-widest text-ink uppercase"
>
{chipLabel(rel)}
{chipLabel(rel, personId)}
</span>
<a
href="/persons/{otherId(rel)}"
class="min-w-0 flex-1 truncate font-serif text-sm text-ink hover:underline"
>
{otherName(rel)}
{otherName(rel, personId)}
</a>
</li>
{/each}

View File

@@ -5,6 +5,7 @@ import PersonRelationshipsCard from './PersonRelationshipsCard.svelte';
const PERSON_ID = '00000000-0000-0000-0000-000000000001';
const SPOUSE_ID = '00000000-0000-0000-0000-000000000002';
const PARENT_ID = '00000000-0000-0000-0000-000000000003';
describe('PersonRelationshipsCard', () => {
it('hides an inferred relationship that is already a direct one', async () => {
@@ -53,4 +54,42 @@ describe('PersonRelationshipsCard', () => {
await expect.element(page.getByText('Carla Cousine')).toBeInTheDocument();
});
it('shows Elternteil-von chip when personId is the PARENT_OF subject', async () => {
render(PersonRelationshipsCard, {
personId: PERSON_ID,
relationships: [
{
id: 'r1',
personId: PERSON_ID,
relatedPersonId: PARENT_ID,
personDisplayName: 'Anna Müller',
relatedPersonDisplayName: 'Kind Müller',
relationType: 'PARENT_OF'
}
],
inferredRelationships: []
});
await expect.element(page.getByText('Elternteil von')).toBeInTheDocument();
});
it('shows Kind-von chip when personId is the PARENT_OF object', async () => {
render(PersonRelationshipsCard, {
personId: PERSON_ID,
relationships: [
{
id: 'r2',
personId: PARENT_ID,
relatedPersonId: PERSON_ID,
personDisplayName: 'Eltern Müller',
relatedPersonDisplayName: 'Anna Müller',
relationType: 'PARENT_OF'
}
],
inferredRelationships: []
});
await expect.element(page.getByText('Kind von')).toBeInTheDocument();
});
});