feat(frontend): extractValue helper for data export
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { extractValue } from '../src/lib/dataExport';
|
||||
|
||||
const status = {
|
||||
vitals: 'ok',
|
||||
custom_fields: { 'f-weight': 250 },
|
||||
analysis_summary: { total: 12, success_rate: 0.83, counts: { Success: 10, Failure: 2 } },
|
||||
};
|
||||
|
||||
describe('extractValue', () => {
|
||||
it('reads a builtin field via statusKey', () => {
|
||||
expect(extractValue(status, { kind: 'builtin', statusKey: 'vitals' })).toBe('ok');
|
||||
});
|
||||
it('reads a custom field via fieldId', () => {
|
||||
expect(extractValue(status, { kind: 'custom', fieldId: 'f-weight' })).toBe(250);
|
||||
});
|
||||
it('reads session-metric total', () => {
|
||||
expect(extractValue(status, { kind: 'total' })).toBe(12);
|
||||
});
|
||||
it('reads session-metric success_rate as a raw 0-1 fraction', () => {
|
||||
expect(extractValue(status, { kind: 'success_rate' })).toBe(0.83);
|
||||
});
|
||||
it('reads a dynamic count category', () => {
|
||||
expect(extractValue(status, { kind: 'category', category: 'Failure' })).toBe(2);
|
||||
});
|
||||
it('returns null when analysis_summary is absent', () => {
|
||||
expect(extractValue({ custom_fields: {} }, { kind: 'total' })).toBeNull();
|
||||
expect(extractValue({}, { kind: 'category', category: 'Success' })).toBeNull();
|
||||
});
|
||||
it('returns null for a missing custom field', () => {
|
||||
expect(extractValue({ custom_fields: {} }, { kind: 'custom', fieldId: 'nope' })).toBeNull();
|
||||
expect(extractValue({}, { kind: 'builtin', statusKey: 'notes' })).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user