feat(editor): references dialog over the finding, view mode
A modal Dialog replaces the citations side sheet; families open it too (isCitable). The finding dialog shows only « Références citées » and « X références », also at zero; its edit form no longer carries reference_ids. A dirty form refusing « Aller à » or « Tout afficher » closes the clean references dialog first.
This commit is contained in:
1 parent
ff21b0315e
commit
abc781df52
29 files changed
+432
-858
No files matched your search
@@ -9,13 +9,13 @@ import {
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
|
||||
import {
|
||||
forgetSessionTag,
|
||||
resolveSessionTag,
|
||||
} from '@/editor/history/sessionTag'
|
||||
import { useCitationDraft } from '@/editor/findings/citationDraft'
|
||||
import { useAuthStore } from '@/state/authStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
@@ -830,16 +830,33 @@ function citingText(ids = ['ref-a']): string {
|
||||
|
||||
const nodeIds = () =>
|
||||
doc().finding_zones[0].categories[0].children[0].reference_ids
|
||||
const cite = (user: User, label: string) =>
|
||||
user.selectOptions(inDialog().getByLabelText('Citer une référence'), label)
|
||||
const save = (user: User) =>
|
||||
user.click(inDialog().getByRole('button', { name: 'Enregistrer' }))
|
||||
const panelOpen = () => screen.queryByTestId('editor-citations-panel')
|
||||
const nodeKey: ElementKey = {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
}
|
||||
|
||||
describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
it('the view has no cite control and no remove; the trigger opens the sheet', async () => {
|
||||
/** Node A cites `ids` from now on: a change made outside the finding's edit form. */
|
||||
function citeElsewhere(ids: string[]) {
|
||||
act(() => {
|
||||
const node = doc().finding_zones[0].categories[0].children[0]
|
||||
store.getState().commit({
|
||||
op: 'update',
|
||||
key: nodeKey,
|
||||
element: { kind: 'finding_node', value: { ...node, reference_ids: ids } },
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
describe('the finding dialog holds no citation control (Rev 5, owner item 1)', () => {
|
||||
it('the view shows « Références citées » and « X références » only', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
expect(inDialog().getByText('Références citées')).toBeVisible()
|
||||
expect(inDialog().queryByText('Alpha')).toBeNull()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(
|
||||
@@ -847,7 +864,7 @@ describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('a family view lists its citations read-only', async () => {
|
||||
it('a family view lists nothing inline; its « X références » opens the dialog', async () => {
|
||||
let text = insert(sheetText(), reference('ref-a', 'Alpha'))
|
||||
const key = { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] }
|
||||
const cat = JSON.parse(text).finding_zones[0].categories[0]
|
||||
@@ -858,148 +875,48 @@ describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
text = edit(text, { op: 'update', key, element } as never)
|
||||
const user = await mount(1280, text)
|
||||
await openFinding(user, /Cat A/)
|
||||
expect(inDialog().getByText('Alpha')).toBeVisible()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(inDialog().queryByText('Alpha')).toBeNull()
|
||||
await user.click(inDialog().getByRole('button', { name: '1 référence' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
expect(within(panelOpen()!).getByText('Alpha')).toBeVisible()
|
||||
})
|
||||
|
||||
it('the form stages a cite and a remove, written only by « Enregistrer »', async () => {
|
||||
it('a zone has no « Références citées »', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Zone A/)
|
||||
expect(inDialog().queryByText('Références citées')).toBeNull()
|
||||
})
|
||||
|
||||
it('the edit form shows the header and the button only, at zero too', async () => {
|
||||
const user = await mount(1280, citingText([]))
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Alpha' }))
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
expect(entries()).toBe(before)
|
||||
expect(inDialog().getByText('Références citées')).toBeVisible()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '1 référence' }),
|
||||
inDialog().getByRole('button', { name: '0 référence' }),
|
||||
).toBeVisible()
|
||||
await save(user)
|
||||
expect(nodeIds()).toEqual(['ref-b'])
|
||||
expect(entries()).toBe(before + 1)
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
})
|
||||
|
||||
it('one undo restores the names and the citations together', async () => {
|
||||
it('a save keeps a citations change made elsewhere while the form was open', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.clear(nameField())
|
||||
await user.type(nameField(), 'Renommé')
|
||||
await cite(user, 'Beta')
|
||||
await save(user)
|
||||
expect(doc().finding_zones[0].categories[0].children[0].name.fr).toBe(
|
||||
'Renommé',
|
||||
)
|
||||
expect(nodeIds()).toEqual(['ref-a', 'ref-b'])
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(doc().finding_zones[0].categories[0].children[0].name.fr).toBe(
|
||||
'Node A',
|
||||
)
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('a cite then its remove is pristine: « Enregistrer » writes nothing', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
citeElsewhere(['ref-a', 'ref-b'])
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Beta' }))
|
||||
await save(user)
|
||||
expect(entries()).toBe(before)
|
||||
})
|
||||
|
||||
it('« Annuler » with only a citation change asks, « Abandonner » writes nothing', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
expect(entries()).toBe(before)
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('the sheet opened from the form lists the draft and cannot remove', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: '2 références' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
const sheet = within(panelOpen()!)
|
||||
expect(sheet.getByText(/2 références citées/)).toBeVisible()
|
||||
expect(sheet.queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('the published draft returns to null on « Abandonner » and on save', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
expect(useCitationDraft.getState().draft?.ids).toEqual(['ref-a', 'ref-b'])
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
expect(useCitationDraft.getState().draft).toBeNull()
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await save(user)
|
||||
expect(useCitationDraft.getState().draft).toBeNull()
|
||||
})
|
||||
|
||||
it('a Retirer-only change counts and lists the draft, the document stays', async () => {
|
||||
const user = await mount(1280, citingText(['ref-a', 'ref-b']))
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Alpha' }))
|
||||
await user.click(inDialog().getByRole('button', { name: '1 référence' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
const sheet = within(panelOpen()!)
|
||||
expect(sheet.getByText(/1 référence citée/)).toBeVisible()
|
||||
expect(sheet.getByText(/Beta/)).toBeVisible()
|
||||
expect(sheet.queryByText(/Alpha/)).toBeNull()
|
||||
const node = doc().finding_zones[0].categories[0].children[0]
|
||||
expect(node.name.fr).toBe('Renommé')
|
||||
expect(nodeIds()).toEqual(['ref-a', 'ref-b'])
|
||||
})
|
||||
|
||||
it('a read-only flip keeps a citation-only draft, never dropped silently', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
act(() => {
|
||||
setWidth(900)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: 'Enregistrer' }),
|
||||
).toBeDisabled()
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
act(() => {
|
||||
setWidth(1280)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
expect(entries()).toBe(before + 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the citations sheet over a dirty edit form (final review rev 4, item 1)', () => {
|
||||
describe('the references dialog over a dirty edit form', () => {
|
||||
const question = 'Abandonner les modifications ?'
|
||||
const dialogs = () => [...document.querySelectorAll('dialog[open]')]
|
||||
const refForm = () =>
|
||||
dialogs().find((d) => d.querySelector('#reference-form-citation')) as
|
||||
| HTMLElement
|
||||
| undefined
|
||||
let api: NavigationStub
|
||||
beforeEach(() => {
|
||||
api = new NavigationStub()
|
||||
@@ -1012,13 +929,13 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
Reflect.deleteProperty(window, 'navigation')
|
||||
})
|
||||
|
||||
/** Node A in edit with Beta cited in the draft, its sheet open over the form. */
|
||||
async function sheetOverDirtyForm() {
|
||||
/** Node A in edit with its name changed, its references dialog open over the form. */
|
||||
async function dialogOverDirtyForm() {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: '2 références' }))
|
||||
await user.type(nameField(), ' x')
|
||||
await user.click(inDialog().getByRole('button', { name: '1 référence' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
await waitFor(() =>
|
||||
expect(written()?.view.finding).toMatchObject({ citations: true }),
|
||||
@@ -1026,13 +943,10 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
return user
|
||||
}
|
||||
|
||||
const draftKept = () =>
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
const draftKept = () => expect(nameField()).toHaveValue('Node A x')
|
||||
|
||||
it('a Back closes the clean sheet and asks nothing', async () => {
|
||||
await sheetOverDirtyForm()
|
||||
it('a Back closes the clean references dialog and asks nothing', async () => {
|
||||
await dialogOverDirtyForm()
|
||||
await back()
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
@@ -1040,22 +954,8 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a Back from a clean reference dialog over the sheet closes it only', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
const sheet = within(panelOpen()!)
|
||||
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||
const tile = within(head.closest('li')!)
|
||||
await user.click(tile.getByRole('button', { name: 'Modifier' }))
|
||||
await waitFor(() => expect(refForm()).toBeDefined())
|
||||
await back()
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
expect(panelOpen()).not.toBeNull()
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
})
|
||||
|
||||
it('a jump of two entries inside the editor closes the sheet, then the form asks', async () => {
|
||||
await sheetOverDirtyForm()
|
||||
it('a jump of two entries inside the editor closes the dialog, then the form asks', async () => {
|
||||
await dialogOverDirtyForm()
|
||||
await act(async () => navigate(-2))
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
@@ -1066,103 +966,8 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('after the cascade keeps the form, one Back reopens the sheet (docs, limit 5)', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
const sheet = within(panelOpen()!)
|
||||
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||
const tile = within(head.closest('li')!)
|
||||
await user.click(tile.getByRole('button', { name: 'Modifier' }))
|
||||
await waitFor(() => expect(refForm()).toBeDefined())
|
||||
await user.type(within(refForm()!).getByLabelText('Citation'), ' x')
|
||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||
navigationType: 'traverse',
|
||||
destination: { url, key: 'list', sameDocument: true },
|
||||
})
|
||||
act(() => {
|
||||
api.dispatchEvent(event)
|
||||
})
|
||||
await user.click(
|
||||
within(refForm()!).getByRole('button', { name: 'Abandonner' }),
|
||||
)
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
// The reference dialog plays its exit, then leaves: only the finding dialog stays.
|
||||
await waitFor(() => expect(dialogs()).toHaveLength(1))
|
||||
await user.click(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
)
|
||||
await back()
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
expect(api.traverseTo).not.toHaveBeenCalled()
|
||||
draftKept()
|
||||
})
|
||||
|
||||
/** The reference Alpha's edit dialog opened from the sheet; `dirty` types in it. */
|
||||
async function referenceOverSheet(user: User, dirty: boolean) {
|
||||
const sheet = within(panelOpen()!)
|
||||
const head = sheet.getByRole('button', { name: /^Alpha/ })
|
||||
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
|
||||
const tile = within(head.closest('li')!)
|
||||
await user.click(tile.getByRole('button', { name: 'Modifier' }))
|
||||
await waitFor(() => expect(refForm()).toBeDefined())
|
||||
if (dirty)
|
||||
await user.type(within(refForm()!).getByLabelText('Citation'), ' x')
|
||||
}
|
||||
|
||||
it('a jump of three entries asks the dirty reference only, nothing stays pending under it', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
await referenceOverSheet(user, true)
|
||||
await act(async () => navigate(-3))
|
||||
await waitFor(() => expect(screen.queryAllByText(question)).toHaveLength(1))
|
||||
expect(refForm()!.contains(screen.getByText(question))).toBe(true)
|
||||
await user.click(
|
||||
within(refForm()!).getByRole('button', { name: 'Abandonner' }),
|
||||
)
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
// The refused jump is dropped: the sheet stays, and no question comes up unasked.
|
||||
expect(panelOpen()).not.toBeNull()
|
||||
expect(screen.queryByText(question)).toBeNull()
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a clean reference over the sheet over a dirty form: a Back asks the form in view', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
await referenceOverSheet(user, false)
|
||||
await act(async () => navigate(-3))
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a clean reference over the sheet over a dirty form: a leave out asks the form in view', async () => {
|
||||
const user = await sheetOverDirtyForm()
|
||||
await referenceOverSheet(user, false)
|
||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||
navigationType: 'traverse',
|
||||
destination: { url, key: 'list', sameDocument: true },
|
||||
})
|
||||
act(() => {
|
||||
api.dispatchEvent(event)
|
||||
})
|
||||
expect(event.defaultPrevented).toBe(true)
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
await waitFor(() => expect(refForm()).toBeUndefined())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('a jump out of the editor closes the sheet, then the form asks in view', async () => {
|
||||
await sheetOverDirtyForm()
|
||||
it('a jump out of the editor closes the dialog, then the form asks in view', async () => {
|
||||
await dialogOverDirtyForm()
|
||||
const url = new URL('/app/admin/sheets', window.location.origin).href
|
||||
const event = Object.assign(new Event('navigate', { cancelable: true }), {
|
||||
navigationType: 'traverse',
|
||||
@@ -1179,4 +984,38 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('« Tout afficher » refused by the form: the dialog closes first, the question in view', async () => {
|
||||
const user = await dialogOverDirtyForm()
|
||||
await user.click(
|
||||
within(panelOpen()!).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
}),
|
||||
)
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
),
|
||||
)
|
||||
expect(written()?.view.tab).toBe('findings')
|
||||
expect(written()?.view.finding).toMatchObject({ citations: false })
|
||||
draftKept()
|
||||
})
|
||||
|
||||
it('« Aller à » refused by the form: the dialog closes first, the question in view', async () => {
|
||||
const user = await dialogOverDirtyForm()
|
||||
const sheet = within(panelOpen()!)
|
||||
await user.click(sheet.getByRole('button', { name: /^Alpha/ }))
|
||||
await user.click(sheet.getAllByRole('button', { name: /^Aller à / })[0])
|
||||
await waitFor(() => expect(panelOpen()).toBeNull())
|
||||
expect(inDialog().getByText(question)).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
inDialog().getByRole('button', { name: 'Continuer la saisie' }),
|
||||
),
|
||||
)
|
||||
draftKept()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user