feat(editor): references dialog over the finding, view mode
A modal Dialog replaces the citations side sheet; families open it too (isCitable). The finding dialog shows only « Références citées » and « X références », also at zero; its edit form no longer carries reference_ids. A dirty form refusing « Aller à » or « Tout afficher » closes the clean references dialog first.
This commit is contained in:
1 parent
ff21b0315e
commit
abc781df52
29 files changed
+432
-858
No files matched your search
@@ -1,4 +1,4 @@
|
||||
/** R2.4: the citations panel of one finding (board 25): contents, « Retirer », motion, closes, focus. */
|
||||
/** R2.4, Rev 5: the references dialog of one finding: contents, view mode, closes, focus. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
@@ -109,12 +109,15 @@ const ready = () =>
|
||||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
const panel = () => screen.getByTestId('editor-citations-panel')
|
||||
const hasPanel = () => screen.queryByTestId('editor-citations-panel') !== null
|
||||
const layer = () => panel().closest('[data-place="citations"]')!
|
||||
const citationsDialog = () => panel().closest('dialog')!
|
||||
const tiles = () => [...panel().querySelectorAll('ul > li')]
|
||||
const trigger = (name = '2 références') =>
|
||||
inFindingDialog().getByRole('button', { name })
|
||||
const heading = () =>
|
||||
within(panel()).getByRole('heading', { name: 'Références citées' })
|
||||
within(citationsDialog()).getByRole('heading', {
|
||||
name: 'Références du constat',
|
||||
})
|
||||
const backdrop = () => within(citationsDialog()).getByTestId('dialog-backdrop')
|
||||
const doc = () => JSON.parse(store.getState().documentText)
|
||||
const nodeA = () =>
|
||||
doc().finding_zones[0].categories[0].children[0] as {
|
||||
@@ -148,7 +151,7 @@ async function select(user: User, label: RegExp) {
|
||||
await openFinding(user, label)
|
||||
}
|
||||
|
||||
/** The sheet of Node A, open over its dialog: its first control (✕) holds the focus. */
|
||||
/** The references dialog of Node A, 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))
|
||||
@@ -161,10 +164,10 @@ const link = () =>
|
||||
})
|
||||
|
||||
const closeButton = () =>
|
||||
within(panel()).getByRole('button', { name: 'Fermer les références' })
|
||||
within(citationsDialog()).getByRole('button', { name: 'Fermer' })
|
||||
|
||||
describe('opening', () => {
|
||||
it('has no header button; only a finding opens it, its heading takes the focus after the slide', async () => {
|
||||
it('has no header button; « X références » opens a modal dialog over the finding, ✕ focused', async () => {
|
||||
const user = await mount()
|
||||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
||||
expect(hasPanel()).toBe(false)
|
||||
@@ -173,23 +176,37 @@ describe('opening', () => {
|
||||
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel')
|
||||
await user.click(trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).not.toBe(heading())
|
||||
await focusIs(closeButton)
|
||||
expect(panel()).toHaveAttribute('aria-labelledby', 'editor-citations-title')
|
||||
expect(heading()).toHaveAttribute('id', 'editor-citations-title')
|
||||
expect(citationsDialog()).toHaveAttribute(
|
||||
'aria-labelledby',
|
||||
'editor-citations-title',
|
||||
)
|
||||
expect(citationsDialog()).toHaveAttribute('data-layer')
|
||||
expect(panel()).toHaveAttribute('data-place', 'citations')
|
||||
expect(document.querySelectorAll('dialog[open]')).toHaveLength(2)
|
||||
expect(findingDialog()).not.toBe(citationsDialog())
|
||||
})
|
||||
|
||||
it('a family lists its citations read-only: no trigger, no Retirer, no panel', async () => {
|
||||
it('a family opens the same dialog with its citations', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Cat A/)
|
||||
const detail = screen.getByRole('tabpanel', { name: 'Constats' })
|
||||
expect(
|
||||
within(detail).queryByRole('button', { name: /références?$/ }),
|
||||
).toBeNull()
|
||||
expect(within(detail).getByText('Barone, Ostéologie')).toBeVisible()
|
||||
expect(
|
||||
within(detail).queryByRole('button', { name: /^Retirer/ }),
|
||||
).toBeNull()
|
||||
expect(hasPanel()).toBe(false)
|
||||
expect(inFindingDialog().queryByText('Barone, Ostéologie')).toBeNull()
|
||||
await user.click(trigger())
|
||||
await focusIs(closeButton)
|
||||
expect(panel()).toHaveTextContent('Zone A › Cat A')
|
||||
expect(tiles()).toHaveLength(2)
|
||||
expect(tiles()[0].textContent).toContain('Barone')
|
||||
expect(tiles()[1].textContent).toContain('Denoix')
|
||||
})
|
||||
|
||||
it('« 0 référence » is offered at zero and opens the empty dialog', async () => {
|
||||
const user = await mount(1280, nodeText([]))
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger('0 référence'))
|
||||
await focusIs(closeButton)
|
||||
expect(tiles()).toHaveLength(0)
|
||||
expect(panel()).toHaveTextContent('Ce constat ne cite aucune référence.')
|
||||
})
|
||||
|
||||
it('shows the path, the count, and only the references of the finding as tiles', async () => {
|
||||
@@ -205,7 +222,7 @@ describe('opening', () => {
|
||||
expect(panel()).not.toHaveTextContent('Denoix')
|
||||
})
|
||||
|
||||
it('an open tile marks the current finding and offers Modifier only', async () => {
|
||||
it('view mode: an open tile marks the current finding, « Aller à » only, no edit control', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
@@ -214,34 +231,23 @@ describe('opening', () => {
|
||||
expect(
|
||||
within(tile).getAllByRole('button', { name: /^Aller à / }),
|
||||
).toHaveLength(2)
|
||||
expect(within(tile).getByRole('button', { name: 'Modifier' })).toBeVisible()
|
||||
for (const absent of [
|
||||
'Modifier',
|
||||
'Retirer de ce constat',
|
||||
'Supprimer',
|
||||
'Monter',
|
||||
'Descendre',
|
||||
]) {
|
||||
expect(within(panel()).queryByRole('button', { name: absent })).toBeNull()
|
||||
expect(
|
||||
within(citationsDialog()).queryByRole('button', { name: absent }),
|
||||
).toBeNull()
|
||||
}
|
||||
expect(within(citationsDialog()).queryByRole('searchbox')).toBeNull()
|
||||
expect(within(citationsDialog()).queryByRole('textbox')).toBeNull()
|
||||
expect(within(citationsDialog()).queryByRole('combobox')).toBeNull()
|
||||
})
|
||||
|
||||
it('has no search, no add control; « Modifier » opens the reference dialog over the sheet', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(within(panel()).queryByRole('searchbox')).toBeNull()
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: /Ajouter/ }),
|
||||
).toBeNull()
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(within(panel()).getByRole('button', { name: 'Modifier' }))
|
||||
expect(document.querySelectorAll('dialog[open]')).toHaveLength(3)
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Modifier la référence' }),
|
||||
).toBeVisible()
|
||||
expect(panel().querySelector('[id$="-citation"]')).toBeNull()
|
||||
})
|
||||
|
||||
it('ids stay unique with the Références tab mounted and the panel open (P14)', async () => {
|
||||
it('ids stay unique with the Références tab mounted and the dialog open (P14)', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
await user.click(screen.getByRole('button', { name: /^Barone/ }))
|
||||
@@ -267,26 +273,12 @@ describe('opening', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('motion', () => {
|
||||
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()
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
expect(slid()).toMatch(/translateX\(/)
|
||||
expect(screen.getByTestId('references-scrim')).toBeInTheDocument()
|
||||
expect(panel().closest('header')).toBeNull()
|
||||
await focusIs(closeButton)
|
||||
await waitFor(() => expect(slid()).not.toMatch(/translateX\([1-9]/))
|
||||
})
|
||||
|
||||
it('reduced motion: no slide, the same lifecycle', async () => {
|
||||
describe('reduced motion', () => {
|
||||
it('the same lifecycle: open, close, the trigger takes the focus back', async () => {
|
||||
setReducedMotion(true)
|
||||
const user = await mount()
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
expect(slid()).not.toMatch(/translateX\(/)
|
||||
await focusIs(closeButton)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
@@ -302,7 +294,7 @@ const MODES = [
|
||||
describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
beforeEach(() => setReducedMotion(reduced))
|
||||
|
||||
it('✕, Escape and the scrim each close it after the exit: the trigger holds the focus', async () => {
|
||||
it('✕, Escape and the backdrop each close it after the exit: the trigger holds the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
@@ -315,7 +307,7 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
await focusIs(() => trigger())
|
||||
await user.click(trigger())
|
||||
await focusIs(closeButton)
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
fireEvent.click(backdrop())
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
@@ -350,14 +342,14 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
await focusIs(() =>
|
||||
within(tabPanel).getByRole('heading', { name: 'Références' }),
|
||||
)
|
||||
// Filtered by the finding the sheet belonged to: its two citations (R2F-6).
|
||||
// Filtered by the finding the dialog belonged to: its two citations (R2F-6).
|
||||
expect(within(tabPanel).getAllByRole('listitem')).toHaveLength(2)
|
||||
expect(
|
||||
within(tabPanel).getByText('Références du constat : Node A'),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('« Aller à » a citer from a panel tile closes the sheet and opens that finding in its dialog', async () => {
|
||||
it('« Aller à » a citer from a tile closes the dialog and opens that finding in its dialog', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
@@ -387,7 +379,7 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
expect(document.activeElement).not.toBe(document.body)
|
||||
})
|
||||
|
||||
it('below 640 px the sheet opens from « Plus » > Constats and closes on its own', async () => {
|
||||
it('below 640 px the dialog 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' }))
|
||||
@@ -401,7 +393,7 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
})
|
||||
|
||||
describe('the exit', () => {
|
||||
it('a sheet playing its exit is inert, its trigger reads « expanded » until it is gone', async () => {
|
||||
it('a dialog playing its exit is inert, its trigger reads « expanded » until it is gone', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
@@ -416,14 +408,14 @@ describe('the exit', () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
fireEvent.keyDown(layer(), { key: 'Escape' })
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
fireEvent.keyDown(citationsDialog(), { key: 'Escape' })
|
||||
fireEvent.click(backdrop())
|
||||
await closed()
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
|
||||
it('Ctrl+Z is ignored while the sheet is open: Défaire is unreachable under a dialog', async () => {
|
||||
it('Ctrl+Z is ignored while the dialog is open: Défaire is unreachable under a dialog', async () => {
|
||||
const user = await mount()
|
||||
act(() => void commitMove(40))
|
||||
await openFromFinding(user)
|
||||
@@ -434,7 +426,7 @@ describe('the exit', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the library and the history around the panel', () => {
|
||||
describe('the library and the history around the dialog', () => {
|
||||
it('« Tout afficher » clears the search of the tab and keeps its sort, open tiles kept (P4)', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
@@ -489,7 +481,7 @@ describe('the library and the history around the panel', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the sheet cannot remove a citation (the edit form does)', () => {
|
||||
describe('the view mode cannot remove a citation', () => {
|
||||
it('no tile offers « Retirer de ce constat »', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
@@ -538,7 +530,7 @@ function cite(ids: string[]) {
|
||||
}
|
||||
|
||||
describe('the panel review fixes', () => {
|
||||
it('the sheet is a modal dialog named by its title (M4: no announcement needed)', async () => {
|
||||
it('the dialog is modal and named by its title (M4: no announcement needed)', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
const dialog = panel().closest('dialog')!
|
||||
|
||||
Reference in new issue
Block a user