fix(subspecies): allows for custom subspecies names

This commit is contained in:
Lewis Wynne 2026-03-24 16:49:39 +00:00
parent 25968533ab
commit 7ccfda5d17
2 changed files with 6 additions and 1 deletions

View file

@ -101,6 +101,11 @@ describe('formatFieldOutput', () => {
expect(formatFieldOutput(field, 'hharar', stubSpecies, 'tajara')).toBe('Ethnicity: Hharar');
});
it('formats custom subspecies with dynamic label', () => {
const field: FieldDef = { label: 'Subspecies', type: 'subspecies' };
expect(formatFieldOutput(field, 'asdfg', stubSpecies, 'tajara')).toBe('Ethnicity: asdfg');
});
it('returns null for empty subspecies', () => {
const field: FieldDef = { label: 'Subspecies', type: 'subspecies' };
expect(formatFieldOutput(field, '', stubSpecies, 'tajara')).toBeNull();

View file

@ -48,7 +48,7 @@ export function formatFieldOutput(
const sp = speciesData.find((s) => s.id === currentSpecies);
if (!sp) return null;
const sub = sp.subspecies.find((s) => s.id === value);
return sub ? `${sp.subspeciesLabel}: ${sub.name}` : null;
return sub ? `${sp.subspeciesLabel}: ${sub.name}` : `${sp.subspeciesLabel}: ${value}`;
}
case 'languages': {