fix(editor): one history entry per reference edit, focus kept
Final review fixes. « Terminer » and every panel close re-committed the edited field against a stale value, adding a second identical history entry so the first « Défaire » seemed to do nothing: the tile now reads the latest applied value (tests assert the undo-length delta). A tile leaving the search on « Terminer » stays pinned until the next view change and keeps focus; « Ajouter la référence » resets search and sort and focuses the new tile. Also: refused draft dropped on a read-only flip is announced; arrow keys respect a refused tab switch; pinned index kept across read-only; the panel announces « Références citées »; search text inserted literally; « Aller à » names its citer; the edit header's name starts with « Terminer. »; undo removing the focused panel tile moves focus per P20; no-result announced once; docs corrected. Gates: typecheck, lint, test:run (app 1510), build, e2e:ui 251; e2e:shell 16 specs (admin and editor-equine excluded): 117 passed / 108 skipped / 1 failed (crossing:211 stuck on the MFA step-up screen before the editor), rerun alone 11 passed; full-row guard: no pre-existing row changed in any table.
This commit is contained in:
1 parent
2182307c62
commit
1bf27014b3
21 files changed
+677
-136
No files matched your search
@@ -9,6 +9,7 @@ import {
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
@@ -205,7 +206,7 @@ describe('opening', () => {
|
||||
const tile = tiles()[0] as HTMLElement
|
||||
expect(within(tile).getByText('ce constat')).toBeInTheDocument()
|
||||
expect(
|
||||
within(tile).getAllByRole('button', { name: 'Aller à' }),
|
||||
within(tile).getAllByRole('button', { name: /^Aller à / }),
|
||||
).toHaveLength(2)
|
||||
expect(within(tile).getByRole('button', { name: 'Modifier' })).toBeVisible()
|
||||
expect(
|
||||
@@ -358,7 +359,7 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
const go = within(panel()).getAllByRole('button', { name: 'Aller à' })
|
||||
const go = within(panel()).getAllByRole('button', { name: /^Aller à / })
|
||||
await user.click(go[0])
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
@@ -705,3 +706,149 @@ describe("a tile in edit when the panel closes (P22'')", () => {
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
})
|
||||
|
||||
const live = () => document.querySelector('p.sr-only[aria-live="polite"]')
|
||||
const entries = () => store.getState().undo.length
|
||||
const undo = () => act(() => store.getState().undoStep())
|
||||
const nodeKey: ElementKey = {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
}
|
||||
|
||||
/** The finding node cites `ids` from now on (one history entry). */
|
||||
function cite(ids: string[]) {
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'update',
|
||||
key: nodeKey,
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: {
|
||||
...doc().finding_zones[0].categories[0].children[0],
|
||||
reference_ids: ids,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
describe('one user edit, one history entry in the panel (C1)', () => {
|
||||
/** Opens Barone, enters edit and types a URL; the field keeps the focus. */
|
||||
async function typeUrl(user: User) {
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(within(panel()).getByRole('button', { name: 'Modifier' }))
|
||||
const url = panel().querySelector<HTMLInputElement>(
|
||||
'#panel-reference-0-ref-a-url',
|
||||
)!
|
||||
await user.type(url, 'https://a.org/')
|
||||
expect(document.activeElement).toBe(url)
|
||||
return entries()
|
||||
}
|
||||
|
||||
it('✕ pressed with the field still focused (iPadOS) adds one entry', async () => {
|
||||
const user = await mount()
|
||||
const before = await typeUrl(user)
|
||||
fireEvent.click(closeButton())
|
||||
await closed()
|
||||
expect(entries() - before).toBe(1)
|
||||
expect(doc().references[0].url).toBe('https://a.org/')
|
||||
undo()
|
||||
expect(doc().references[0].url).toBeNull()
|
||||
})
|
||||
|
||||
it('a tab switch with the field still focused adds one entry', async () => {
|
||||
const user = await mount()
|
||||
const before = await typeUrl(user)
|
||||
fireEvent.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
await closed()
|
||||
expect(entries() - before).toBe(1)
|
||||
undo()
|
||||
expect(doc().references[0].url).toBeNull()
|
||||
})
|
||||
|
||||
it('a forced close (finding vanished) adds the edit once, besides the removal', async () => {
|
||||
const user = await mount()
|
||||
const before = await typeUrl(user)
|
||||
act(() => {
|
||||
store.getState().commit({ op: 'remove', key: nodeKey })
|
||||
})
|
||||
await closed()
|
||||
expect(entries() - before).toBe(2)
|
||||
expect(doc().references[0].url).toBe('https://a.org/')
|
||||
})
|
||||
})
|
||||
|
||||
describe('the panel review fixes', () => {
|
||||
it('opening announces the panel title, not the tab name (M4)', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(live()?.textContent?.trim()).toBe('Références citées')
|
||||
})
|
||||
|
||||
it('every « Aller à » names its citer (M6)', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
const names = within(panel())
|
||||
.getAllByRole('button', { name: /^Aller à / })
|
||||
.map((button) => button.getAttribute('aria-label'))
|
||||
expect(new Set(names).size).toBe(names.length)
|
||||
expect(names).toEqual([
|
||||
'Aller à Zone A › Cat A',
|
||||
'Aller à Zone A › Cat A › Node A',
|
||||
])
|
||||
})
|
||||
|
||||
it('an undo that removes the focused tile moves the focus to the next one (M8)', async () => {
|
||||
const user = await mount(1280, nodeText(['ref-c']))
|
||||
cite(['ref-a', 'ref-c'])
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
expect(document.activeElement).toBe(tiles()[0].querySelector('button'))
|
||||
undo()
|
||||
expect(tiles()).toHaveLength(1)
|
||||
await focusIs(() => tiles()[0].querySelector('button')!)
|
||||
expect(tiles()[0]).toHaveTextContent('Code rural')
|
||||
})
|
||||
|
||||
it('an undo that removes the last focused tile moves the focus to the previous one (M8)', async () => {
|
||||
const user = await mount(1280, nodeText(['ref-a']))
|
||||
cite(['ref-a', 'ref-c'])
|
||||
await openFromFinding(user)
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', { name: /^Code rural/ }),
|
||||
)
|
||||
undo()
|
||||
expect(tiles()).toHaveLength(1)
|
||||
await focusIs(() => tiles()[0].querySelector('button')!)
|
||||
expect(tiles()[0]).toHaveTextContent('Barone')
|
||||
})
|
||||
|
||||
it('an undo that removes the only tile puts the focus on the heading (M8)', async () => {
|
||||
const user = await mount(1280, nodeText([]))
|
||||
cite(['ref-a'])
|
||||
await openFromFinding(user, '1 référence')
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
undo()
|
||||
expect(tiles()).toHaveLength(0)
|
||||
await focusIs(heading)
|
||||
})
|
||||
|
||||
it('an arrow key in the tab row leaves the focus on the refused field (M2)', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(within(panel()).getByRole('button', { name: 'Modifier' }))
|
||||
const field = panel().querySelector<HTMLTextAreaElement>(
|
||||
'#panel-reference-0-ref-a-citation',
|
||||
)!
|
||||
await user.clear(field)
|
||||
const tab = screen.getByRole('tab', { name: 'Constats' })
|
||||
fireEvent.keyDown(tab, { key: 'ArrowRight' })
|
||||
expect(hasPanel()).toBe(true)
|
||||
expect(document.activeElement).toBe(field)
|
||||
expect(tab).toHaveAttribute('aria-selected', 'true')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user