clean all
This commit is contained in:
1 parent
f57d6ec3d3
commit
27afb719f5
101 files changed
+45
-14426
No files matched your search
Whitespace-only changes.
@@ -1,20 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { newId } from '@/lib/id';
|
||||
|
||||
describe('newId', () => {
|
||||
it('returns a string without prefix when called bare', () => {
|
||||
const id = newId();
|
||||
expect(typeof id).toBe('string');
|
||||
expect(id.length).toBe(12);
|
||||
});
|
||||
|
||||
it('prefixes when asked', () => {
|
||||
expect(newId('finding')).toMatch(/^finding_[A-Za-z0-9_-]{10}$/);
|
||||
});
|
||||
|
||||
it('is unique across 1000 calls', () => {
|
||||
const ids = new Set(Array.from({ length: 1000 }, () => newId()));
|
||||
expect(ids.size).toBe(1000);
|
||||
});
|
||||
});
|
||||
@@ -1,75 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { exportReportBytes, type AnatomyAssets } from '@/pdf/export';
|
||||
import { importReport } from '@/pdf/import';
|
||||
import { EQUINE_ANATOMY } from '@/species/equine/anatomy';
|
||||
|
||||
// 1×1 transparent PNG as Uint8Array
|
||||
const TINY_PNG = Uint8Array.from([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4,
|
||||
0x89, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0x00, 0x01, 0x00, 0x00,
|
||||
0x05, 0x00, 0x01, 0x0d, 0x0a, 0x2d, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae,
|
||||
0x42, 0x60, 0x82,
|
||||
]);
|
||||
|
||||
const assets: AnatomyAssets = {
|
||||
anatomy: EQUINE_ANATOMY,
|
||||
rasters: {
|
||||
lateral_left: TINY_PNG,
|
||||
lateral_right: TINY_PNG,
|
||||
dorsal: TINY_PNG,
|
||||
},
|
||||
};
|
||||
|
||||
const sampleReport = {
|
||||
version: 1 as const,
|
||||
id: 'r_roundtrip',
|
||||
createdAt: '2026-05-17T10:00:00.000Z',
|
||||
species: 'equine' as const,
|
||||
practitioner: {
|
||||
fullName: 'Dr. Test',
|
||||
phone: '0102030405',
|
||||
email: 'test@example.com',
|
||||
},
|
||||
animal: { name: 'Pégase', owner: 'Famille Martin' },
|
||||
sessionDate: '2026-05-17',
|
||||
findings: [
|
||||
{
|
||||
id: 'finding_1',
|
||||
zones: ['thoracic-back'],
|
||||
linkedZones: ['lumbar'],
|
||||
pathologies: [{ id: 'eq_kissing_spines', label: 'Kissing spines', free: false }],
|
||||
severity: 'moderate' as const,
|
||||
comment: 'Sensibilité marquée en flexion latérale.',
|
||||
},
|
||||
],
|
||||
conclusion: 'Tableau de dysfonction dorsale.',
|
||||
recommendations: 'Repos 7 jours, séance de contrôle à 3 semaines.',
|
||||
nextAppointment: '2026-06-07',
|
||||
};
|
||||
|
||||
describe('PDF roundtrip', () => {
|
||||
it('exports then imports back equal report', async () => {
|
||||
const bytes = await exportReportBytes(sampleReport, assets);
|
||||
expect(bytes.byteLength).toBeGreaterThan(0);
|
||||
expect(new TextDecoder().decode(bytes.slice(0, 5))).toBe('%PDF-');
|
||||
|
||||
const result = await importReport(bytes);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.report).toEqual(sampleReport);
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects a PDF without our attachment', async () => {
|
||||
// Build a tiny PDF with no attachment using pdf-lib
|
||||
const { PDFDocument } = await import('pdf-lib');
|
||||
const pdf = await PDFDocument.create();
|
||||
pdf.addPage();
|
||||
const bytes = await pdf.save();
|
||||
const result = await importReport(bytes);
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) expect(result.reason).toBe('NO_ATTACHMENT');
|
||||
});
|
||||
});
|
||||
@@ -1,53 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { FindingSchema, SeveritySchema } from '@/schema/finding';
|
||||
|
||||
describe('FindingSchema', () => {
|
||||
it('parses a minimal valid finding', () => {
|
||||
const r = FindingSchema.safeParse({
|
||||
id: 'f_1',
|
||||
zones: ['z1'],
|
||||
severity: 'mild',
|
||||
});
|
||||
expect(r.success).toBe(true);
|
||||
if (r.success) {
|
||||
expect(r.data.linkedZones).toEqual([]);
|
||||
expect(r.data.pathologies).toEqual([]);
|
||||
expect(r.data.comment).toBe('');
|
||||
}
|
||||
});
|
||||
|
||||
it('requires at least one zone', () => {
|
||||
const r = FindingSchema.safeParse({
|
||||
id: 'f_1',
|
||||
zones: [],
|
||||
severity: 'mild',
|
||||
});
|
||||
expect(r.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects invalid severity', () => {
|
||||
const r = FindingSchema.safeParse({
|
||||
id: 'f_1',
|
||||
zones: ['z1'],
|
||||
severity: 'extreme',
|
||||
});
|
||||
expect(r.success).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts free-text pathology entries', () => {
|
||||
const r = FindingSchema.safeParse({
|
||||
id: 'f_1',
|
||||
zones: ['z1'],
|
||||
severity: 'moderate',
|
||||
pathologies: [{ id: 'free_xyz', label: 'Sensibilité atypique', free: true }],
|
||||
});
|
||||
expect(r.success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SeveritySchema', () => {
|
||||
it('enumerates mild | moderate | severe', () => {
|
||||
expect(SeveritySchema.options).toEqual(['mild', 'moderate', 'severe']);
|
||||
});
|
||||
});
|
||||
@@ -1,53 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { ReportSchema, SCHEMA_VERSION } from '@/schema/report';
|
||||
|
||||
const sample = {
|
||||
version: 1 as const,
|
||||
id: 'r_abc123',
|
||||
createdAt: '2026-05-17T10:00:00.000Z',
|
||||
species: 'equine' as const,
|
||||
practitioner: {
|
||||
fullName: 'Dr. Doe',
|
||||
},
|
||||
animal: { name: 'Pégase', owner: 'Famille Martin' },
|
||||
sessionDate: '2026-05-17',
|
||||
findings: [],
|
||||
conclusion: '',
|
||||
recommendations: '',
|
||||
};
|
||||
|
||||
describe('ReportSchema', () => {
|
||||
it('exposes schema version 1', () => {
|
||||
expect(SCHEMA_VERSION).toBe(1);
|
||||
});
|
||||
|
||||
it('parses a valid sample', () => {
|
||||
const result = ReportSchema.safeParse(sample);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects missing version', () => {
|
||||
const { version: _v, ...withoutVersion } = sample;
|
||||
const result = ReportSchema.safeParse(withoutVersion);
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects unknown species', () => {
|
||||
const bad = { ...sample, species: 'dinosaur' };
|
||||
const result = ReportSchema.safeParse(bad);
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects empty animal name', () => {
|
||||
const bad = { ...sample, animal: { name: '', owner: 'X' } };
|
||||
const result = ReportSchema.safeParse(bad);
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts optional nextAppointment', () => {
|
||||
const withNext = { ...sample, nextAppointment: '2026-06-01' };
|
||||
const result = ReportSchema.safeParse(withNext);
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
@@ -1,9 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { SCHEMA_VERSION } from '@/schema/report';
|
||||
|
||||
describe('scaffold smoke', () => {
|
||||
it('schema version is 1', () => {
|
||||
expect(SCHEMA_VERSION).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -1,65 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { EQUINE_ANATOMY } from '@/species/equine/anatomy';
|
||||
import { EQUINE_PATHOLOGIES } from '@/species/equine/pathologies';
|
||||
|
||||
describe('EQUINE_ANATOMY', () => {
|
||||
it('has vertebral formula C7 / T18 / L6 / S5', () => {
|
||||
expect(EQUINE_ANATOMY.vertebralFormula).toEqual({
|
||||
cervical: 7,
|
||||
thoracic: 18,
|
||||
lumbar: 6,
|
||||
sacral: 5,
|
||||
});
|
||||
});
|
||||
|
||||
it('declares the expected macro zones', () => {
|
||||
const ids = EQUINE_ANATOMY.zones.map((z) => z.id);
|
||||
for (const expected of [
|
||||
'neck',
|
||||
'withers',
|
||||
'thoracic-back',
|
||||
'lumbar',
|
||||
'sacrum',
|
||||
'shoulder-l',
|
||||
'shoulder-r',
|
||||
'hip-l',
|
||||
'hip-r',
|
||||
'tail',
|
||||
]) {
|
||||
expect(ids).toContain(expected);
|
||||
}
|
||||
});
|
||||
|
||||
it('thoracic-back has 18 subzones T1..T18', () => {
|
||||
const z = EQUINE_ANATOMY.zones.find((zz) => zz.id === 'thoracic-back');
|
||||
expect(z).toBeDefined();
|
||||
expect(z?.subzones).toHaveLength(18);
|
||||
expect(z?.subzones?.[0]?.id).toBe('T1');
|
||||
expect(z?.subzones?.[17]?.id).toBe('T18');
|
||||
});
|
||||
|
||||
it('every zone declares at least one view', () => {
|
||||
for (const z of EQUINE_ANATOMY.zones) {
|
||||
expect(z.views.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('EQUINE_PATHOLOGIES', () => {
|
||||
it('seeds at least 30 entries', () => {
|
||||
expect(EQUINE_PATHOLOGIES.length).toBeGreaterThanOrEqual(30);
|
||||
});
|
||||
|
||||
it('every entry cites at least one source', () => {
|
||||
for (const p of EQUINE_PATHOLOGIES) {
|
||||
expect(p.sources.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it('every entry is applicable to equine', () => {
|
||||
for (const p of EQUINE_PATHOLOGIES) {
|
||||
expect(p.applicableSpecies).toContain('equine');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,19 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { getSpecies, isSpeciesAvailable } from '@/species';
|
||||
|
||||
describe('species registry', () => {
|
||||
it('equine is registered', () => {
|
||||
expect(isSpeciesAvailable('equine')).toBe(true);
|
||||
const pack = getSpecies('equine');
|
||||
expect(pack).toBeDefined();
|
||||
expect(pack?.anatomy.id).toBe('equine');
|
||||
expect(pack?.pathologies.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('non-MVP species are not available yet', () => {
|
||||
for (const id of ['chien', 'chat', 'lapin', 'bovin', 'chevre', 'ane', 'mouton', 'porc'] as const) {
|
||||
expect(isSpeciesAvailable(id)).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,94 +0,0 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { emptyReport, useReportStore } from '@/state/reportStore';
|
||||
|
||||
beforeEach(() => {
|
||||
useReportStore.getState().reset();
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
describe('useReportStore', () => {
|
||||
it('starts empty', () => {
|
||||
const s = useReportStore.getState();
|
||||
expect(s.report).toBeNull();
|
||||
expect(s.selection).toEqual([]);
|
||||
});
|
||||
|
||||
it('hydrate sets report', () => {
|
||||
const r = emptyReport({ animal: { name: 'Pégase', owner: 'X' } });
|
||||
useReportStore.getState().hydrate(r);
|
||||
expect(useReportStore.getState().report?.animal.name).toBe('Pégase');
|
||||
});
|
||||
|
||||
it('toggleZone adds then removes', () => {
|
||||
const { toggleZone } = useReportStore.getState();
|
||||
toggleZone('z1');
|
||||
expect(useReportStore.getState().selection).toEqual(['z1']);
|
||||
toggleZone('z2');
|
||||
expect(useReportStore.getState().selection).toEqual(['z1', 'z2']);
|
||||
toggleZone('z1');
|
||||
expect(useReportStore.getState().selection).toEqual(['z2']);
|
||||
});
|
||||
|
||||
it('addFinding appends and clears selection', () => {
|
||||
useReportStore.getState().hydrate(emptyReport());
|
||||
useReportStore.getState().setSelection(['z1', 'z2']);
|
||||
const f = useReportStore.getState().addFinding({
|
||||
zones: ['z1', 'z2'],
|
||||
linkedZones: [],
|
||||
pathologies: [],
|
||||
severity: 'mild',
|
||||
comment: '',
|
||||
});
|
||||
expect(useReportStore.getState().report?.findings).toHaveLength(1);
|
||||
expect(useReportStore.getState().selection).toEqual([]);
|
||||
expect(f.id).toMatch(/^finding_/);
|
||||
});
|
||||
|
||||
it('updateFinding merges', () => {
|
||||
useReportStore.getState().hydrate(emptyReport());
|
||||
const f = useReportStore.getState().addFinding({
|
||||
zones: ['z1'],
|
||||
linkedZones: [],
|
||||
pathologies: [],
|
||||
severity: 'mild',
|
||||
comment: '',
|
||||
});
|
||||
useReportStore.getState().updateFinding(f.id, { severity: 'severe', comment: 'lourd' });
|
||||
const found = useReportStore.getState().report?.findings[0];
|
||||
expect(found?.severity).toBe('severe');
|
||||
expect(found?.comment).toBe('lourd');
|
||||
});
|
||||
|
||||
it('removeFinding removes by id', () => {
|
||||
useReportStore.getState().hydrate(emptyReport());
|
||||
const f = useReportStore.getState().addFinding({
|
||||
zones: ['z1'],
|
||||
linkedZones: [],
|
||||
pathologies: [],
|
||||
severity: 'mild',
|
||||
comment: '',
|
||||
});
|
||||
useReportStore.getState().removeFinding(f.id);
|
||||
expect(useReportStore.getState().report?.findings).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('setConclusion / setRecommendations / setNextAppointment', () => {
|
||||
useReportStore.getState().hydrate(emptyReport());
|
||||
useReportStore.getState().setConclusion('A');
|
||||
useReportStore.getState().setRecommendations('B');
|
||||
useReportStore.getState().setNextAppointment('2026-06-01');
|
||||
const r = useReportStore.getState().report;
|
||||
expect(r?.conclusion).toBe('A');
|
||||
expect(r?.recommendations).toBe('B');
|
||||
expect(r?.nextAppointment).toBe('2026-06-01');
|
||||
});
|
||||
|
||||
it('persists report to localStorage', () => {
|
||||
useReportStore.getState().hydrate(emptyReport({ animal: { name: 'X', owner: 'Y' } }));
|
||||
const raw = localStorage.getItem('osteo-report-draft');
|
||||
expect(raw).not.toBeNull();
|
||||
const parsed = JSON.parse(raw ?? '{}') as { state?: { report?: { animal?: { name?: string } } } };
|
||||
expect(parsed.state?.report?.animal?.name).toBe('X');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user