fix(editor): Task 2 review round 1, trace calls, form hooks, keyboard proof
This commit is contained in:
1 parent
c893dec60b
commit
b703333b20
15 files changed
+476
-261
No files matched your search
@@ -330,6 +330,45 @@ describe('read-only flip and the gone rule', () => {
|
||||
expect(field).toHaveFocus()
|
||||
})
|
||||
|
||||
it('a flip to read-only while « Modifier » holds the focus keeps it in the dialog (the tab row is inert)', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Cat A/)
|
||||
const button = inDialog().getByRole('button', { name: 'Modifier' })
|
||||
button.focus()
|
||||
expect(button).toHaveFocus()
|
||||
act(() => {
|
||||
setWidth(900)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
// The edit-only actions left the page: the focus moved to the dialog's first control.
|
||||
expect(button.isConnected).toBe(false)
|
||||
expect(findingDialog()!.contains(document.activeElement)).toBe(true)
|
||||
})
|
||||
|
||||
it('a forced close of a dirty form says the dropped draft once, with the gone text', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.type(nameField(), ' bis')
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
await closed()
|
||||
const live = () => document.querySelector('p.sr-only[aria-live="polite"]')!
|
||||
await waitFor(() =>
|
||||
expect(live().textContent).toBe(
|
||||
"Saisie abandonnée. Ce constat n'existe plus",
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('an element that vanishes closes its dialog by replace and says so', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Node A/)
|
||||
|
||||
@@ -13,6 +13,8 @@ import type {
|
||||
AnatomicalSheetDocument,
|
||||
ElementKey,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import { findingLayerOf } from '@/editor/findingLayer'
|
||||
import { testLayer } from '../helpers/findingsHost'
|
||||
import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
||||
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
||||
import EditorTabBody from '@/components/editor/EditorTabBody'
|
||||
@@ -115,7 +117,7 @@ describe('focus requests', () => {
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'node-a'],
|
||||
}
|
||||
render(<FindingsTab {...base} focus={request(key)} />)
|
||||
render(<FindingsTab {...base} layer={testLayer} focus={request(key)} />)
|
||||
const item = await screen.findByRole('treeitem', { name: /Nœud A/ })
|
||||
expect(item.getAttribute('aria-selected')).toBe('true')
|
||||
await waitFor(() => expect(document.activeElement).toBe(item))
|
||||
@@ -210,7 +212,7 @@ describe('focus requests', () => {
|
||||
const gone: ElementKey = { kind: 'zone', id: 'zone-gone' }
|
||||
render(
|
||||
<FocusConsumedContext value={consumed}>
|
||||
<FindingsTab {...base} focus={request(gone, 4)} />
|
||||
<FindingsTab {...base} layer={testLayer} focus={request(gone, 4)} />
|
||||
</FocusConsumedContext>,
|
||||
)
|
||||
await waitFor(() => expect(consumed).toHaveBeenCalledWith(4, 'none'))
|
||||
@@ -268,7 +270,7 @@ function Probe({ go, tier }: { go: EditorTarget; tier: 'wide' | 'small' }) {
|
||||
visited={state.visitedTabs}
|
||||
{...base}
|
||||
navigate={nav.navigate}
|
||||
openCitations={nav.openCitations}
|
||||
layer={findingLayerOf(nav)}
|
||||
focus={state.focus}
|
||||
annotations={{
|
||||
section: state.section,
|
||||
@@ -388,6 +390,9 @@ describe('a request that finds nothing', () => {
|
||||
const key: ElementKey = { kind: 'zone', id: 'zone-a' }
|
||||
render(<Probe go={targetOfKey(key)} tier="wide" />)
|
||||
await user.click(screen.getByText('go'))
|
||||
// « Aller à » opens the element's dialog; closed, its row holds the focus.
|
||||
const dialog = await screen.findByRole('dialog')
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Fermer' }))
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('treeitem', { name: /Zone A/ }),
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
store,
|
||||
versionAnswer,
|
||||
} from '../helpers/editorHarness'
|
||||
import { testLayer } from '../helpers/findingsHost'
|
||||
import { openFinding } from '../helpers/findingDialog'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
@@ -513,6 +514,7 @@ describe('a request reaches only its owner', () => {
|
||||
readOnly={false}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
layer={testLayer}
|
||||
focus={{
|
||||
target: targetOfKey({
|
||||
kind: 'finding',
|
||||
|
||||
Reference in new issue
Block a user