feat(editor): finding dialog and citations side sheet in the history
Constats opens each element in one modal dialog (view, edit with a local draft, creation) driven by the editor view layer of the browser history. The citations panel becomes a modal side sheet stacked over it; its geometry, exit machinery and page inertness are removed. Back and Forward restore the layers, a dirty form asks first.
This commit is contained in:
1 parent
8e4f02620a
commit
18085cecf8
50 files changed
+2642
-1504
No files matched your search
@@ -19,6 +19,11 @@ import {
|
||||
serverHas,
|
||||
store,
|
||||
} from '../helpers/editorHarness'
|
||||
import {
|
||||
findingDialog,
|
||||
inFindingDialog,
|
||||
openFinding,
|
||||
} from '../helpers/findingDialog'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
import { setReducedMotion } from '../helpers/motion'
|
||||
|
||||
@@ -107,10 +112,7 @@ const hasPanel = () => screen.queryByTestId('editor-citations-panel') !== null
|
||||
const layer = () => panel().closest('[data-place="citations"]')!
|
||||
const tiles = () => [...panel().querySelectorAll('ul > li')]
|
||||
const trigger = (name = '2 références') =>
|
||||
within(screen.getByRole('tabpanel', { name: 'Constats' })).getByRole(
|
||||
'button',
|
||||
{ name },
|
||||
)
|
||||
inFindingDialog().getByRole('button', { name })
|
||||
const heading = () =>
|
||||
within(panel()).getByRole('heading', { name: 'Références citées' })
|
||||
const doc = () => JSON.parse(store.getState().documentText)
|
||||
@@ -119,6 +121,13 @@ const nodeA = () =>
|
||||
reference_ids: string[]
|
||||
review_status: string
|
||||
}
|
||||
const removeNodeA = () =>
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a', 'fnode-a'] },
|
||||
})
|
||||
})
|
||||
const closed = () => waitFor(() => expect(hasPanel()).toBe(false))
|
||||
const focusIs = (element: () => Element) =>
|
||||
waitFor(() => expect(document.activeElement).toBe(element()))
|
||||
@@ -133,21 +142,17 @@ async function mount(width = 1280, text = nodeText()) {
|
||||
|
||||
type User = ReturnType<typeof userEvent.setup>
|
||||
|
||||
/** The finding dialog of `label` (a row activation opens it, R2F-3). */
|
||||
async function select(user: User, label: RegExp) {
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
const family = screen.getByRole('treeitem', { name: /Cat A/ })
|
||||
if (!screen.queryByRole('treeitem', { name: /Node A/ })) {
|
||||
await user.click(family)
|
||||
await user.keyboard('{ArrowRight}')
|
||||
}
|
||||
await user.click(screen.getByRole('treeitem', { name: label }))
|
||||
await openFinding(user, label)
|
||||
}
|
||||
|
||||
/** The panel of Node A, open and in place: its heading holds the focus. */
|
||||
/** The sheet of Node A, open over its dialog: its first control (✕) holds the focus. */
|
||||
async function openFromFinding(user: User, name = '2 références') {
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger(name))
|
||||
await focusIs(heading)
|
||||
await focusIs(closeButton)
|
||||
}
|
||||
|
||||
const link = () =>
|
||||
@@ -169,7 +174,7 @@ describe('opening', () => {
|
||||
await user.click(trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).not.toBe(heading())
|
||||
await focusIs(heading)
|
||||
await focusIs(closeButton)
|
||||
expect(panel()).toHaveAttribute('aria-labelledby', 'editor-citations-title')
|
||||
})
|
||||
|
||||
@@ -261,7 +266,7 @@ describe('opening', () => {
|
||||
})
|
||||
|
||||
describe('motion', () => {
|
||||
const slid = () => (layer().firstElementChild as HTMLElement).style.transform
|
||||
const slid = () => (layer() as HTMLElement).style.transform
|
||||
|
||||
it('slides in from the right and fades the scrim, the page behind inert', async () => {
|
||||
const user = await mount()
|
||||
@@ -270,8 +275,8 @@ describe('motion', () => {
|
||||
expect(slid()).toMatch(/translateX\(/)
|
||||
expect(screen.getByTestId('references-scrim')).toBeInTheDocument()
|
||||
expect(panel().closest('header')).toBeNull()
|
||||
await focusIs(heading)
|
||||
expect(slid()).not.toMatch(/translateX\([1-9]/)
|
||||
await focusIs(closeButton)
|
||||
await waitFor(() => expect(slid()).not.toMatch(/translateX\([1-9]/))
|
||||
})
|
||||
|
||||
it('reduced motion: no slide, the same lifecycle', async () => {
|
||||
@@ -280,7 +285,7 @@ describe('motion', () => {
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
expect(slid()).not.toMatch(/translateX\(/)
|
||||
await focusIs(heading)
|
||||
await focusIs(closeButton)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
@@ -302,23 +307,26 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
await user.click(trigger())
|
||||
await focusIs(heading)
|
||||
await focusIs(closeButton)
|
||||
await user.keyboard('{Escape}')
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
await user.click(trigger())
|
||||
await focusIs(heading)
|
||||
await focusIs(closeButton)
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('Escape with nothing focused closes it too', async () => {
|
||||
it('the platform close request closes it with nothing focused (no key reaches the page)', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
;(document.activeElement as HTMLElement).blur()
|
||||
await user.keyboard('{Escape}')
|
||||
fireEvent(
|
||||
panel().closest('dialog')!,
|
||||
new Event('cancel', { cancelable: true }),
|
||||
)
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
@@ -343,18 +351,6 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
expect(within(tabPanel).getAllByRole('listitem')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('selecting a tab closes it, the new tab button holds the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
await closed()
|
||||
expect(screen.getByRole('tab', { name: 'Vérification' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Vérification' }))
|
||||
})
|
||||
|
||||
it('« Aller à » a citer from a panel tile closes it and lands on that finding', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
@@ -365,100 +361,62 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
await focusIs(() => screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
})
|
||||
|
||||
it('the finding vanishing closes it, the active tab button holds the focus', async () => {
|
||||
it('the finding vanishing closes both layers and says so once the dialogs are gone', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
removeNodeA()
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Constats' }))
|
||||
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||
await waitFor(() =>
|
||||
expect(live()).toHaveTextContent("Ce constat n'existe plus"),
|
||||
)
|
||||
expect(document.activeElement).not.toBe(document.body)
|
||||
})
|
||||
|
||||
it('below 640 px the active tab sits under « Plus »: it holds the focus', async () => {
|
||||
it('below 640 px the sheet opens from « Plus » > Constats and closes on its own', async () => {
|
||||
const user = await mount(375)
|
||||
await user.click(screen.getByRole('button', { name: 'Plus' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
await user.keyboard('{ArrowRight}')
|
||||
await user.click(screen.getByRole('treeitem', { name: /Node A/ }))
|
||||
await openFinding(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
await focusIs(heading)
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
await focusIs(closeButton)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('button', { name: 'Plus' }))
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
})
|
||||
|
||||
describe('the exit', () => {
|
||||
it('keeps the page and the panel inert until it is over, then lifts it', async () => {
|
||||
it('a sheet playing its exit is inert, its trigger reads « expanded » until it is gone', async () => {
|
||||
const user = await mount()
|
||||
const page = () =>
|
||||
screen.getAllByRole('tabpanel', { hidden: true })[0].parentElement
|
||||
await openFromFinding(user)
|
||||
expect(page()).toHaveAttribute('inert')
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
await user.click(closeButton())
|
||||
expect(hasPanel()).toBe(true)
|
||||
expect(layer()).toHaveAttribute('inert')
|
||||
expect(page()).toHaveAttribute('inert')
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(panel().closest('dialog')).toHaveAttribute('inert')
|
||||
await closed()
|
||||
expect(page()).not.toHaveAttribute('inert')
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('a second close is a no-op, a tab choice replaces the pending move', async () => {
|
||||
it('a second close during the exit finds no layer and does nothing', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
fireEvent.keyDown(layer(), { key: 'Escape' })
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
await closed()
|
||||
expect(screen.getByRole('tab', { name: 'Vérification' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Vérification' }))
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
|
||||
it('leaves a focus the user placed elsewhere during the exit alone', async () => {
|
||||
it('Ctrl+Z is ignored while the sheet is open: Défaire is unreachable under a dialog', async () => {
|
||||
const user = await mount()
|
||||
act(() => void commitMove(40))
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
const save = screen.getByRole('button', { name: /Enregistrer/ })
|
||||
act(() => save.focus())
|
||||
await closed()
|
||||
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||
expect(document.activeElement).toBe(save)
|
||||
})
|
||||
|
||||
it('Défaire and Refaire stay usable while it is open', async () => {
|
||||
const user = await mount()
|
||||
act(() => void commitMove(40))
|
||||
await openFromFinding(user)
|
||||
const undo = screen.getByRole('button', { name: /Défaire/ })
|
||||
await waitFor(() => expect(undo).toBeEnabled())
|
||||
await user.click(undo)
|
||||
const before = store.getState().undo.length
|
||||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||||
expect(store.getState().undo.length).toBe(before)
|
||||
expect(hasPanel()).toBe(true)
|
||||
expect(screen.getByRole('button', { name: /Refaire/ })).toBeEnabled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -487,7 +445,7 @@ describe('the library and the history around the panel', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('an undo that removes the finding closes it: the active tab button holds the focus (P6)', async () => {
|
||||
it('an undo that removes the finding closes both layers (gone rule)', async () => {
|
||||
const user = await mount()
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
@@ -509,10 +467,11 @@ describe('the library and the history around the panel', () => {
|
||||
})
|
||||
await select(user, /Node B/)
|
||||
await user.click(trigger('1 référence'))
|
||||
await focusIs(heading)
|
||||
await focusIs(closeButton)
|
||||
act(() => void store.getState().undoStep())
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Constats' }))
|
||||
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||
expect(document.activeElement).not.toBe(document.body)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -593,8 +552,8 @@ describe('« Retirer de ce constat »', () => {
|
||||
expect(hasPanel()).toBe(true)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
// the trigger is gone with its count: the active tab button takes the focus (P6)
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Constats' }))
|
||||
// the trigger is gone with its count: the focus stays inside the finding dialog
|
||||
expect(findingDialog()!.contains(document.activeElement)).toBe(true)
|
||||
})
|
||||
|
||||
it('a dangling id is a « Référence introuvable » row with Retirer, counted like the rest', async () => {
|
||||
@@ -647,15 +606,10 @@ describe("a tile in edit when the panel closes (P22'')", () => {
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
|
||||
it('a refused draft cancels a tab switch and « Tout afficher »', async () => {
|
||||
it('a refused draft cancels « Tout afficher »', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
expect(screen.getByRole('tab', { name: 'Constats' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
@@ -668,20 +622,12 @@ describe("a tile in edit when the panel closes (P22'')", () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
removeNodeA()
|
||||
await closed()
|
||||
expect(
|
||||
screen.getByText(/Saisie non appliquée : Citation/),
|
||||
).toBeInTheDocument()
|
||||
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||
await waitFor(() =>
|
||||
expect(live()).toHaveTextContent(/Saisie non appliquée : Citation/),
|
||||
)
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
|
||||
@@ -695,14 +641,16 @@ describe("a tile in edit when the panel closes (P22'')", () => {
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
|
||||
it('Ctrl+Z reverts a reference edit while the panel is open', async () => {
|
||||
it('a committed tile edit is one entry, reverted by Défaire once the sheet is closed', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
await user.type(field, 'Neuf')
|
||||
fireEvent.blur(field)
|
||||
expect(doc().references[0].citation).toBe('Neuf')
|
||||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
})
|
||||
@@ -758,16 +706,6 @@ describe('one user edit, one history entry in the panel (C1)', () => {
|
||||
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)
|
||||
@@ -776,15 +714,18 @@ describe('one user edit, one history entry in the panel (C1)', () => {
|
||||
})
|
||||
await closed()
|
||||
expect(entries() - before).toBe(2)
|
||||
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||
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 () => {
|
||||
it('the sheet is a modal dialog named by its title (M4: no announcement needed)', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(live()?.textContent?.trim()).toBe('Références citées')
|
||||
const dialog = panel().closest('dialog')!
|
||||
expect(dialog).toHaveAttribute('aria-labelledby', 'editor-citations-title')
|
||||
expect(dialog).toHaveAttribute('open')
|
||||
})
|
||||
|
||||
it('every « Aller à » names its citer (M6)', async () => {
|
||||
@@ -835,20 +776,4 @@ describe('the panel review fixes', () => {
|
||||
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