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,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 »')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user