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
@@ -1,124 +0,0 @@
|
||||
/** R2.4: the exit coordinator of the citations panel (P9, P28) and the gates it feeds. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
renderHook,
|
||||
render,
|
||||
screen,
|
||||
} from '@testing-library/react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
ReadOnlyContext,
|
||||
ReferencesOpenContext,
|
||||
useDecisionsOpen,
|
||||
} from '@/editor/editingContext'
|
||||
import {
|
||||
PANEL_EXIT_S,
|
||||
useCitationsExit,
|
||||
type PendingClose,
|
||||
} from '@/editor/useCitationsExit'
|
||||
|
||||
beforeEach(() => vi.useFakeTimers())
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
const move = (kind: PendingClose['kind']): PendingClose => ({
|
||||
action: { type: 'close_citations' },
|
||||
kind,
|
||||
text: kind,
|
||||
})
|
||||
|
||||
describe('useCitationsExit', () => {
|
||||
it('applies the pending move once, from the callback', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('citations_closed')))
|
||||
expect(result.current.exiting).toBe(true)
|
||||
act(() => result.current.complete())
|
||||
act(() => result.current.complete())
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
expect(apply).toHaveBeenCalledWith(move('citations_closed'))
|
||||
expect(result.current.exiting).toBe(false)
|
||||
})
|
||||
|
||||
it('applies it from the one-shot timer when the callback never fires', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('show_all')))
|
||||
act(() => void vi.advanceTimersByTime(PANEL_EXIT_S * 1000 + 99))
|
||||
expect(apply).not.toHaveBeenCalled()
|
||||
act(() => void vi.advanceTimersByTime(2))
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
act(() => result.current.complete())
|
||||
act(() => void vi.advanceTimersByTime(1000))
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('a callback that comes first cancels the timer', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('go_to')))
|
||||
act(() => result.current.complete())
|
||||
act(() => void vi.advanceTimersByTime(1000))
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('a second close is a no-op, a tab choice replaces the move', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('citations_closed')))
|
||||
act(() => result.current.record(move('show_all')))
|
||||
expect(result.current.busy()).toBe(true)
|
||||
act(() => result.current.record(move('tab_selected')))
|
||||
act(() => result.current.complete())
|
||||
expect(apply).toHaveBeenCalledWith(move('tab_selected'))
|
||||
})
|
||||
|
||||
it('a tab choice keeps the note of a forced close it replaces', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
const note = 'Saisie non appliquée : Citation'
|
||||
act(() => result.current.record({ ...move('citations_closed'), note }))
|
||||
act(() => result.current.record(move('tab_selected')))
|
||||
act(() => result.current.complete())
|
||||
expect(apply).toHaveBeenCalledWith({ ...move('tab_selected'), note })
|
||||
})
|
||||
|
||||
it('a timer left running does not fire after the editor is left', () => {
|
||||
const apply = vi.fn()
|
||||
const { result, unmount } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('citations_closed')))
|
||||
unmount()
|
||||
act(() => void vi.advanceTimersByTime(1000))
|
||||
expect(apply).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('useDecisionsOpen while the citations panel is open', () => {
|
||||
const key: ElementKey = { kind: 'finding', zone_id: 'z', path: ['c', 'n'] }
|
||||
const Probe = () => <p>{useDecisionsOpen() ? 'open' : 'held'}</p>
|
||||
const within = (readOnly: boolean, citationsOf: ElementKey | null) =>
|
||||
render(
|
||||
<ReadOnlyContext value={readOnly}>
|
||||
<ReferencesOpenContext value={citationsOf}>
|
||||
<Probe />
|
||||
</ReferencesOpenContext>
|
||||
</ReadOnlyContext>,
|
||||
)
|
||||
|
||||
it('holds every decision dialog back, panel open or still leaving (no modal in an inert page)', () => {
|
||||
within(false, key)
|
||||
expect(screen.getByText('held')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('lets them open once the panel is gone, and never while read-only', () => {
|
||||
within(false, null)
|
||||
expect(screen.getByText('open')).toBeInTheDocument()
|
||||
cleanup()
|
||||
within(true, null)
|
||||
expect(screen.getByText('held')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,53 +0,0 @@
|
||||
/** R2.4 fix: the layer's heading focus survives a reopen during a slow exit; it fits the viewport. */
|
||||
import type { ComponentProps } from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
||||
import { AnimatePresence } from 'motion/react'
|
||||
import CitationsLayer from '@/components/editor/references/CitationsLayer'
|
||||
import '../helpers/motion'
|
||||
|
||||
vi.mock('@/components/editor/references/CitationsPanel', () => ({
|
||||
default: () => (
|
||||
<h2 tabIndex={-1} data-place-heading>
|
||||
Panel
|
||||
</h2>
|
||||
),
|
||||
}))
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
const props: ComponentProps<typeof CitationsLayer> = {
|
||||
readOnly: false,
|
||||
citedBy: { kind: 'finding', zone_id: 'z', path: ['c', 'n'] },
|
||||
onClose: () => undefined,
|
||||
onGone: () => undefined,
|
||||
onShowAll: () => undefined,
|
||||
navigate: () => undefined,
|
||||
registerCanLeave: () => undefined,
|
||||
}
|
||||
|
||||
const harness = (show: boolean) => (
|
||||
<AnimatePresence>
|
||||
{show && <CitationsLayer key="citations" {...props} />}
|
||||
</AnimatePresence>
|
||||
)
|
||||
const heading = () => screen.getByRole('heading', { name: 'Panel' })
|
||||
|
||||
describe('CitationsLayer', () => {
|
||||
it('focuses its heading again when reopened with the same key during the exit', async () => {
|
||||
const view = render(harness(true))
|
||||
await waitFor(() => expect(document.activeElement).toBe(heading()))
|
||||
;(document.activeElement as HTMLElement).blur()
|
||||
view.rerender(harness(false))
|
||||
view.rerender(harness(true))
|
||||
await waitFor(() => expect(document.activeElement).toBe(heading()))
|
||||
})
|
||||
|
||||
it('writes a pixel height on the panel, never on the page', async () => {
|
||||
render(harness(true))
|
||||
const panel = heading().closest('[data-place="citations"]')!
|
||||
.firstElementChild as HTMLElement
|
||||
expect(panel.style.height).toMatch(/^\d+(\.\d+)?px$/)
|
||||
expect(document.documentElement.style.height).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -15,6 +15,7 @@ import ModalDialog from '@/components/ui/ModalDialog'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, edit, insert, point } from '../helpers/editorFixtures'
|
||||
import { resetStore, serverHas, store } from '../helpers/editorHarness'
|
||||
import { openFinding } from '../helpers/findingDialog'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
@@ -142,9 +143,7 @@ const citations = () => screen.queryByTestId('editor-citations-panel')
|
||||
/** Constats, the node selected, its « 1 référence » trigger pressed. */
|
||||
async function openCitations(user: ReturnType<typeof userEvent.setup>) {
|
||||
await user.click(screen.getByRole('tab', { 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(screen.getByRole('button', { name: '1 référence' }))
|
||||
expect(citations()).not.toBeNull()
|
||||
}
|
||||
@@ -277,15 +276,21 @@ describe('Escape with the focus on the page', () => {
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('the citations panel open: it closes, the annotation selection is kept', async () => {
|
||||
it('the citations sheet open: Escape closes it only, the annotation selection is kept', async () => {
|
||||
const user = await mount(WITH_NODE())
|
||||
await select(user)
|
||||
await openCitations(user)
|
||||
const trigger = screen.getByRole('button', { name: '1 référence' })
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'true')
|
||||
escape(document.body)
|
||||
await user.keyboard('{Escape}')
|
||||
await waitFor(() => expect(citations()).toBeNull())
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'false')
|
||||
// the finding dialog under the sheet is still there: a second Escape closes it
|
||||
expect(document.querySelector('dialog[open]')).not.toBeNull()
|
||||
await user.keyboard('{Escape}')
|
||||
await waitFor(() =>
|
||||
expect(document.querySelector('dialog[open]')).toBeNull(),
|
||||
)
|
||||
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
@@ -317,16 +322,6 @@ describe('Escape with the focus on the page', () => {
|
||||
})
|
||||
|
||||
describe('Escape and the other layers', () => {
|
||||
it('closes the citations panel from the tab row, the selection kept', async () => {
|
||||
const user = await mount(WITH_NODE())
|
||||
await select(user)
|
||||
await openCitations(user)
|
||||
escape(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await waitFor(() => expect(citations()).toBeNull())
|
||||
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('closes « Plus » first (small tier), the twin selection kept', async () => {
|
||||
const user = await mount(TWO(), 500)
|
||||
await select(user)
|
||||
|
||||
@@ -0,0 +1,415 @@
|
||||
/** R2F-3: the finding dialog (view, edit, creation), its history entries and its guards. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import { defaultView } from '@/editor/navigation'
|
||||
import {
|
||||
baseText,
|
||||
resetStore,
|
||||
serverHas,
|
||||
SHEET,
|
||||
store,
|
||||
USER,
|
||||
} from '../helpers/editorHarness'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
import {
|
||||
findingDialog,
|
||||
inFindingDialog,
|
||||
openFinding,
|
||||
treeRow,
|
||||
} from '../helpers/findingDialog'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
...(await orig<typeof import('@faunosteo/supabase')>()),
|
||||
getSheetVersion: vi.fn(),
|
||||
downloadSheetDrawing: vi.fn(),
|
||||
saveSheetDraft: vi.fn(),
|
||||
getOfficialSheetAdmin: vi.fn(),
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
let navigate: NavigateFunction
|
||||
let location: Location
|
||||
const probe = (n: NavigateFunction, l: Location) => {
|
||||
navigate = n
|
||||
location = l
|
||||
}
|
||||
const written = () =>
|
||||
(location.state as Record<string, HistoryEntry> | null)?.[ENTRY_KEY]
|
||||
const back = () => act(async () => navigate(-1))
|
||||
|
||||
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
setWidth(1024)
|
||||
})
|
||||
|
||||
const path = `/app/admin/sheets/${SHEET}/draft`
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
|
||||
/** Zone A > Cat A > Node A (cites nothing). */
|
||||
function sheetText(): string {
|
||||
let text = insert(baseText(), {
|
||||
kind: 'zone',
|
||||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||||
})
|
||||
text = edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'zone', id: 'zone-a' },
|
||||
element: {
|
||||
kind: 'finding_category',
|
||||
value: {
|
||||
id: 'fcat-a',
|
||||
kind: 'dysfunction',
|
||||
name: name('Cat A'),
|
||||
description: {},
|
||||
reference_ids: [],
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
return edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: {
|
||||
id: 'fnode-a',
|
||||
name: name('Node A'),
|
||||
description: {},
|
||||
requires_vet_referral: false,
|
||||
reference_ids: [],
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type User = ReturnType<typeof userEvent.setup>
|
||||
|
||||
async function mount(width = 1280): Promise<User> {
|
||||
serverHas(sheetText(), 3)
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width, probe })
|
||||
await screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await waitFor(() => expect(written()?.view.tab).toBe('findings'))
|
||||
return user
|
||||
}
|
||||
|
||||
const doc = () => JSON.parse(store.getState().documentText)
|
||||
const entries = () => store.getState().undo.length
|
||||
const inDialog = () => inFindingDialog()
|
||||
const modify = (user: User) =>
|
||||
user.click(inDialog().getByRole('button', { name: 'Modifier' }))
|
||||
const nameField = () => inDialog().getByLabelText('Nom (FR)')
|
||||
const closed = () => waitFor(() => expect(findingDialog()).toBeNull())
|
||||
|
||||
describe('opening', () => {
|
||||
it('a click, Enter and Space each select the row and open its dialog; the tree stays', async () => {
|
||||
const user = await mount()
|
||||
const before = screen.getAllByRole('treeitem').length
|
||||
await openFinding(user, /Cat A/)
|
||||
expect(treeRow(/Cat A/)).toHaveAttribute('aria-selected', 'true')
|
||||
expect(inDialog().getByRole('heading', { name: 'Cat A' })).toBeVisible()
|
||||
await user.click(inDialog().getByRole('button', { name: 'Fermer' }))
|
||||
await closed()
|
||||
treeRow(/Cat A/).focus()
|
||||
await user.keyboard('{Enter}')
|
||||
await waitFor(() => expect(findingDialog()).not.toBeNull())
|
||||
await user.keyboard('{Escape}')
|
||||
await closed()
|
||||
await user.keyboard(' ')
|
||||
await waitFor(() => expect(findingDialog()).not.toBeNull())
|
||||
expect(screen.getAllByRole('treeitem')).toHaveLength(before)
|
||||
})
|
||||
|
||||
it('writes one entry on open; Back closes it and the row holds the focus', async () => {
|
||||
const user = await mount()
|
||||
const first = written()!.id
|
||||
await openFinding(user, /Cat A/)
|
||||
await waitFor(() => expect(written()?.id).not.toBe(first))
|
||||
expect(written()?.view.finding).toMatchObject({ citations: false })
|
||||
expect(written()?.below?.finding).toBeNull()
|
||||
await back()
|
||||
await closed()
|
||||
await waitFor(() => expect(document.activeElement).toBe(treeRow(/Cat A/)))
|
||||
expect(written()?.id).toBe(first)
|
||||
})
|
||||
|
||||
it('the close button asks nothing of a pristine view and pops its entry', async () => {
|
||||
const user = await mount()
|
||||
const first = written()!.id
|
||||
await openFinding(user, /Cat A/)
|
||||
await waitFor(() => expect(written()?.id).not.toBe(first))
|
||||
await user.click(inDialog().getByRole('button', { name: 'Fermer' }))
|
||||
await closed()
|
||||
await waitFor(() => expect(written()?.id).toBe(first))
|
||||
expect(document.activeElement).toBe(treeRow(/Cat A/))
|
||||
})
|
||||
})
|
||||
|
||||
describe('edit mode', () => {
|
||||
it('a pristine « Enregistrer » is no command and no entry; a changed one is one', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Cat A/)
|
||||
const before = entries()
|
||||
await modify(user)
|
||||
await user.click(inDialog().getByRole('button', { name: 'Enregistrer' }))
|
||||
expect(entries()).toBe(before)
|
||||
expect(inDialog().getByRole('button', { name: 'Modifier' })).toHaveFocus()
|
||||
await modify(user)
|
||||
await user.clear(nameField())
|
||||
await user.type(nameField(), 'Renommée')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Enregistrer' }))
|
||||
expect(entries()).toBe(before + 1)
|
||||
expect(doc().finding_zones[0].categories[0].name.fr).toBe('Renommée')
|
||||
expect(inDialog().getByRole('status')).toHaveTextContent(
|
||||
'Modifications enregistrées',
|
||||
)
|
||||
})
|
||||
|
||||
it('a blank name is refused on its field, nothing is written', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Cat A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await user.clear(nameField())
|
||||
await user.click(inDialog().getByRole('button', { name: 'Enregistrer' }))
|
||||
expect(entries()).toBe(before)
|
||||
expect(nameField()).toHaveFocus()
|
||||
expect(nameField()).toHaveAccessibleDescription('Ce champ est obligatoire.')
|
||||
})
|
||||
|
||||
it('« Annuler » with changes asks first; « Abandonner » commits nothing', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Cat A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await user.type(nameField(), ' bis')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
).toHaveFocus()
|
||||
await user.click(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
)
|
||||
expect(nameField()).toHaveValue('Cat A bis')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
expect(entries()).toBe(before)
|
||||
expect(doc().finding_zones[0].categories[0].name.fr).toBe('Cat A')
|
||||
expect(inDialog().getByRole('button', { name: 'Modifier' })).toBeVisible()
|
||||
})
|
||||
|
||||
it('a dirty close request (Escape, ✕, a native cancel) asks and keeps the dialog', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Cat A/)
|
||||
await modify(user)
|
||||
await user.type(nameField(), ' bis')
|
||||
await user.keyboard('{Escape}')
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
await user.click(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
)
|
||||
await user.click(inDialog().getByRole('button', { name: 'Fermer' }))
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
fireEvent(findingDialog()!, new Event('cancel', { cancelable: true }))
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
await closed()
|
||||
expect(doc().finding_zones[0].categories[0].name.fr).toBe('Cat A')
|
||||
})
|
||||
|
||||
it('a Back with changes asks, keeps the page and the draft, then Abandonner pops once', async () => {
|
||||
const user = await mount()
|
||||
const first = written()!.id
|
||||
await openFinding(user, /Cat A/)
|
||||
await waitFor(() => expect(written()?.id).not.toBe(first))
|
||||
await modify(user)
|
||||
await user.type(nameField(), ' bis')
|
||||
await back()
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
fireEvent.click(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
)
|
||||
expect(nameField()).toHaveValue('Cat A bis')
|
||||
fireEvent(findingDialog()!, new Event('cancel', { cancelable: true }))
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
await closed()
|
||||
await waitFor(() => expect(written()?.view.finding).toBeNull())
|
||||
expect(entries()).toBe(0)
|
||||
// The refused Back pushes the view again from an effect: the test router's low-priority
|
||||
// transition lands up to 5 s later (a test-DOM artifact, a browser applies it at once).
|
||||
}, 20_000)
|
||||
})
|
||||
|
||||
describe('creation', () => {
|
||||
it('is a layer of its own, replaced by the element after « Créer » (no extra entry)', async () => {
|
||||
const user = await mount()
|
||||
const first = written()!.id
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter une zone' }))
|
||||
await waitFor(() => expect(written()?.id).not.toBe(first))
|
||||
const creation = written()!.id
|
||||
expect(written()?.view.finding).toEqual({
|
||||
create: { kind: 'zone', parent: null },
|
||||
})
|
||||
await user.type(document.getElementById('finding-new-name-fr')!, 'Tête')
|
||||
await user.type(document.getElementById('finding-new-name-en')!, 'Head')
|
||||
await user.click(
|
||||
within(findingDialog()!).getByRole('button', { name: 'Créer' }),
|
||||
)
|
||||
await waitFor(() => expect(written()?.view.finding).toHaveProperty('key'))
|
||||
expect(written()?.id).toBe(creation)
|
||||
expect(doc().finding_zones).toHaveLength(2)
|
||||
await back()
|
||||
await closed()
|
||||
expect(written()?.id).toBe(first)
|
||||
})
|
||||
|
||||
it('a dirty creation asks before it closes and writes nothing', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter une zone' }))
|
||||
await user.type(document.getElementById('finding-new-name-fr')!, 'Tête')
|
||||
await user.keyboard('{Escape}')
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
await closed()
|
||||
expect(doc().finding_zones).toHaveLength(1)
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('button', { name: 'Ajouter une zone' }),
|
||||
),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('read-only flip and the gone rule', () => {
|
||||
it('1280 to 900 to 1280 keeps the draft and the focus, « Enregistrer » off meanwhile', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Cat A/)
|
||||
await modify(user)
|
||||
await user.type(nameField(), ' bis')
|
||||
const field = nameField()
|
||||
act(() => {
|
||||
setWidth(900)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(nameField()).toBe(field)
|
||||
expect(field).toHaveAttribute('readonly')
|
||||
expect(field).toHaveFocus()
|
||||
expect(inDialog().getByText(/Élargissez la fenêtre/)).toBeVisible()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: 'Enregistrer' }),
|
||||
).toBeDisabled()
|
||||
expect(doc().finding_zones[0].categories[0].name.fr).toBe('Cat A')
|
||||
act(() => {
|
||||
setWidth(1280)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(field).not.toHaveAttribute('readonly')
|
||||
expect(field).toHaveValue('Cat A bis')
|
||||
expect(field).toHaveFocus()
|
||||
})
|
||||
|
||||
it('an element that vanishes closes its dialog by replace and says so', async () => {
|
||||
const user = await mount()
|
||||
await openFinding(user, /Node A/)
|
||||
const open = written()!
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
await closed()
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
document.querySelector('p.sr-only[aria-live="polite"]'),
|
||||
).toHaveTextContent("Ce constat n'existe plus"),
|
||||
)
|
||||
expect(written()?.id).toBe(open.id)
|
||||
expect(written()?.view.finding).toBeNull()
|
||||
})
|
||||
|
||||
it('a reading dialog restored for a key the sheet lacks is dropped, with its announcement', async () => {
|
||||
serverHas(sheetText(), 3)
|
||||
const gone = {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'gone'],
|
||||
}
|
||||
const view = {
|
||||
...defaultView('findings'),
|
||||
finding: { key: gone, citations: false },
|
||||
}
|
||||
const state = {
|
||||
[ENTRY_KEY]: {
|
||||
id: 'old',
|
||||
view,
|
||||
below: null,
|
||||
sheetId: SHEET,
|
||||
userId: USER,
|
||||
},
|
||||
}
|
||||
mountDraft({ probe, entries: [{ pathname: path, state }] })
|
||||
await screen.findByRole('heading', {
|
||||
level: 1,
|
||||
name: 'Brouillon, version 4',
|
||||
})
|
||||
await waitFor(() => expect(written()?.view.finding).toBeNull())
|
||||
expect(findingDialog()).toBeNull()
|
||||
expect(written()?.id).toBe('old')
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
document.querySelector('p.sr-only[aria-live="polite"]'),
|
||||
).toHaveTextContent("Ce constat n'existe plus"),
|
||||
)
|
||||
})
|
||||
|
||||
it('a creation form in the entry is never restored by a reload', async () => {
|
||||
serverHas(sheetText(), 3)
|
||||
const view = {
|
||||
...defaultView('findings'),
|
||||
finding: { create: { kind: 'zone', parent: null } },
|
||||
}
|
||||
const state = {
|
||||
[ENTRY_KEY]: {
|
||||
id: 'old',
|
||||
view,
|
||||
below: null,
|
||||
sheetId: SHEET,
|
||||
userId: USER,
|
||||
},
|
||||
}
|
||||
mountDraft({ probe, entries: [{ pathname: path, state }] })
|
||||
await screen.findByRole('heading', {
|
||||
level: 1,
|
||||
name: 'Brouillon, version 4',
|
||||
})
|
||||
await waitFor(() => expect(written()?.view.finding).toBeNull())
|
||||
expect(findingDialog()).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -1,17 +1,24 @@
|
||||
/** Lot I: the Constats tree. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen, within } from '@testing-library/react'
|
||||
import {
|
||||
cleanup,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
ElementKey,
|
||||
FindingNode,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import FindingCreateForm from '@/components/editor/findings/FindingCreateForm'
|
||||
import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
||||
import { buildItems, keyMove, visibleItems } from '@/editor/findings/tree'
|
||||
import { initialNavigation, navigationReducer } from '@/editor/navigation'
|
||||
import { ReferencesOpenContext } from '@/editor/editingContext'
|
||||
import {
|
||||
citationsOfView,
|
||||
initialNavigation,
|
||||
navigationReducer,
|
||||
} from '@/editor/navigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
@@ -21,6 +28,8 @@ import {
|
||||
resetStore,
|
||||
store,
|
||||
} from '../helpers/editorHarness'
|
||||
import { findingDialog, inFindingDialog } from '../helpers/findingDialog'
|
||||
import FindingsHost from '../helpers/findingsHost'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
@@ -32,7 +41,7 @@ vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
||||
type User = ReturnType<typeof userEvent.setup>
|
||||
const doc = (): AnatomicalSheetDocument =>
|
||||
JSON.parse(store.getState().documentText)
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
@@ -92,6 +101,33 @@ afterEach(() => {
|
||||
const items = () => screen.getAllByRole('treeitem')
|
||||
const labels = () => items().map((i) => i.textContent ?? '')
|
||||
|
||||
/** The X of the finding dialog: it closes and the row it opened from holds the focus. */
|
||||
async function closeDialog(user: User) {
|
||||
const dialog = findingDialog()!
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Fermer' }))
|
||||
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||
}
|
||||
|
||||
/** Selects a row by activating it (its dialog opens) and closes the dialog again. */
|
||||
async function pick(user: User, row: HTMLElement) {
|
||||
await user.click(row)
|
||||
await waitFor(() => expect(findingDialog()).not.toBeNull())
|
||||
await closeDialog(user)
|
||||
}
|
||||
|
||||
/** The deletion dialog stacked over the finding dialog: the last dialog of the page. */
|
||||
async function deleteDialog() {
|
||||
await waitFor(() =>
|
||||
expect(document.querySelectorAll('dialog[open]')).toHaveLength(2),
|
||||
)
|
||||
return within(document.querySelectorAll('dialog[open]')[1] as HTMLElement)
|
||||
}
|
||||
|
||||
/** The dialog's one « Enregistrer »: names, descriptions and the vet flag in one save. */
|
||||
async function startEdit(user: User) {
|
||||
await user.click(inFindingDialog().getByRole('button', { name: 'Modifier' }))
|
||||
}
|
||||
|
||||
describe('findings tree model', () => {
|
||||
it('flattens in order and hides collapsed branches', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
@@ -124,7 +160,7 @@ describe('findings tree model', () => {
|
||||
children: [],
|
||||
review_status: 'inherited',
|
||||
})
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
expect(screen.getAllByRole('treeitem').length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
@@ -184,7 +220,7 @@ describe('findings tree model', () => {
|
||||
describe('Constats tab', () => {
|
||||
it('renders a tree with levels, and zones carry no badge', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
expect(screen.getByRole('tree')).toBeInTheDocument()
|
||||
const [zoneA] = items()
|
||||
expect(zoneA).toHaveAttribute('aria-level', '1')
|
||||
@@ -197,7 +233,7 @@ describe('Constats tab', () => {
|
||||
it('moves with the arrows, opens and closes branches', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
items()[0].focus()
|
||||
await user.keyboard('{ArrowDown}')
|
||||
expect(items()[1]).toHaveFocus()
|
||||
@@ -217,7 +253,7 @@ describe('Constats tab', () => {
|
||||
it('creates a zone only with both names', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter une zone' }))
|
||||
await user.type(
|
||||
screen.getByLabelText('Nom (FR)', { selector: '#finding-new-name-fr' }),
|
||||
@@ -233,16 +269,17 @@ describe('Constats tab', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
expect(doc().finding_zones).toHaveLength(3)
|
||||
expect(doc().finding_zones[2].id).toMatch(/^zone-[a-z2-7]{10}$/)
|
||||
expect(
|
||||
screen.getByLabelText('Nom (FR)', { selector: '#finding-name-fr' }),
|
||||
).toHaveValue('Tête')
|
||||
// the creation turns into the view of the new element, in the same dialog
|
||||
expect(inFindingDialog().getByText('Zone de constats')).toBeInTheDocument()
|
||||
expect(document.querySelector('#finding-name-fr')).toHaveTextContent('Tête')
|
||||
expect(document.querySelector('#finding-new-name-fr')).toBeNull()
|
||||
})
|
||||
|
||||
it('creates a category with a kind and a node under the selection', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(items()[0])
|
||||
render(<FindingsHost />)
|
||||
await pick(user, items()[0])
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
@@ -270,6 +307,8 @@ describe('Constats tab', () => {
|
||||
kind: 'anamnesis',
|
||||
review_status: 'to_confirm',
|
||||
})
|
||||
// the new category is selected behind its dialog: close it, add a node under it
|
||||
await closeDialog(user)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un constat' }))
|
||||
await user.type(
|
||||
screen.getByLabelText('Nom (FR)', { selector: '#finding-new-name-fr' }),
|
||||
@@ -301,7 +340,7 @@ describe('Constats tab', () => {
|
||||
it('lands in the zone chosen in the form, not the zone of the selected node (C46)', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
items()[0].focus()
|
||||
await user.keyboard('{ArrowDown}{ArrowRight}{ArrowRight}')
|
||||
expect(items()[2]).toHaveAttribute('aria-selected', 'true')
|
||||
@@ -325,7 +364,7 @@ describe('Constats tab', () => {
|
||||
it('appends the category after the existing ones of the chosen zone', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
@@ -339,10 +378,10 @@ describe('Constats tab', () => {
|
||||
it('is enabled with nothing selected and preselects nothing among several zones', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
const add = screen.getByRole('button', { name: 'Ajouter une catégorie' })
|
||||
expect(add).toBeEnabled()
|
||||
await user.click(items()[2])
|
||||
await pick(user, items()[2])
|
||||
await user.click(add)
|
||||
expect(screen.getByLabelText('Zone')).toHaveValue('')
|
||||
})
|
||||
@@ -357,7 +396,7 @@ describe('Constats tab', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
@@ -369,7 +408,7 @@ describe('Constats tab', () => {
|
||||
|
||||
it('is disabled with its hint while no zone exists', async () => {
|
||||
await openReady()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
).toBeDisabled()
|
||||
@@ -392,11 +431,11 @@ describe('Constats tab', () => {
|
||||
}
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
const add = screen.getByRole('button', { name: 'Ajouter un constat' })
|
||||
await user.click(items()[0])
|
||||
await pick(user, items()[0])
|
||||
expect(add).toBeDisabled()
|
||||
await user.click(items()[1])
|
||||
await pick(user, items()[1])
|
||||
for (let i = 0; i < 30; i++) {
|
||||
if (document.activeElement?.getAttribute('aria-level') === '8') break
|
||||
await user.keyboard('{ArrowRight}')
|
||||
@@ -407,33 +446,53 @@ describe('Constats tab', () => {
|
||||
expect(add).toBeDisabled()
|
||||
})
|
||||
|
||||
it('renames, marks reviewed and resets to confirm', async () => {
|
||||
it('marks reviewed and resets to confirm from the dialog, at once', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[1])
|
||||
await user.click(screen.getByRole('button', { name: 'Marquer comme relu' }))
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: 'Marquer comme relu' }),
|
||||
)
|
||||
expect(doc().finding_zones[0].categories[0].review_status).toBe('reviewed')
|
||||
expect(within(items()[1]).getByText('Relu')).toBeInTheDocument()
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Remettre à confirmer' }),
|
||||
inFindingDialog().getByRole('button', { name: 'Remettre à confirmer' }),
|
||||
)
|
||||
expect(doc().finding_zones[0].categories[0].review_status).toBe(
|
||||
'to_confirm',
|
||||
)
|
||||
const fr = screen.getByLabelText('Nom (FR)', {
|
||||
selector: '#finding-name-fr',
|
||||
})
|
||||
})
|
||||
|
||||
it('renames in the edit form: nothing is written before « Enregistrer », one update after', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[1])
|
||||
await startEdit(user)
|
||||
const fr = inFindingDialog().getByLabelText('Nom (FR)')
|
||||
await user.clear(fr)
|
||||
await user.type(fr, 'Renommée')
|
||||
await user.tab()
|
||||
expect(doc().finding_zones[0].categories[0].name.fr).toBe('Cat A')
|
||||
const before = store.getState().undo.length
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: 'Enregistrer' }),
|
||||
)
|
||||
expect(doc().finding_zones[0].categories[0].name.fr).toBe('Renommée')
|
||||
expect(store.getState().undo.length).toBe(before + 1)
|
||||
expect(inFindingDialog().getByRole('status')).toHaveTextContent(
|
||||
'Modifications enregistrées',
|
||||
)
|
||||
expect(document.querySelector('#finding-name-fr')).toHaveTextContent(
|
||||
'Renommée',
|
||||
)
|
||||
})
|
||||
|
||||
it('marks a node with set_status and a zone with mark_reviewed', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[0])
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Remettre à confirmer' }),
|
||||
@@ -442,8 +501,11 @@ describe('Constats tab', () => {
|
||||
const cat = doc().finding_zones[0].categories[0]
|
||||
expect(cat.review_status).toBe('reviewed')
|
||||
expect(cat.children[0].children[0].review_status).toBe('reviewed')
|
||||
await user.click(items()[1])
|
||||
await closeDialog(user)
|
||||
await pick(user, items()[1])
|
||||
items()[1].focus()
|
||||
await user.keyboard('{ArrowRight}{ArrowDown}')
|
||||
await user.click(items()[2])
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Remettre à confirmer' }),
|
||||
)
|
||||
@@ -455,9 +517,10 @@ describe('Constats tab', () => {
|
||||
it('reorders siblings with the arrows', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[1])
|
||||
expect(screen.getByRole('button', { name: 'Monter' })).toBeDisabled()
|
||||
await closeDialog(user)
|
||||
await user.click(items()[0])
|
||||
await user.click(screen.getByRole('button', { name: 'Descendre' }))
|
||||
expect(doc().finding_zones.map((z) => z.id)).toEqual(['zone-b', 'zone-a'])
|
||||
@@ -467,14 +530,20 @@ describe('Constats tab', () => {
|
||||
it('deletes with the descendants listed, then removes them', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[1])
|
||||
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
||||
const dialog = await screen.findByRole('dialog')
|
||||
expect(within(dialog).getByText(/aussi supprimés/)).toBeInTheDocument()
|
||||
expect(within(dialog).getAllByRole('listitem')).toHaveLength(2)
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Supprimer' }))
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: 'Supprimer' }),
|
||||
)
|
||||
const dialog = await deleteDialog()
|
||||
expect(dialog.getByText(/aussi supprimés/)).toBeInTheDocument()
|
||||
expect(dialog.getAllByRole('listitem')).toHaveLength(2)
|
||||
await user.click(dialog.getByRole('button', { name: 'Supprimer' }))
|
||||
expect(doc().finding_zones[0].categories).toEqual([])
|
||||
// the deletion closes both dialogs: the finding layer is replaced, no Back step
|
||||
await waitFor(() =>
|
||||
expect(document.querySelector('dialog[open]')).toBeNull(),
|
||||
)
|
||||
expect(screen.queryByText('Cat A')).toBeNull()
|
||||
})
|
||||
|
||||
@@ -491,22 +560,20 @@ describe('Constats tab', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[0])
|
||||
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
||||
const dialog = await screen.findByRole('dialog')
|
||||
expect(
|
||||
within(dialog).getByText(/ne peut pas être supprimé/),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
within(dialog).queryByRole('button', { name: 'Supprimer' }),
|
||||
).toBeNull()
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: 'Supprimer' }),
|
||||
)
|
||||
const dialog = await deleteDialog()
|
||||
expect(dialog.getByText(/ne peut pas être supprimé/)).toBeInTheDocument()
|
||||
expect(dialog.queryByRole('button', { name: 'Supprimer' })).toBeNull()
|
||||
expect(doc().finding_zones).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('is plain text and keyboard-navigable when read-only', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
render(<FindingsTab {...props} readOnly />)
|
||||
render(<FindingsHost readOnly />)
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Ajouter une zone' }),
|
||||
).toBeNull()
|
||||
@@ -515,12 +582,15 @@ describe('Constats tab', () => {
|
||||
const user = userEvent.setup()
|
||||
await user.click(items()[1])
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
expect(
|
||||
inFindingDialog().queryByRole('button', { name: 'Modifier' }),
|
||||
).toBeNull()
|
||||
expect(document.querySelector('#finding-name-fr')).toHaveTextContent(
|
||||
'Cat A',
|
||||
)
|
||||
})
|
||||
|
||||
it('edits descriptions (blank side omitted), the vet flag and the cited references', async () => {
|
||||
it('edits descriptions (blank side omitted) and the vet flag in one save, cites at once', async () => {
|
||||
let text = treeText()
|
||||
text = insert(text, {
|
||||
kind: 'reference',
|
||||
@@ -534,26 +604,74 @@ describe('Constats tab', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(items()[1])
|
||||
render(<FindingsHost />)
|
||||
await pick(user, items()[1])
|
||||
items()[1].focus()
|
||||
await user.keyboard('{ArrowRight}{ArrowDown}')
|
||||
await user.click(items()[2])
|
||||
const node = () => doc().finding_zones[0].categories[0].children[0]
|
||||
const fr = screen.getByLabelText('Description (FR)')
|
||||
const save = () =>
|
||||
user.click(inFindingDialog().getByRole('button', { name: 'Enregistrer' }))
|
||||
await startEdit(user)
|
||||
const fr = inFindingDialog().getByLabelText('Description (FR)')
|
||||
await user.type(fr, 'Texte')
|
||||
await user.tab()
|
||||
expect(node().description).toEqual({ fr: 'Texte' })
|
||||
await user.clear(fr)
|
||||
await user.tab()
|
||||
await user.click(
|
||||
inFindingDialog().getByLabelText('Renvoi vers un vétérinaire'),
|
||||
)
|
||||
expect(node().description).toEqual({})
|
||||
await user.click(screen.getByLabelText('Renvoi vers un vétérinaire'))
|
||||
const before = store.getState().undo.length
|
||||
await save()
|
||||
expect(node().description).toEqual({ fr: 'Texte' })
|
||||
expect(node().requires_vet_referral).toBe(true)
|
||||
expect(store.getState().undo.length).toBe(before + 1)
|
||||
await startEdit(user)
|
||||
await user.clear(inFindingDialog().getByLabelText('Description (FR)'))
|
||||
await save()
|
||||
expect(node().description).toEqual({})
|
||||
// « Citer une référence » is no part of the form: it acts at once, in view mode
|
||||
await user.selectOptions(
|
||||
screen.getByLabelText('Citer une référence'),
|
||||
inFindingDialog().getByLabelText('Citer une référence'),
|
||||
'ref-a',
|
||||
)
|
||||
expect(node().reference_ids).toEqual(['ref-a'])
|
||||
await user.click(screen.getByRole('button', { name: /Retirer Alpha/ }))
|
||||
expect(node().reference_ids).toEqual([])
|
||||
// a finding node lists its citations in the sheet, not inline
|
||||
expect(
|
||||
inFindingDialog().queryByRole('button', { name: /Retirer Alpha/ }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
inFindingDialog().getByRole('button', { name: '1 référence' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a family keeps its inline list of citations with « Retirer »', async () => {
|
||||
let text = treeText()
|
||||
text = insert(text, {
|
||||
kind: 'reference',
|
||||
value: {
|
||||
id: 'ref-a',
|
||||
type: 'book',
|
||||
citation: 'Alpha',
|
||||
url: null,
|
||||
doi: null,
|
||||
},
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsHost />)
|
||||
await user.click(items()[1])
|
||||
const family = () => doc().finding_zones[0].categories[0]
|
||||
await user.selectOptions(
|
||||
inFindingDialog().getByLabelText('Citer une référence'),
|
||||
'ref-a',
|
||||
)
|
||||
expect(family().reference_ids).toEqual(['ref-a'])
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: /Retirer Alpha/ }),
|
||||
)
|
||||
expect(family().reference_ids).toEqual([])
|
||||
expect(
|
||||
inFindingDialog().getByText('Aucune référence citée.'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('the trigger shows exactly for the keys open_citations accepts', async () => {
|
||||
@@ -574,22 +692,30 @@ describe('Constats tab', () => {
|
||||
}
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
const openCitations = vi.fn()
|
||||
render(<FindingsTab {...props} openCitations={openCitations} />)
|
||||
await user.click(items()[1])
|
||||
render(<FindingsHost />)
|
||||
await pick(user, items()[1])
|
||||
items()[1].focus()
|
||||
await user.keyboard('{ArrowRight}{ArrowDown}{ArrowRight}')
|
||||
const all = buildItems(doc())
|
||||
expect(items()).toHaveLength(all.length)
|
||||
const truth: [string, boolean][] = []
|
||||
for (const [index, item] of all.entries()) {
|
||||
await user.click(items()[index])
|
||||
const shown = screen.queryByRole('button', { name: /^1 référence$/ })
|
||||
await waitFor(() => expect(findingDialog()).not.toBeNull())
|
||||
const shown = inFindingDialog().queryByRole('button', {
|
||||
name: /^1 référence$/,
|
||||
})
|
||||
const start = initialNavigation('findings')
|
||||
const accepted =
|
||||
navigationReducer(start, { type: 'open_citations', citedBy: item.key })
|
||||
.citationsOf !== null
|
||||
citationsOfView(
|
||||
navigationReducer(start, {
|
||||
type: 'open_citations',
|
||||
citedBy: item.key,
|
||||
}),
|
||||
) !== null
|
||||
expect(shown !== null, item.id).toBe(accepted)
|
||||
truth.push([item.kind, shown !== null])
|
||||
await closeDialog(user)
|
||||
}
|
||||
expect(truth).toEqual([
|
||||
['zone', false],
|
||||
@@ -602,7 +728,7 @@ describe('Constats tab', () => {
|
||||
expect(all.filter((item) => item.kind === 'node')).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('the trigger reads « expanded » only for the finding the panel shows', async () => {
|
||||
it('the trigger reads « expanded » while the sheet of its finding is open', async () => {
|
||||
let text = insert(treeText(), {
|
||||
kind: 'reference',
|
||||
value: { id: 'ref-a', type: 'book', citation: 'A', url: null, doi: null },
|
||||
@@ -620,39 +746,46 @@ describe('Constats tab', () => {
|
||||
}
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
const shows = (citationsOf: ElementKey | null) => (
|
||||
<ReferencesOpenContext value={citationsOf}>
|
||||
<FindingsTab {...props} openCitations={vi.fn()} />
|
||||
</ReferencesOpenContext>
|
||||
)
|
||||
const { rerender } = render(shows(nodes[1].key))
|
||||
await user.click(items()[1])
|
||||
render(<FindingsHost />)
|
||||
await pick(user, items()[1])
|
||||
items()[1].focus()
|
||||
await user.keyboard('{ArrowRight}{ArrowDown}')
|
||||
await user.click(items()[2])
|
||||
const trigger = () => screen.getByRole('button', { name: /^1 référence$/ })
|
||||
const trigger = () =>
|
||||
inFindingDialog().getByRole('button', { name: /^1 référence$/ })
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
rerender(shows(nodes[0].key))
|
||||
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel')
|
||||
await user.click(trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
rerender(shows(null))
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Fermer les références' }),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false'),
|
||||
)
|
||||
})
|
||||
|
||||
it('a category has no vet flag; read-only hides the editing actions', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
const { rerender } = render(<FindingsTab {...props} />)
|
||||
const { rerender } = render(<FindingsHost />)
|
||||
await user.click(items()[1])
|
||||
await startEdit(user)
|
||||
expect(screen.queryByLabelText('Renvoi vers un vétérinaire')).toBeNull()
|
||||
rerender(<FindingsTab {...props} readOnly />)
|
||||
expect(screen.getByLabelText('Description (FR)')).toBeInTheDocument()
|
||||
rerender(<FindingsHost readOnly />)
|
||||
expect(screen.queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
// the open form is kept, its fields read-only, « Enregistrer » disabled
|
||||
expect(screen.getByLabelText('Nom (FR)')).toHaveAttribute('readonly')
|
||||
expect(screen.getByRole('button', { name: 'Enregistrer' })).toBeDisabled()
|
||||
})
|
||||
|
||||
it('collapsing an ancestor of the selection selects the ancestor', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(items()[1])
|
||||
render(<FindingsHost />)
|
||||
await pick(user, items()[1])
|
||||
items()[1].focus()
|
||||
await user.keyboard('{ArrowRight}{ArrowRight}')
|
||||
expect(items()[2]).toHaveAttribute('aria-selected', 'true')
|
||||
await user.click(items()[0].querySelector('span') as HTMLElement)
|
||||
@@ -663,37 +796,48 @@ describe('Constats tab', () => {
|
||||
it('after a delete the previous sibling, else the parent, is selected and focused', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(items()[2])
|
||||
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
||||
const dialog = await screen.findByRole('dialog')
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Supprimer' }))
|
||||
render(<FindingsHost />)
|
||||
const remove = async (row: HTMLElement) => {
|
||||
await user.click(row)
|
||||
await user.click(
|
||||
inFindingDialog().getByRole('button', { name: 'Supprimer' }),
|
||||
)
|
||||
const dialog = await deleteDialog()
|
||||
await user.click(dialog.getByRole('button', { name: 'Supprimer' }))
|
||||
await waitFor(() =>
|
||||
expect(document.querySelector('dialog[open]')).toBeNull(),
|
||||
)
|
||||
}
|
||||
await remove(items()[2])
|
||||
expect(doc().finding_zones.map((z) => z.id)).toEqual(['zone-a'])
|
||||
await waitFor(() => expect(items()[0]).toHaveFocus())
|
||||
expect(items()[0]).toHaveAttribute('aria-selected', 'true')
|
||||
expect(items()[0]).toHaveFocus()
|
||||
await user.click(items()[1])
|
||||
await user.click(screen.getAllByRole('button', { name: 'Supprimer' })[0])
|
||||
const second = (await screen.findAllByRole('dialog')).at(-1) as HTMLElement
|
||||
await user.click(within(second).getByRole('button', { name: 'Supprimer' }))
|
||||
await remove(items()[1])
|
||||
await waitFor(() => expect(items()[0]).toHaveFocus())
|
||||
expect(items()[0]).toHaveAttribute('aria-selected', 'true')
|
||||
expect(items()[0]).toHaveFocus()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the category form title (N1 review, C46)', () => {
|
||||
it('names the chosen zone, and falls back to an existing label before the choice', async () => {
|
||||
describe('the category form zone line (N1 review, C46)', () => {
|
||||
it('names the chosen zone once it is chosen, nothing before the choice', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<FindingCreateForm
|
||||
pending={{ kind: 'category', parent: null }}
|
||||
readOnly={false}
|
||||
guards={{
|
||||
register: vi.fn(),
|
||||
ask: () => ({ allowed: true }),
|
||||
askAll: () => ({ allowed: true }),
|
||||
}}
|
||||
onCreated={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
onClose={vi.fn()}
|
||||
/>,
|
||||
)
|
||||
const title = () => document.querySelector('p.font-medium')?.textContent
|
||||
expect(title()).toBe('Ajouter une catégorie')
|
||||
const line = () => document.querySelector('p.font-medium')?.textContent
|
||||
expect(line()).toBeUndefined()
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-a')
|
||||
expect(title()).toBe('Nouvelle catégorie dans la zone « Zone A »')
|
||||
expect(line()).toBe('Nouvelle catégorie dans la zone « Zone A »')
|
||||
})
|
||||
})
|
||||
@@ -33,12 +33,58 @@ const entry = (patch: Partial<HistoryEntry> = {}): HistoryEntry => ({
|
||||
})
|
||||
const stateOf = (value: unknown) => ({ [ENTRY_KEY]: value })
|
||||
|
||||
const node = { kind: 'finding', zone_id: 'z', path: ['f', 'n'] } as const
|
||||
|
||||
describe('sanitizeView', () => {
|
||||
it('keeps a tab and a section, and holds no layer yet', () => {
|
||||
it('keeps a tab and a section, and drops a malformed layer', () => {
|
||||
const raw = { tab: 'annotations', section: 'views', finding: { key: {} } }
|
||||
expect(sanitizeView(raw)).toEqual(view('annotations', { section: 'views' }))
|
||||
})
|
||||
|
||||
it('keeps the reading layers of Constats: the dialog and the sheet over it', () => {
|
||||
const dialog = {
|
||||
tab: 'findings',
|
||||
section: 'drawing',
|
||||
finding: { key: node },
|
||||
}
|
||||
expect(sanitizeView(dialog)?.finding).toEqual({
|
||||
key: node,
|
||||
citations: false,
|
||||
})
|
||||
const sheet = { ...dialog, finding: { key: node, citations: true } }
|
||||
expect(sanitizeView(sheet)?.finding).toEqual({ key: node, citations: true })
|
||||
expect(layerCount(sanitizeView(sheet)!)).toBe(2)
|
||||
})
|
||||
|
||||
it('a sheet needs a finding node, a layer needs the Constats tab', () => {
|
||||
const family = { kind: 'finding', zone_id: 'z', path: ['f'] }
|
||||
const raw = { tab: 'findings', section: 'drawing' }
|
||||
const asked = { ...raw, finding: { key: family, citations: true } }
|
||||
expect(sanitizeView(asked)?.finding).toEqual({
|
||||
key: family,
|
||||
citations: false,
|
||||
})
|
||||
const elsewhere = {
|
||||
tab: 'general',
|
||||
finding: { key: node, citations: false },
|
||||
}
|
||||
expect(sanitizeView(elsewhere)?.finding).toBeNull()
|
||||
})
|
||||
|
||||
it('a creation is a form: read back only where forms are kept', () => {
|
||||
const raw = {
|
||||
tab: 'findings',
|
||||
section: 'drawing',
|
||||
finding: { create: { kind: 'node', parent: node } },
|
||||
}
|
||||
expect(sanitizeView(raw)?.finding).toEqual({
|
||||
create: { kind: 'node', parent: node },
|
||||
})
|
||||
expect(sanitizeView(raw, false)?.finding).toBeNull()
|
||||
const odd = { ...raw, finding: { create: { kind: 'x', parent: null } } }
|
||||
expect(sanitizeView(odd)?.finding).toBeNull()
|
||||
})
|
||||
|
||||
it('drops what is no view: an unknown tab, a non-object', () => {
|
||||
expect(sanitizeView({ tab: 'nowhere', section: 'views' })).toBeNull()
|
||||
expect(sanitizeView('general')).toBeNull()
|
||||
@@ -115,6 +161,38 @@ describe('planWrite', () => {
|
||||
expect(planWrite(inSection, view('general'), false)).toBe('push')
|
||||
})
|
||||
|
||||
it('a finding dialog and its sheet go back one layer at a time', () => {
|
||||
const dialog = view('findings', {
|
||||
finding: { key: node, citations: false },
|
||||
})
|
||||
const sheet = view('findings', { finding: { key: node, citations: true } })
|
||||
expect(planWrite(entry({ view: view('findings') }), dialog, false)).toBe(
|
||||
'push',
|
||||
)
|
||||
expect(planWrite(entry({ view: dialog }), sheet, false)).toBe('push')
|
||||
const onSheet = entry({ view: sheet, below: dialog })
|
||||
expect(planWrite(onSheet, dialog, false)).toBe('back')
|
||||
const opened = entry({ view: dialog, below: view('findings') })
|
||||
expect(planWrite(opened, view('findings'), false)).toBe('back')
|
||||
})
|
||||
|
||||
it('a layer left for another tab is a push, a replace hint overrides a removal', () => {
|
||||
const sheet = view('findings', { finding: { key: node, citations: true } })
|
||||
const top = entry({ view: sheet, below: view('findings') })
|
||||
// « Tout afficher » and « Aller à »: a step forward, Back returns to the sheet
|
||||
expect(planWrite(top, view('references'), false)).toBe('push')
|
||||
// a deletion or a vanished element: no Back step to a dead dialog
|
||||
expect(planWrite(top, view('findings'), true)).toBe('replace')
|
||||
// a creation turned into its element: same layer, replaced
|
||||
const create = view('findings', {
|
||||
finding: { create: { kind: 'node', parent: null } },
|
||||
})
|
||||
const created = view('findings', {
|
||||
finding: { key: node, citations: false },
|
||||
})
|
||||
expect(planWrite(entry({ view: create }), created, true)).toBe('replace')
|
||||
})
|
||||
|
||||
it('goes back for a layer removed when the entry holds the view below', () => {
|
||||
const layer = view('findings', { reference: { create: true } })
|
||||
const opened = entry({ view: layer, below: view('findings') })
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** R2F-1/2: guard stack, announcer queue, a Back refused while the citations panel is open. */
|
||||
/** R2F-1/2: guard stack, announcer queue, a Back over the finding layers. */
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
@@ -46,8 +46,12 @@ function Page({ guard }: { guard?: () => { allowed: boolean } }) {
|
||||
return (
|
||||
<>
|
||||
<EditorTabs active={nav.state.tab} tier="wide" onSelect={nav.selectTab} />
|
||||
<button onClick={() => nav.openFinding(finding)}>open</button>
|
||||
<button onClick={() => nav.openCitations(finding)}>cite</button>
|
||||
<button onClick={() => nav.registerCanLeave(guard ?? null)}>guard</button>
|
||||
<button onClick={() => nav.guards.register('finding', guard ?? null)}>
|
||||
guard
|
||||
</button>
|
||||
<p data-testid="layer">{JSON.stringify(nav.state.finding)}</p>
|
||||
<button onClick={() => nav.announce('one')}>say one</button>
|
||||
<button onClick={() => nav.announce('two')}>say two</button>
|
||||
<p data-testid="live">{nav.live}</p>
|
||||
@@ -62,24 +66,63 @@ const mount = (guard?: () => { allowed: boolean }) =>
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
describe('a Back while the citations panel is open', () => {
|
||||
it('keeps the page where it is, asks the dirty layer, and pushes the view again', async () => {
|
||||
describe('a Back over the finding layers', () => {
|
||||
async function openSheet(guard?: () => { allowed: boolean }) {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
const guard = vi.fn(() => ({ allowed: false }))
|
||||
mount(guard)
|
||||
await user.click(screen.getByRole('button', { name: 'guard' }))
|
||||
if (guard) await user.click(screen.getByRole('button', { name: 'guard' }))
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('button', { name: 'open' }))
|
||||
await user.click(screen.getByRole('button', { name: 'cite' }))
|
||||
const before = entry().id
|
||||
return user
|
||||
}
|
||||
const layer = () => JSON.parse(screen.getByTestId('layer').textContent!)
|
||||
|
||||
it('closes the sheet first, then the dialog, one layer per entry', async () => {
|
||||
await openSheet()
|
||||
expect(layer()).toMatchObject({ citations: true })
|
||||
expect(entry().below?.finding).toMatchObject({ citations: false })
|
||||
act(() => navigate(-1))
|
||||
expect(guard).toHaveBeenCalledWith(false)
|
||||
expect(layer()).toMatchObject({ citations: false })
|
||||
act(() => navigate(-1))
|
||||
expect(layer()).toBeNull()
|
||||
expect(screen.getByRole('tab', { selected: true })).toHaveTextContent(
|
||||
'Constats',
|
||||
)
|
||||
})
|
||||
|
||||
it('a dirty layer keeps the page where it is: asked, the view pushed again', async () => {
|
||||
const guard = vi.fn(() => ({ allowed: false }))
|
||||
await openSheet(guard)
|
||||
const before = entry().id
|
||||
act(() => navigate(-1))
|
||||
expect(guard).toHaveBeenCalledWith(false)
|
||||
expect(layer()).toMatchObject({ citations: true })
|
||||
expect(entry().id).not.toBe(before)
|
||||
expect(entry().view.tab).toBe('findings')
|
||||
expect(entry().below?.tab).toBe('general')
|
||||
expect(entry().view.finding).toMatchObject({ citations: true })
|
||||
expect(entry().below?.finding).toMatchObject({ citations: false })
|
||||
})
|
||||
|
||||
it('a modal that is no layer refuses the Back too', async () => {
|
||||
await openSheet()
|
||||
const dialog = document.createElement('dialog')
|
||||
dialog.setAttribute('open', '')
|
||||
document.body.append(dialog)
|
||||
act(() => navigate(-1))
|
||||
expect(layer()).toMatchObject({ citations: true })
|
||||
dialog.remove()
|
||||
})
|
||||
|
||||
it('a layer dialog open does not refuse it', async () => {
|
||||
await openSheet()
|
||||
const dialog = document.createElement('dialog')
|
||||
dialog.setAttribute('open', '')
|
||||
dialog.setAttribute('data-layer', '')
|
||||
document.body.append(dialog)
|
||||
act(() => navigate(-1))
|
||||
expect(layer()).toMatchObject({ citations: false })
|
||||
dialog.remove()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -88,6 +88,20 @@ describe('mount', () => {
|
||||
expect(written()?.id).toBe('old')
|
||||
})
|
||||
|
||||
it('a reload never reopens a form: the creation layer is replaced by the view without it', async () => {
|
||||
const create = {
|
||||
...defaultView('findings'),
|
||||
finding: { create: { kind: 'zone', parent: null } },
|
||||
}
|
||||
const entries = [{ pathname: path, state: foreign({ view: create }) }]
|
||||
mountDraft({ probe, entries })
|
||||
await ready()
|
||||
expect(selected()).toBe('Constats')
|
||||
await waitFor(() => expect(written()?.view.finding).toBeNull())
|
||||
expect(written()?.id).toBe('old')
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
})
|
||||
|
||||
it('replaces an entry of another sheet or account by the default view', async () => {
|
||||
const entries = [{ pathname: path, state: foreign({ sheetId: 'other' }) }]
|
||||
mountDraft({ probe, entries })
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
store,
|
||||
versionAnswer,
|
||||
} from '../helpers/editorHarness'
|
||||
import { openFinding } from '../helpers/findingDialog'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
@@ -126,9 +127,7 @@ function referenceText(): string {
|
||||
/** Constats, the node selected, its « 1 référence » trigger pressed. */
|
||||
async function openCitations(user: Awaited<ReturnType<typeof mount>>) {
|
||||
await user.click(tab('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(screen.getByRole('button', { name: '1 référence' }))
|
||||
}
|
||||
|
||||
@@ -203,7 +202,9 @@ describe('text typed in a place that is left', () => {
|
||||
const user = await mount()
|
||||
await user.click(tab('Références'))
|
||||
await user.click(
|
||||
inPlace('references').getByRole('button', { name: 'Ajouter une référence' }),
|
||||
inPlace('references').getByRole('button', {
|
||||
name: 'Ajouter une référence',
|
||||
}),
|
||||
)
|
||||
const field = inPlace('references').getByLabelText('Citation', {
|
||||
selector: '#tab-reference-new-citation',
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
citationsOfView,
|
||||
initialNavigation,
|
||||
navigationReducer,
|
||||
targetOfKey,
|
||||
viewOf,
|
||||
type EditorTarget,
|
||||
type NavigationState,
|
||||
} from '../../src/editor/navigation'
|
||||
@@ -74,7 +76,7 @@ describe('navigationReducer', () => {
|
||||
expect(state.visitedTabs).toEqual(['annotations'])
|
||||
expect(state.visitedSections).toEqual(['drawing'])
|
||||
expect(initialNavigation('general').visitedSections).toEqual([])
|
||||
expect(state.citationsOf).toBeNull()
|
||||
expect(state.finding).toBeNull()
|
||||
expect(state.libraryReset).toBe(0)
|
||||
})
|
||||
|
||||
@@ -97,21 +99,21 @@ describe('navigationReducer', () => {
|
||||
type: 'go_to',
|
||||
target: targetOfKey(key),
|
||||
})
|
||||
expect(state).toMatchObject({ tab: 'references', citationsOf: null })
|
||||
expect(state).toMatchObject({ tab: 'references', finding: null })
|
||||
expect(state.visitedTabs).toEqual(['general', 'references'])
|
||||
expect(state.focus?.target).toEqual(targetOfKey(key))
|
||||
})
|
||||
|
||||
it('go_to a tab closes the citations panel', () => {
|
||||
it('go_to a tab closes the finding layers', () => {
|
||||
const state = run(
|
||||
initialNavigation('general'),
|
||||
{ type: 'open_citations', citedBy: node },
|
||||
{ type: 'go_to', target: targetOfKey(finding) },
|
||||
)
|
||||
expect(state.citationsOf).toBeNull()
|
||||
expect(state.finding).toBeNull()
|
||||
})
|
||||
|
||||
it('select_tab closes the panel and keeps the section, no request', () => {
|
||||
it('select_tab closes the layers and keeps the section, no request', () => {
|
||||
const state = run(
|
||||
initialNavigation('annotations'),
|
||||
{ type: 'open_section', section: 'regions' },
|
||||
@@ -121,16 +123,16 @@ describe('navigationReducer', () => {
|
||||
expect(state).toMatchObject({
|
||||
tab: 'findings',
|
||||
section: 'regions',
|
||||
citationsOf: null,
|
||||
finding: null,
|
||||
focus: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('open_citations opens for a finding node only', () => {
|
||||
const base = initialNavigation('findings')
|
||||
expect(
|
||||
run(base, { type: 'open_citations', citedBy: node }).citationsOf,
|
||||
).toBe(node)
|
||||
const opened = run(base, { type: 'open_citations', citedBy: node })
|
||||
expect(citationsOfView(opened)).toBe(node)
|
||||
expect(opened.finding).toEqual({ key: node, citations: true })
|
||||
for (const refused of [
|
||||
finding,
|
||||
view,
|
||||
@@ -141,7 +143,7 @@ describe('navigationReducer', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('show_all_references closes the panel, shows the tab and bumps the reset', () => {
|
||||
it('show_all_references closes the layers, shows the tab and bumps the reset', () => {
|
||||
const state = run(
|
||||
initialNavigation('findings'),
|
||||
{ type: 'open_citations', citedBy: node },
|
||||
@@ -149,7 +151,7 @@ describe('navigationReducer', () => {
|
||||
)
|
||||
expect(state).toMatchObject({
|
||||
tab: 'references',
|
||||
citationsOf: null,
|
||||
finding: null,
|
||||
libraryReset: 1,
|
||||
focus: undefined,
|
||||
})
|
||||
@@ -183,13 +185,45 @@ describe('navigationReducer', () => {
|
||||
{ type: 'open_citations', citedBy: node },
|
||||
)
|
||||
expect(opened).toMatchObject({ tab: 'annotations', section: 'views' })
|
||||
expect(opened.citationsOf).toBe(node)
|
||||
expect(citationsOfView(opened)).toBe(node)
|
||||
const closed = run(opened, { type: 'close_citations' })
|
||||
expect(closed).toMatchObject({
|
||||
tab: 'annotations',
|
||||
section: 'views',
|
||||
citationsOf: null,
|
||||
expect(closed).toMatchObject({ tab: 'annotations', section: 'views' })
|
||||
expect(citationsOfView(closed)).toBeNull()
|
||||
// the sheet closes alone: the finding dialog under it stays
|
||||
expect(closed.finding).toEqual({ key: node, citations: false })
|
||||
})
|
||||
|
||||
it('open_finding shows the dialog of a key on Constats, close_finding takes both layers', () => {
|
||||
const opened = run(initialNavigation('general'), {
|
||||
type: 'open_finding',
|
||||
key: finding,
|
||||
})
|
||||
expect(opened).toMatchObject({ tab: 'findings' })
|
||||
expect(opened.finding).toEqual({ key: finding, citations: false })
|
||||
const sheet = run(opened, { type: 'open_citations', citedBy: node })
|
||||
expect(sheet.finding).toEqual({ key: node, citations: true })
|
||||
expect(run(sheet, { type: 'close_finding' }).finding).toBeNull()
|
||||
})
|
||||
|
||||
it('create_finding holds the kind and the parent, a creation has no sheet', () => {
|
||||
const state = run(initialNavigation('findings'), {
|
||||
type: 'create_finding',
|
||||
kind: 'node',
|
||||
parent: finding,
|
||||
})
|
||||
expect(state.finding).toEqual({ create: { kind: 'node', parent: finding } })
|
||||
expect(citationsOfView(state)).toBeNull()
|
||||
expect(run(state, { type: 'close_citations' })).toBe(state)
|
||||
})
|
||||
|
||||
it('restore_view puts back the layers of the view it is given', () => {
|
||||
const base = initialNavigation('findings')
|
||||
const restored = run(base, {
|
||||
type: 'restore_view',
|
||||
view: { ...viewOf(base), finding: { key: node, citations: true } },
|
||||
})
|
||||
expect(citationsOfView(restored)).toBe(node)
|
||||
expect(restored.focus).toBeUndefined()
|
||||
})
|
||||
|
||||
it('focus_consumed clears only its serial and serials are not reused', () => {
|
||||
|
||||
@@ -171,16 +171,31 @@ describe('typed values come back after a 1 024 px crossing', () => {
|
||||
await keepsTypedValue(user, 'view-new-fr', 'Nom (FR)', 'Ajouter la vue')
|
||||
})
|
||||
|
||||
it('the findings creation form', async () => {
|
||||
it('the findings creation form: kept in its dialog, read-only while narrow, focus kept', async () => {
|
||||
const user = await mount()
|
||||
await user.click(tab('Constats'))
|
||||
await user.click(button('Ajouter une zone'))
|
||||
await keepsTypedValue(
|
||||
user,
|
||||
'finding-new-name-fr',
|
||||
'Nom (FR)',
|
||||
'Ajouter une zone',
|
||||
)
|
||||
const field = byId('finding-new-name-fr')
|
||||
await user.type(field, 'Saisie')
|
||||
expect(field).toHaveFocus()
|
||||
cross(900)
|
||||
// no edit part leaves the page: the dialog keeps the draft, says why, writes nothing
|
||||
expect(field).toBeVisible()
|
||||
expect(field).toHaveAttribute('readonly')
|
||||
expect(field).toHaveAttribute('aria-readonly', 'true')
|
||||
expect(field).toHaveValue('Saisie')
|
||||
expect(field).toHaveFocus()
|
||||
expect(screen.getByText(/Élargissez la fenêtre/)).toBeInTheDocument()
|
||||
expect(button('Créer')).toBeDisabled()
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
cross(1280)
|
||||
expect(byId('finding-new-name-fr')).toBe(field)
|
||||
expect(field).not.toHaveAttribute('readonly')
|
||||
expect(field).toHaveValue('Saisie')
|
||||
expect(field).toHaveFocus()
|
||||
expect(screen.queryByText(/Élargissez la fenêtre/)).toBeNull()
|
||||
expect(button('Créer')).toBeEnabled()
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
})
|
||||
|
||||
it('the submission note', async () => {
|
||||
|
||||
@@ -13,6 +13,11 @@ import {
|
||||
serverHas,
|
||||
store,
|
||||
} from '../helpers/editorHarness'
|
||||
import {
|
||||
findingDialog,
|
||||
inFindingDialog,
|
||||
openFinding,
|
||||
} from '../helpers/findingDialog'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
@@ -401,18 +406,13 @@ describe('an undo that removes a tile holding a refused draft (V1)', () => {
|
||||
/** The citations panel of Node A, its Denoix tile in edit. */
|
||||
async function openPanel(user: User) {
|
||||
await user.click(screen.getByRole('tab', { 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(
|
||||
within(screen.getByRole('tabpanel', { name: 'Constats' })).getByRole(
|
||||
'button',
|
||||
{ name: '2 références' },
|
||||
),
|
||||
inFindingDialog().getByRole('button', { name: '2 références' }),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('heading', { name: 'Références citées' }),
|
||||
screen.getByRole('button', { name: 'Fermer les références' }),
|
||||
),
|
||||
)
|
||||
const panel = screen.getByTestId('editor-citations-panel')
|
||||
@@ -421,6 +421,20 @@ async function openPanel(user: User) {
|
||||
return panel
|
||||
}
|
||||
|
||||
/** The sheet, then the finding dialog under it, closed with their ✕. */
|
||||
async function closeLayers(user: User) {
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Fermer les références' }),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull(),
|
||||
)
|
||||
await user.click(
|
||||
within(findingDialog()!).getByRole('button', { name: 'Fermer' }),
|
||||
)
|
||||
await waitFor(() => expect(document.querySelector('dialog[open]')).toBeNull())
|
||||
}
|
||||
|
||||
describe('a read-only flip in the citations panel', () => {
|
||||
it('shows the note in the panel tile, says it once, focuses the tile header', async () => {
|
||||
const user = await mount()
|
||||
@@ -431,9 +445,12 @@ describe('a read-only flip in the citations panel', () => {
|
||||
const item = tile('ref-b', 'panel')
|
||||
expect(within(item).getByText(`${NOTE} : Adresse web (URL)`)).toBeVisible()
|
||||
await flush()
|
||||
expect(watch.seen).toHaveLength(1)
|
||||
// the page is inert under the two dialogs: the announcement waits for them
|
||||
expect(watch.seen).toHaveLength(0)
|
||||
expect(document.activeElement).toBe(header('ref-b', 'panel'))
|
||||
expect(history()).toEqual({ undo: 0, redo: 0 })
|
||||
await closeLayers(user)
|
||||
await waitFor(() => expect(watch.seen).toHaveLength(1))
|
||||
watch.stop()
|
||||
})
|
||||
|
||||
@@ -491,14 +508,9 @@ describe('an undo that takes a tile holding a refused draft out of the panel (V1
|
||||
})
|
||||
expect(history()).toEqual({ undo: 1, redo: 0 })
|
||||
await user.click(screen.getByRole('tab', { 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(
|
||||
within(screen.getByRole('tabpanel', { name: 'Constats' })).getByRole(
|
||||
'button',
|
||||
{ name: '3 références' },
|
||||
),
|
||||
inFindingDialog().getByRole('button', { name: '3 références' }),
|
||||
)
|
||||
const panel = await screen.findByTestId('editor-citations-panel')
|
||||
await user.click(within(panel).getByRole('button', { name: /^Code rural/ }))
|
||||
@@ -511,7 +523,10 @@ describe('an undo that takes a tile holding a refused draft out of the panel (V1
|
||||
expect(header('ref-c', 'panel')).toBeNull()
|
||||
expect(screen.getByTestId('editor-citations-panel')).toBe(panel)
|
||||
expect(history()).toEqual({ undo: 0, redo: 1 })
|
||||
expect(watch.seen).toEqual([`${NOTE} : Citation`])
|
||||
// said once the sheet and the finding dialog under it are closed
|
||||
expect(watch.seen).toEqual([])
|
||||
await closeLayers(user)
|
||||
await waitFor(() => expect(watch.seen).toEqual([`${NOTE} : Citation`]))
|
||||
watch.stop()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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