test(app): access labels open the bilan window by keyboard

This commit is contained in:
bchanot committed 2026-11-23 18:39:37 +01:00
1 parent e064a4eed0
commit 819654fd11
4 files changed
+93 -2

No files matched your search

@@ -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 (
<AccessLabels
box={box}
@@ -259,7 +259,7 @@ describe('AnatomyCanvas', () => {
render(<AnatomyCanvas index={down} viewId="main" states={new Map()} onZoneClick={() => 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 () => {
@@ -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 })
@@ -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<typeof import('@/anatomy/accessLabels')>()),
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()