feat(editor): VertebraPicker preselects region tab inferred from zone label

When opened from a spine zone, the picker now lands on the matching
region tab instead of defaulting to Cervicales every time. Inference is
substring-based on the FR label first, EN as fallback (cervic→C,
thorac/dors→T, lombair/lumbar→L, sacral/sacre→S, caudal/coccyg→Cd),
case- and accent-insensitive. An existing selection still wins over
the inferred region so re-opening lands where the user left off.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude committed 2026-05-19 05:09:57 +02:00
1 parent 6a0ab22f76
commit b3bd75d2e2
3 files changed
+94 -3

No files matched your search

+61 -1
View File
@@ -1,7 +1,9 @@
import { describe, it, expect, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import VertebraPicker from '@/components/observation/VertebraPicker'
import VertebraPicker, {
regionFromLabel,
} from '@/components/observation/VertebraPicker'
import { EQUINE_VERTEBRAL_FORMULA } from '@/domain/species/equine/vertebrae'
describe('VertebraPicker', () => {
@@ -37,4 +39,62 @@ describe('VertebraPicker', () => {
await userEvent.click(screen.getByRole('button', { name: 'Valider' }))
expect(onConfirm).toHaveBeenCalledWith([{ region: 'T', index: 12 }])
})
it('preselects the tab matching initialRegion', () => {
render(
<VertebraPicker
open
onClose={() => {}}
onConfirm={() => {}}
initial={[]}
formula={EQUINE_VERTEBRAL_FORMULA}
title="Vertèbres lombaires"
initialRegion="L"
/>,
)
expect(screen.getByRole('tab', { name: /Lombaires/ })).toHaveAttribute(
'aria-selected',
'true',
)
})
it('region of first existing selection wins over initialRegion', () => {
render(
<VertebraPicker
open
onClose={() => {}}
onConfirm={() => {}}
initial={[{ region: 'S', index: 2 }]}
formula={EQUINE_VERTEBRAL_FORMULA}
title="Vertèbres sacrales"
initialRegion="C"
/>,
)
expect(screen.getByRole('tab', { name: /Sacrales/ })).toHaveAttribute(
'aria-selected',
'true',
)
})
})
describe('regionFromLabel', () => {
it('matches FR roots (accent-insensitive)', () => {
expect(regionFromLabel('Vertèbres cervicales')).toBe('C')
expect(regionFromLabel('Vertèbres thoraciques')).toBe('T')
expect(regionFromLabel('Vertèbres lombaires')).toBe('L')
expect(regionFromLabel('Vertèbres sacrales')).toBe('S')
expect(regionFromLabel('Vertèbres caudales')).toBe('Cd')
})
it('matches EN roots', () => {
expect(regionFromLabel('Cervical Vertebrae')).toBe('C')
expect(regionFromLabel('Thoracic Vertebrae')).toBe('T')
expect(regionFromLabel('Lumbar Vertebrae')).toBe('L')
expect(regionFromLabel('Coccygeal Vertebrae')).toBe('Cd')
})
it('returns undefined when no root matches', () => {
expect(regionFromLabel('Épaule')).toBeUndefined()
expect(regionFromLabel('')).toBeUndefined()
})
})