fix(editor): an explicit discard of the citations draft says nothing
This commit is contained in:
1 parent
82bdf8de71
commit
7a5684aace
4 files changed
+69
-9
No files matched your search
@@ -17,8 +17,11 @@ import { CITATIONS_TITLE_ID } from './useCitationsPanel'
|
|||||||
export interface CitationsDialogProps {
|
export interface CitationsDialogProps {
|
||||||
/** The family or finding node whose citations it shows; null while it is closed. */
|
/** The family or finding node whose citations it shows; null while it is closed. */
|
||||||
citedBy: ElementKey | null
|
citedBy: ElementKey | null
|
||||||
/** A close: a user one (✕, Escape, the backdrop) is refused by a draft; forced goes. */
|
/**
|
||||||
onClose: (forced?: boolean) => boolean
|
* A close: a user one (✕, Escape, the backdrop) is refused by a draft; forced goes;
|
||||||
|
* `discarded` after the user's « Abandonner » (nothing said).
|
||||||
|
*/
|
||||||
|
onClose: (forced?: boolean, discarded?: boolean) => boolean
|
||||||
/** « Tout afficher dans l'onglet Références ». */
|
/** « Tout afficher dans l'onglet Références ». */
|
||||||
onShowAll: () => void
|
onShowAll: () => void
|
||||||
/** « Aller à » a citing finding or a reference. */
|
/** « Aller à » a citing finding or a reference. */
|
||||||
@@ -67,7 +70,7 @@ function EditBody({ citedBy, mode, props }: BodyProps) {
|
|||||||
guards={props.guards}
|
guards={props.guards}
|
||||||
references={props.references}
|
references={props.references}
|
||||||
onDone={mode.done}
|
onDone={mode.done}
|
||||||
onDiscardClose={() => props.onClose(true)}
|
onDiscardClose={() => props.onClose(true, true)}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ function clearerOf(latest: { current: LeaveNav }): (layer: LayerName) => void {
|
|||||||
const above = layersAbove(layer)
|
const above = layersAbove(layer)
|
||||||
if (above.includes('reference') && state.reference) references.close(true)
|
if (above.includes('reference') && state.reference) references.close(true)
|
||||||
const cited = above.includes('citations') && citationsOfView(state)
|
const cited = above.includes('citations') && citationsOfView(state)
|
||||||
if (cited) closeCitations(true)
|
// Clean, or a draft the user just answered « Abandonner » for: nothing to say.
|
||||||
|
if (cited) closeCitations(true, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,9 +138,10 @@ export interface EditorNavigation {
|
|||||||
openCitations: (citedBy: ElementKey, opener?: Opener) => void
|
openCitations: (citedBy: ElementKey, opener?: Opener) => void
|
||||||
/**
|
/**
|
||||||
* A close of the citations dialog: a user one is refused by its draft (it asks first),
|
* A close of the citations dialog: a user one is refused by its draft (it asks first),
|
||||||
* a forced one goes (the draft is dropped, and said so).
|
* a forced one goes (the draft is dropped, and said so). `discarded`: the user already
|
||||||
|
* answered « Abandonner », the forced close says nothing (as the other forms).
|
||||||
*/
|
*/
|
||||||
closeCitations: (forced?: boolean) => boolean
|
closeCitations: (forced?: boolean, discarded?: boolean) => boolean
|
||||||
/** « X références », where the focus returns once the citations dialog is closed. */
|
/** « X références », where the focus returns once the citations dialog is closed. */
|
||||||
citationsTrigger: () => HTMLElement | null
|
citationsTrigger: () => HTMLElement | null
|
||||||
/**
|
/**
|
||||||
@@ -405,11 +406,11 @@ function useCitationsLayer(ctx: LayerContext, openers: Openers) {
|
|||||||
[openers, dispatch, mark],
|
[openers, dispatch, mark],
|
||||||
)
|
)
|
||||||
const closeCitations = useCallback(
|
const closeCitations = useCallback(
|
||||||
(forced = false) => {
|
(forced = false, discarded = false) => {
|
||||||
const answer = guards.ask('citations', forced)
|
const answer = guards.ask('citations', forced)
|
||||||
if (!answer.allowed) return false
|
if (!answer.allowed) return false
|
||||||
// A forced close of a draft says it was dropped, as the other forced closes.
|
// A draft dropped by a move the user did not answer is said; an « Abandonner » is not.
|
||||||
if (answer.note) announce(answer.note)
|
if (answer.note && !discarded) announce(answer.note)
|
||||||
mark()
|
mark()
|
||||||
dispatch({ type: 'close_citations' })
|
dispatch({ type: 'close_citations' })
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|||||||
import { act, cleanup, screen, waitFor, within } from '@testing-library/react'
|
import { act, cleanup, screen, waitFor, within } from '@testing-library/react'
|
||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||||
|
import { flushAfterModals } from '@/components/ui/afterModalsClosed'
|
||||||
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
|
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
|
||||||
import {
|
import {
|
||||||
forgetSessionTag,
|
forgetSessionTag,
|
||||||
@@ -286,7 +287,34 @@ describe('the draft', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const live = () =>
|
||||||
|
document.querySelector('p.sr-only[aria-live="polite"]')!.textContent ?? ''
|
||||||
|
|
||||||
describe('leaving the edit mode with changes', () => {
|
describe('leaving the edit mode with changes', () => {
|
||||||
|
it('an explicit « Abandonner » after ✕ closes the dialog without a word', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
await removeRow(user, /Barone/)
|
||||||
|
await user.click(button('Fermer'))
|
||||||
|
await user.click(button('Abandonner'))
|
||||||
|
await waitFor(() => expect(citations()).toBeUndefined())
|
||||||
|
await user.click(inFindingDialog().getByRole('button', { name: 'Fermer' }))
|
||||||
|
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||||
|
await act(async () => undefined)
|
||||||
|
expect(live()).not.toContain('Saisie abandonnée')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a system close of the draft (the finding vanished) says it was dropped', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await editCitations(user)
|
||||||
|
await removeRow(user, /Barone/)
|
||||||
|
act(() => {
|
||||||
|
store.getState().commit({ op: 'remove', key: nodeKey })
|
||||||
|
})
|
||||||
|
await waitFor(() => expect(citations()).toBeUndefined())
|
||||||
|
await waitFor(() => expect(live()).toContain('Saisie abandonnée'))
|
||||||
|
})
|
||||||
|
|
||||||
it('« Annuler » asks; « Abandonner » goes back to the view, nothing written', async () => {
|
it('« Annuler » asks; « Abandonner » goes back to the view, nothing written', async () => {
|
||||||
const user = await mount()
|
const user = await mount()
|
||||||
await editCitations(user)
|
await editCitations(user)
|
||||||
@@ -545,6 +573,33 @@ describe('a reference over the references dialog of a dirty finding (criterion 2
|
|||||||
expect(api.traverseTo).toHaveBeenCalledWith('list')
|
expect(api.traverseTo).toHaveBeenCalledWith('list')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('the cascade after the user answered « Abandonner » says nothing', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await openFinding(user, /Node A/)
|
||||||
|
await user.click(
|
||||||
|
inFindingDialog().getByRole('button', { name: 'Modifier' }),
|
||||||
|
)
|
||||||
|
await user.type(inFindingDialog().getByLabelText('Nom (FR)'), ' bis')
|
||||||
|
await user.click(
|
||||||
|
inFindingDialog().getByRole('button', { name: '2 références' }),
|
||||||
|
)
|
||||||
|
await waitFor(() => expect(citations()).toBeDefined())
|
||||||
|
await user.click(button('Modifier'))
|
||||||
|
await removeRow(user, /Barone/)
|
||||||
|
expect(jump().defaultPrevented).toBe(true)
|
||||||
|
await user.click(button('Abandonner'))
|
||||||
|
await waitFor(() => expect(citations()).toBeUndefined())
|
||||||
|
const finding = within(findingDialog()!)
|
||||||
|
await user.click(finding.getByRole('button', { name: 'Abandonner' }))
|
||||||
|
expect(api.traverseTo).toHaveBeenCalledWith('list')
|
||||||
|
// The jump is a stub: the page stays. Its dialogs go, so what waited is said.
|
||||||
|
await act(async () => {
|
||||||
|
document.querySelectorAll('dialog[open]').forEach((d) => d.remove())
|
||||||
|
flushAfterModals()
|
||||||
|
})
|
||||||
|
expect(live()).not.toContain('Saisie abandonnée')
|
||||||
|
})
|
||||||
|
|
||||||
it('« Continuer la saisie » there keeps the finding draft and drops the jump', async () => {
|
it('« Continuer la saisie » there keeps the finding draft and drops the jump', async () => {
|
||||||
const user = await mount()
|
const user = await mount()
|
||||||
await stacked(user)
|
await stacked(user)
|
||||||
|
|||||||
Reference in new issue
Block a user