diff --git a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx index abfe153d..a1fb2425 100644 --- a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx @@ -293,7 +293,10 @@ function EditorLabels({ onSelect: (id: string) => void }) { const version = useEditorStore((s) => s.handleVersion) - const layoutKey = `${build.root?.viewId ?? ''}:${transform}:${selectedId ?? ''}:${version}` + // Every rebuild of the drawing (a place shown again too) hands over a new root. + const [rebuilt, setRebuilt] = useState(0) + useEffect(() => setRebuilt((n) => n + 1), [build.root]) + const layoutKey = `${build.root?.viewId ?? ''}:${transform}:${selectedId ?? ''}:${version}:${rebuilt}` return ( { render( undefined} />) await screen.findByText(en['sheet.core_unavailable']!) expect(screen.getByRole('button', { name: en['sheet.core_retry'] })).toBeInTheDocument() - useLocaleStore.setState({ locale: 'fr' }) + act(() => useLocaleStore.setState({ locale: 'fr' })) }) it('restyles in place when the states change', async () => { diff --git a/apps/app/tests/unit/editor-annotations-tab.test.tsx b/apps/app/tests/unit/editor-annotations-tab.test.tsx index 4c1b62b0..8cf4493d 100644 --- a/apps/app/tests/unit/editor-annotations-tab.test.tsx +++ b/apps/app/tests/unit/editor-annotations-tab.test.tsx @@ -22,6 +22,7 @@ import { fr } from '@/i18n/fr' import { AnnounceContext } from '@/editor/focusRequest' import { useLocaleStore } from '@/state/localeStore' import { useAnnotationWork } from '@/editor/annotations/workStore' +import { emptyForm } from '@/editor/annotations/creation' import { ASSET, drawnText, @@ -2124,6 +2125,42 @@ describe('access labels (D12, D14, D16)', () => { expect(await label()).toBeInTheDocument() }) + it('is hidden while a creation is open', async () => { + labelled() + await mount({ text: withLink() }) + await label() + act(() => + useAnnotationWork.setState({ + creation: { + viewId: 'view-main', + frame: null, + origin: 'add', + pending: { kind: 'point', geometry: { type: 'circle', cx: 5, cy: 5, r: 2 } }, + closed: true, + form: emptyForm(store.getState().previewState!.document, 'point'), + dialog: false, + resumed: false, + }, + }), + ) + await waitFor(() => expect(screen.queryByRole('button', { name: OPEN })).toBeNull()) + act(() => useAnnotationWork.setState({ creation: null })) + expect(await label()).toBeInTheDocument() + }) + + it('measures again after a zoom and after a selection change', async () => { + labelled() + const user = userEvent.setup() + await mount({ text: withLink() }) + await label() + const settled = place.mock.calls.length + await user.click(screen.getByRole('button', { name: 'Zoom avant' })) + await waitFor(() => expect(place.mock.calls.length).toBeGreaterThan(settled)) + const zoomed = place.mock.calls.length + await user.click(await label()) + await waitFor(() => expect(place.mock.calls.length).toBeGreaterThan(zoomed)) + }) + it('on the read-only twin a label shows its view, as the chip does', async () => { labelled() await mount({ text: withLink(), readOnly: true }) diff --git a/apps/app/tests/unit/routes.EditorRoute.test.tsx b/apps/app/tests/unit/routes.EditorRoute.test.tsx index 8bc931dc..cf1ea7de 100644 --- a/apps/app/tests/unit/routes.EditorRoute.test.tsx +++ b/apps/app/tests/unit/routes.EditorRoute.test.tsx @@ -32,6 +32,18 @@ import { setSheetProvider } from '@/sheets/useSheet' import { bundledSheetProvider } from '@/sheets/provider' import { bundledSheet, loadTestSheet, minimalReport } from '../helpers/sheet' +// happy-dom has no layout: labels are placed by this mock, set by the tests that use them. +const place = vi.hoisted(() => vi.fn()) +vi.mock('@/anatomy/accessLabels', async (original) => ({ + ...(await original()), + placeAccessLabels: place, +})) +const placeAll = ({ labels }: { labels: { id: string }[] }) => ({ + placed: labels.map(({ id }) => ({ id, box: { x: 0, y: 0, w: 70, h: 20 }, leader: null })), + overflow: [], + button: null, +}) + const DISCLAIMER_FLAG = 'osteo:disclaimer-shown' let sheet: SheetIndex @@ -40,6 +52,8 @@ beforeAll(async () => { }) beforeEach(() => { + place.mockReset() + place.mockReturnValue({ placed: [], overflow: [], button: null }) useLocaleStore.setState({ locale: 'fr' }) sessionStorage.clear() sessionStorage.setItem(DISCLAIMER_FLAG, '1') @@ -339,6 +353,43 @@ describe('EditorRoute detail window stack (D15)', () => { return screen.findByRole('dialog', { name: 'Incisives' }) } + /** The label of an access, found by its name read from the drawing it sits on. */ + async function labelOf(accessId: string, within_?: HTMLElement) { + const root = within_ ?? document.body + const name = root + .querySelector(`[data-anno-id="${accessId}"]`)! + .getAttribute('data-anno-name-fr')! + return screen.findByRole('button', { + name: fr['canvas.access.open'].replace('{name}', name), + }) + } + + it('Enter on the access label opens the window; Enter on a nested label inside pushes (D12)', async () => { + place.mockImplementation(placeAll) + const user = userEvent.setup() + await mount() + await waitFor(() => + expect(document.querySelector('[data-anno-id="head-trigger"]')).not.toBeNull(), + ) + const pageLabel = await labelOf('head-trigger') + pageLabel.focus() + await user.keyboard('{Enter}') + const head = await screen.findByRole('dialog', { name: HEAD }) + await waitFor(() => + expect(head.querySelector('[data-anno-id="incisors-trigger"]')).not.toBeNull(), + ) + const nested = await within(head).findByRole('button', { + name: fr['canvas.access.open'].replace( + '{name}', + head.querySelector('[data-anno-id="incisors-trigger"]')!.getAttribute('data-anno-name-fr')!, + ), + }) + nested.focus() + await user.keyboard('{Enter}') + const dialog = await screen.findByRole('dialog', { name: 'Incisives' }) + expect(within(dialog).getByRole('button', { name: BACK })).toBeInTheDocument() + }) + it('pushes a nested view, shows the way back, and pops it with the focus on the title', async () => { const user = userEvent.setup() const dialog = await openNested()