feat(export): dimension primitives, date members, status index
This commit is contained in:
@@ -155,3 +155,68 @@ describe('csvFilename', () => {
|
||||
expect(csvFilename('', '')).toBe('export.csv');
|
||||
});
|
||||
});
|
||||
|
||||
import {
|
||||
EXPORT_DIMENSIONS, dimLabel, otherDimension, subjectGroupValue,
|
||||
listDateMembers, buildStatusIndex,
|
||||
} from '../src/lib/dataExport';
|
||||
|
||||
describe('dimension primitives', () => {
|
||||
it('exposes the three dimensions with labels', () => {
|
||||
expect(EXPORT_DIMENSIONS.map((d) => d.dim)).toEqual(['date', 'subject', 'parameter']);
|
||||
expect(dimLabel('date')).toBe('Date');
|
||||
expect(dimLabel('subject')).toBe('Subject');
|
||||
expect(dimLabel('parameter')).toBe('Parameter');
|
||||
});
|
||||
it('otherDimension returns the leftover', () => {
|
||||
expect(otherDimension('date', 'subject')).toBe('parameter');
|
||||
expect(otherDimension('parameter', 'date')).toBe('subject');
|
||||
});
|
||||
});
|
||||
|
||||
describe('subjectGroupValue', () => {
|
||||
const animal = { animal_name: 'Alpha', animal_id_string: 'R-001', subject_info: { sex: 'M', cohort: '' } };
|
||||
it('returns null when no group field', () => {
|
||||
expect(subjectGroupValue(animal, '__none__')).toBeNull();
|
||||
expect(subjectGroupValue(animal, '')).toBeNull();
|
||||
});
|
||||
it('resolves name / id / subject_info fields', () => {
|
||||
expect(subjectGroupValue(animal, '__name__')).toBe('Alpha');
|
||||
expect(subjectGroupValue(animal, '__id__')).toBe('R-001');
|
||||
expect(subjectGroupValue(animal, 'sex')).toBe('M');
|
||||
});
|
||||
it('renders missing or empty values as an em dash', () => {
|
||||
expect(subjectGroupValue(animal, 'cohort')).toBe('—');
|
||||
expect(subjectGroupValue({}, 'sex')).toBe('—');
|
||||
});
|
||||
});
|
||||
|
||||
describe('listDateMembers', () => {
|
||||
it('returns sorted unique dateKeys with id/label', () => {
|
||||
const statuses = [
|
||||
{ date: '2026-07-02T00:00:00.000Z' },
|
||||
{ date: '2026-07-01T12:00:00.000Z' },
|
||||
{ date: '2026-07-02T09:00:00.000Z' },
|
||||
];
|
||||
expect(listDateMembers(statuses)).toEqual([
|
||||
{ id: '2026-07-01', label: '2026-07-01', dateKey: '2026-07-01' },
|
||||
{ id: '2026-07-02', label: '2026-07-02', dateKey: '2026-07-02' },
|
||||
]);
|
||||
});
|
||||
it('tolerates empty input', () => {
|
||||
expect(listDateMembers(undefined)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildStatusIndex', () => {
|
||||
it('indexes by dateKey then animalId, first status wins', () => {
|
||||
const statuses = [
|
||||
{ animal_id: 'a1', date: '2026-07-01T00:00:00.000Z', analysis_summary: { total: 7 } },
|
||||
{ animal_id: 'a1', date: '2026-07-01T06:00:00.000Z', analysis_summary: { total: 99 } },
|
||||
{ animal_id: 'a2', date: '2026-07-01T00:00:00.000Z', analysis_summary: { total: 3 } },
|
||||
];
|
||||
const idx = buildStatusIndex(statuses);
|
||||
expect(idx.get('2026-07-01').get('a1').analysis_summary.total).toBe(7);
|
||||
expect(idx.get('2026-07-01').get('a2').analysis_summary.total).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user