import { describe, expect, it } from 'vitest'; import { parseCalibration } from './lensCalibration.mjs'; const base = { maker: 'Tamron', model: 'SP 24-70mm f/2.8 Di VC USD', mount: 'Canon EF', crop: 1, d: [[24, 2, 0.01, -0.02, 0.03, 0]], }; describe('team lens calibration validation', () => { it('accepts a measured profile and normalises its text', () => { const result = parseCalibration({ ...base, maker: ' Tamron ', notes: ' shot on a 5D ' }); expect(result.error).toBeUndefined(); expect(result.value).toMatchObject({ maker: 'Tamron', model: 'SP 24-70mm f/2.8 Di VC USD', mount: 'Canon EF', crop: 1, notes: 'shot on a 5D', aspect: 0, centerX: 0, centerY: 0, }); expect(result.value.d).toEqual([[24, 2, 0.01, -0.02, 0.03, 0]]); }); it('requires a maker and a model', () => { expect(parseCalibration({ ...base, maker: ' ' }).error).toMatch(/maker/i); expect(parseCalibration({ ...base, model: '' }).error).toMatch(/model/i); }); it('rejects unknown models and impossible focals', () => { expect(parseCalibration({ ...base, d: [[24, 7, 0.01, 0, 0, 0]] }).error).toMatch(/model/i); expect(parseCalibration({ ...base, d: [[0, 2, 0.01, 0, 0, 0]] }).error).toMatch(/focal/i); }); it('rejects a row with the wrong number of values', () => { expect(parseCalibration({ ...base, d: [[24, 2, 0.01]] }).error).toMatch(/6 numbers/); expect(parseCalibration({ ...base, t: [[24, 0, 0, 0]] }).error).toMatch(/8 numbers/); }); it('rejects a crop factor no lens has', () => { expect(parseCalibration({ ...base, crop: 0 }).error).toMatch(/crop/i); expect(parseCalibration({ ...base, crop: 9 }).error).toMatch(/crop/i); }); it('needs at least one sample of any kind', () => { expect(parseCalibration({ ...base, d: [] }).error).toMatch(/at least one/i); }); it('keeps vignetting samples that a measurement pass produced', () => { const result = parseCalibration({ ...base, d: [], v: [ [24, 2.8, 1000, 0.31, -0.12, 0.02], [70, 2.8, 1000, 0.42, -0.2, 0.05], ], }); expect(result.error).toBeUndefined(); expect(result.value.v).toHaveLength(2); expect(result.value.d).toEqual([]); }); it('rejects vignetting without an aperture', () => { expect(parseCalibration({ ...base, d: [], v: [[24, 0, 1000, 0.3, 0, 0]] }).error).toMatch(/aperture/i); }); });