feat(app): application on the canonical sheet — report v3 store with v2 draft migration, bundled SheetProvider (SHEET_BUNDLE), annotation layer rendered from the document, zone interaction service, pickers and cards on the sheet index, PDF v3 export with v2 archive import; legacy registry, matchers, editors and assets removed
This commit is contained in:
1 parent
0a17e390cf
commit
ce2ec26112
114 files changed
+3560
-14637
No files matched your search
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
* The editor route on the bundled sheet: the click chain end to end (DOM
|
||||
* click on a generated marker → service → store), the detail view by its
|
||||
* localized name, the sheet status line, the disclaimer once per session.
|
||||
*/
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
vi,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
} from 'vitest'
|
||||
import {
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
cleanup,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import EditorRoute from '@/app/routes/EditorRoute'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { loadTestSheet, minimalReport } from '../helpers/sheet'
|
||||
|
||||
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
|
||||
let sheet: SheetIndex
|
||||
|
||||
beforeAll(async () => {
|
||||
sheet = await loadTestSheet()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
sessionStorage.clear()
|
||||
sessionStorage.setItem(DISCLAIMER_FLAG, '1')
|
||||
window.scrollTo = vi.fn() as unknown as typeof window.scrollTo
|
||||
useReportStore.setState({ report: null, activeObservationIndex: 0 })
|
||||
useReportStore
|
||||
.getState()
|
||||
.hydrateReport(
|
||||
minimalReport(sheet, {
|
||||
observations: [
|
||||
{
|
||||
id: 'o1',
|
||||
zones: [],
|
||||
findings: [],
|
||||
freeTextFindings: [],
|
||||
comment: '',
|
||||
},
|
||||
],
|
||||
}),
|
||||
)
|
||||
})
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
const zonesOf = (i = 0) =>
|
||||
useReportStore.getState().report!.observations[i]!.zones
|
||||
|
||||
async function mount() {
|
||||
const utils = render(
|
||||
<MemoryRouter initialEntries={['/editor']}>
|
||||
<EditorRoute />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
document.querySelector('[data-anno-id="head-trigger"]'),
|
||||
).not.toBeNull(),
|
||||
)
|
||||
return utils
|
||||
}
|
||||
|
||||
function clickZone(id: string, scope: ParentNode = document) {
|
||||
const els = scope.querySelectorAll(`[data-anno-id="${id}"]`)
|
||||
expect(els.length, id).toBeGreaterThan(0)
|
||||
els[0]!.dispatchEvent(new Event('click', { bubbles: true }))
|
||||
}
|
||||
|
||||
describe('EditorRoute on the canonical sheet', () => {
|
||||
it('shows the sheet status line and toggles a plain zone on the active observation', async () => {
|
||||
await mount()
|
||||
expect(screen.getByTestId('sheet-status').textContent).toBe(
|
||||
fr['sheet.status.draft'],
|
||||
)
|
||||
clickZone('c7-t1')
|
||||
expect(zonesOf()).toEqual([
|
||||
{
|
||||
annotationId: 'c7-t1',
|
||||
viewId: 'main',
|
||||
labelFrSnapshot: 'Charnière C7-T1 (cervico-thoracique)',
|
||||
labelEnSnapshot: 'C7-T1 junction (cervicothoracic)',
|
||||
},
|
||||
])
|
||||
clickZone('c7-t1')
|
||||
expect(zonesOf()).toEqual([])
|
||||
})
|
||||
|
||||
it('a click with no active observation only activates the last one', async () => {
|
||||
useReportStore.getState().setActiveObservation(-1)
|
||||
await mount()
|
||||
clickZone('c7-t1')
|
||||
expect(useReportStore.getState().activeObservationIndex).toBe(0)
|
||||
expect(zonesOf()).toEqual([])
|
||||
})
|
||||
|
||||
it('a bilateral zone opens the side picker and adds the chosen side; both sides then clear on re-click', async () => {
|
||||
const user = userEvent.setup()
|
||||
await mount()
|
||||
clickZone('hip')
|
||||
const dialog = await screen.findByRole('dialog', {
|
||||
name: 'Hanche (coxo-fémorale)',
|
||||
})
|
||||
await user.click(
|
||||
within(dialog).getByRole('button', { name: fr['lateral.both'] }),
|
||||
)
|
||||
expect(zonesOf().map((z) => z.side)).toEqual(['left', 'right'])
|
||||
clickZone('hip')
|
||||
expect(zonesOf()).toEqual([])
|
||||
})
|
||||
|
||||
it('a spine zone is added and opens the vertebra picker; confirming syncs vertebrae by region', async () => {
|
||||
const user = userEvent.setup()
|
||||
await mount()
|
||||
clickZone('cervical')
|
||||
const dialog = await screen.findByRole('dialog', {
|
||||
name: /Vertèbres cervicales/,
|
||||
})
|
||||
expect(zonesOf()[0]!.annotationId).toBe('cervical')
|
||||
expect(
|
||||
within(dialog).getByRole('tab', { name: 'Cervicales' }),
|
||||
).toHaveAttribute('aria-selected', 'true')
|
||||
await user.click(within(dialog).getByText('C3'))
|
||||
await user.click(within(dialog).getByRole('tab', { name: 'Lombaires' }))
|
||||
await user.click(within(dialog).getByText('L2'))
|
||||
await user.click(
|
||||
within(dialog).getByRole('button', { name: fr['common.confirm'] }),
|
||||
)
|
||||
expect(zonesOf().map((z) => [z.annotationId, z.vertebrae])).toEqual([
|
||||
['cervical', [{ region: 'C', index: 3 }]],
|
||||
['lumbar', [{ region: 'L', index: 2 }]],
|
||||
])
|
||||
})
|
||||
|
||||
it('the head trigger opens the detail view by its name and its zones carry the head view id', async () => {
|
||||
await mount()
|
||||
clickZone('head-trigger')
|
||||
const dialog = await screen.findByRole('dialog', {
|
||||
name: 'Tête (vue latérale gauche)',
|
||||
})
|
||||
await waitFor(() =>
|
||||
expect(dialog.querySelector('[data-anno-id="atm"]')).not.toBeNull(),
|
||||
)
|
||||
expect(dialog.querySelector('svg')!.getAttribute('viewBox')).toBe(
|
||||
'60 100 500 380',
|
||||
)
|
||||
clickZone('atm', dialog)
|
||||
expect(zonesOf()).toEqual([
|
||||
expect.objectContaining({ annotationId: 'atm', viewId: 'head' }),
|
||||
])
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Tête (vue latérale gauche)' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the scope disclaimer once per session, from the sheet', async () => {
|
||||
sessionStorage.removeItem(DISCLAIMER_FLAG)
|
||||
const user = userEvent.setup()
|
||||
await mount()
|
||||
const dialog = await screen.findByRole('dialog', {
|
||||
name: fr['editor.disclaimer_title'],
|
||||
})
|
||||
expect(dialog.textContent).toContain('R. 243-6')
|
||||
await user.click(
|
||||
within(dialog).getByRole('button', { name: fr['common.understood'] }),
|
||||
)
|
||||
expect(sessionStorage.getItem(DISCLAIMER_FLAG)).toBe('1')
|
||||
})
|
||||
|
||||
it('restores the per-tab draft when the store is empty, migrating a v2 one', async () => {
|
||||
const report = useReportStore.getState().report!
|
||||
useReportStore.setState({ report: null })
|
||||
sessionStorage.setItem(
|
||||
'osteo:draft',
|
||||
JSON.stringify({ ...report, version: 3 }),
|
||||
)
|
||||
await mount()
|
||||
expect(useReportStore.getState().report?.id).toBe(report.id)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user