feat: dynamic field labels, optionally overriding field names per species
This commit is contained in:
parent
a0060ca4bb
commit
a2b904811a
21 changed files with 322 additions and 73 deletions
37
src/lib/utils/resolve-label.test.ts
Normal file
37
src/lib/utils/resolve-label.test.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { resolveFieldLabel } from './resolve-label';
|
||||
import type { FieldDef } from '$lib/types';
|
||||
import type { SpeciesData } from '$lib/data/types';
|
||||
|
||||
const stubSpecies: SpeciesData[] = [
|
||||
{
|
||||
id: 'tajara',
|
||||
name: 'Tajara',
|
||||
labels: { subspecies: 'Ethnicity', 'skin-color': 'Fur Colour' },
|
||||
subspecies: [{ id: 'hharar', name: 'Hharar' }],
|
||||
languages: [],
|
||||
citizenships: []
|
||||
}
|
||||
];
|
||||
|
||||
describe('resolveFieldLabel', () => {
|
||||
it('returns species override when available', () => {
|
||||
const field: FieldDef = { label: 'Skin Color', type: 'text' };
|
||||
expect(resolveFieldLabel(field, stubSpecies, 'tajara')).toBe('Fur Colour');
|
||||
});
|
||||
|
||||
it('returns null when no species is selected', () => {
|
||||
const field: FieldDef = { label: 'Skin Color', type: 'text' };
|
||||
expect(resolveFieldLabel(field, stubSpecies, undefined)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when species has no label for the field', () => {
|
||||
const field: FieldDef = { label: 'Height', type: 'height' };
|
||||
expect(resolveFieldLabel(field, stubSpecies, 'tajara')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for separator fields', () => {
|
||||
const field: FieldDef = { label: 'Appearance', type: 'separator' };
|
||||
expect(resolveFieldLabel(field, stubSpecies, 'tajara')).toBeNull();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue