Addresses @felix blocker: both functions were duplicated verbatim in StammbaumCard.svelte and StammbaumSidePanel.svelte. Now exported from $lib/relationshipLabels.ts with perspectivePersonId as an explicit param. 8 unit tests added (red→green). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { m } from '$lib/paraglide/messages.js';
|
|
import { chipLabel, otherName } from './relationshipLabels';
|
|
import type { components } from '$lib/generated/api';
|
|
|
|
type RelationshipDTO = components['schemas']['RelationshipDTO'];
|
|
|
|
const ALICE_ID = 'alice-uuid';
|
|
const BOB_ID = 'bob-uuid';
|
|
|
|
function makeRel(
|
|
relationType: RelationshipDTO['relationType'],
|
|
override: Partial<RelationshipDTO> = {}
|
|
): RelationshipDTO {
|
|
return {
|
|
id: 'rel-1',
|
|
personId: ALICE_ID,
|
|
relatedPersonId: BOB_ID,
|
|
personDisplayName: 'Alice',
|
|
relatedPersonDisplayName: 'Bob',
|
|
relationType,
|
|
...override
|
|
};
|
|
}
|
|
|
|
describe('chipLabel', () => {
|
|
it('returns parent_of when perspective is the subject of PARENT_OF', () => {
|
|
const rel = makeRel('PARENT_OF');
|
|
expect(chipLabel(rel, ALICE_ID)).toBe(m.relation_parent_of());
|
|
});
|
|
|
|
it('returns child_of when perspective is the object of PARENT_OF', () => {
|
|
const rel = makeRel('PARENT_OF');
|
|
expect(chipLabel(rel, BOB_ID)).toBe(m.relation_child_of());
|
|
});
|
|
|
|
it('returns spouse_of for SPOUSE_OF regardless of perspective', () => {
|
|
const rel = makeRel('SPOUSE_OF');
|
|
expect(chipLabel(rel, ALICE_ID)).toBe(m.relation_spouse_of());
|
|
expect(chipLabel(rel, BOB_ID)).toBe(m.relation_spouse_of());
|
|
});
|
|
|
|
it('returns sibling_of for SIBLING_OF', () => {
|
|
expect(chipLabel(makeRel('SIBLING_OF'), ALICE_ID)).toBe(m.relation_sibling_of());
|
|
});
|
|
|
|
it('returns friend for FRIEND', () => {
|
|
expect(chipLabel(makeRel('FRIEND'), ALICE_ID)).toBe(m.relation_friend());
|
|
});
|
|
|
|
it('returns other for OTHER', () => {
|
|
expect(chipLabel(makeRel('OTHER'), ALICE_ID)).toBe(m.relation_other());
|
|
});
|
|
});
|
|
|
|
describe('otherName', () => {
|
|
it('returns relatedPersonDisplayName when perspective is the subject', () => {
|
|
const rel = makeRel('PARENT_OF');
|
|
expect(otherName(rel, ALICE_ID)).toBe('Bob');
|
|
});
|
|
|
|
it('returns personDisplayName when perspective is the object', () => {
|
|
const rel = makeRel('PARENT_OF');
|
|
expect(otherName(rel, BOB_ID)).toBe('Alice');
|
|
});
|
|
});
|