diff --git a/apps/app/e2e/shell/editor-citations.spec.ts b/apps/app/e2e/shell/editor-citations.spec.ts index 5dd29e28..89eba4c3 100644 --- a/apps/app/e2e/shell/editor-citations.spec.ts +++ b/apps/app/e2e/shell/editor-citations.spec.ts @@ -585,17 +585,16 @@ test.describe('references dialog, edit mode', () => { expect(nodeOf(saved).reference_ids).toEqual(['ref-a', 'ref-b']) }) - test('« Nouvelle référence » is created over the dialog and cited by the save', async ({ - page, - }) => { - test.setTimeout(150_000) - const { seed } = await open(page) - await editCitations(page) + /** « Nouvelle référence » over the edit mode, typed, then « Ajouter la référence ». */ + async function createPending(page: Page) { const create = inDialog(page, dict['editor.citations.new_reference']) await create.click() const form = referenceDialog(page) await expect(form).toBeVisible() await expect(page.locator('dialog[open]')).toHaveCount(3) + await expect( + form.getByRole('heading', { name: dict['editor.reference.new'] }), + ).toBeVisible() await form.locator('#reference-form-type').selectOption('manual') await form.locator('#reference-form-citation').fill('Source nouvelle') await form @@ -605,14 +604,54 @@ test.describe('references dialog, edit mode', () => { await expect(create).toBeFocused() await expect(draftRows(page)).toHaveCount(4) await expect(draftRows(page).last()).toContainText('Source nouvelle') + await expect(draftRows(page).last()).toContainText( + dict['editor.citations.pending'], + ) + await expect(citationsDialog(page).getByRole('status')).toContainText( + 'Source nouvelle', + ) + } + + test('« Nouvelle référence » then « Abandonner »: the library is unchanged', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await editCitations(page) + await createPending(page) + await inDialog(page, dict['common.cancel']).click() + await inDialog(page, dict['editor.findings.discard']).click() + await expect(editButton(page)).toBeFocused() + await closeCitations(page, dict) + await closeFinding(page, dict) + await expect(historyButton(page, dict, 'undo')).toHaveAttribute( + 'aria-disabled', + 'true', + ) + await expect( + page.locator('p.sr-only[aria-live="polite"]'), + ).not.toContainText('sera enregistrée') + await openTab(page, dict, 'references') + await expect(libraryRoot(page)).toContainText('Source libre') + await expect(libraryRoot(page)).not.toContainText('Source nouvelle') + }) + + test('« Nouvelle référence » then « Enregistrer »: one « Défaire » removes both', async ({ + page, + }) => { + test.setTimeout(150_000) + const { seed } = await open(page) + await editCitations(page) + await createPending(page) await inDialog(page, dict['editor.findings.save']).click() await expect(editButton(page)).toBeFocused() await closeCitations(page, dict) await closeFinding(page, dict) await saveDraft(page, dict, seed.revision + 1) - const saved = await serverDocument>(seed.draftId) - const refs = saved.references as { id: string; citation: string }[] - const added = refs.find((ref) => ref.citation === 'Source nouvelle') + let saved = await serverDocument>(seed.draftId) + const added = (saved.references as { id: string; citation: string }[]).find( + (ref) => ref.citation === 'Source nouvelle', + ) expect(added).toBeDefined() expect(nodeOf(saved).reference_ids).toEqual([ 'ref-a', @@ -620,6 +659,16 @@ test.describe('references dialog, edit mode', () => { 'ref-c', added!.id, ]) + const undo = historyButton(page, dict, 'undo') + await undo.click() + await expect(undo).toHaveAttribute('aria-disabled', 'true') + await saveDraft(page, dict, seed.revision + 2) + saved = await serverDocument>(seed.draftId) + const citations = (saved.references as { citation: string }[]).map( + (ref) => ref.citation, + ) + expect(citations).not.toContain('Source nouvelle') + expect(nodeOf(saved).reference_ids).toEqual(['ref-a', 'ref-b', 'ref-c']) }) }) diff --git a/apps/app/src/components/editor/references/CitationsDialog.tsx b/apps/app/src/components/editor/references/CitationsDialog.tsx index e292766d..f3f49969 100644 --- a/apps/app/src/components/editor/references/CitationsDialog.tsx +++ b/apps/app/src/components/editor/references/CitationsDialog.tsx @@ -54,10 +54,12 @@ interface BodyProps { citedBy: ElementKey mode: Mode props: CitationsDialogProps + /** The edit mode's status line (a draft creation, a pending one removed; Rev 6). */ + onNotice: (text: string) => void } /** The edit mode: where the finding sits, then the draft form. */ -function EditBody({ citedBy, mode, props }: BodyProps) { +function EditBody({ citedBy, mode, props, onNotice }: BodyProps) { const doc = useSheetDocument() const readOnly = useEditorReadOnly() return ( @@ -70,6 +72,7 @@ function EditBody({ citedBy, mode, props }: BodyProps) { guards={props.guards} references={props.references} onDone={mode.done} + onNotice={onNotice} onDiscardClose={() => props.onClose(true, true)} /> @@ -102,10 +105,15 @@ function ViewBody({ citedBy, mode, props }: BodyProps) { ) } -/** The place of the dialog's content, in both modes, then what a save says. */ -function Body(body: BodyProps) { +/** + * The place of the dialog's content, in both modes, then its status line: what a save + * says, or what the edit mode's draft just did (never the editor's live region, Rev 6). + */ +function Body(body: Omit) { const t = useT() const { mode } = body + const [notice, setNotice] = useState('') + if (!mode.editing && notice !== '') setNotice('') return (
- {mode.editing ? : } + {mode.editing ? ( + + ) : ( + + )}

- {mode.saved ? t('editor.findings.saved') : ''} + {notice || (mode.saved ? t('editor.findings.saved') : '')}

) diff --git a/apps/app/src/components/editor/references/CitationsDraftList.tsx b/apps/app/src/components/editor/references/CitationsDraftList.tsx index 876ab6a8..2a38304f 100644 --- a/apps/app/src/components/editor/references/CitationsDraftList.tsx +++ b/apps/app/src/components/editor/references/CitationsDraftList.tsx @@ -1,4 +1,6 @@ import { useEffect, useRef } from 'react' +import type { Reference } from '@faunosteo/core-wasm/types' +import Badge from '@/components/ui/Badge' import Button from '@/components/ui/Button' import FormField, { fieldDescribedBy } from '@/components/ui/FormField' import Select from '@/components/ui/Select' @@ -20,11 +22,13 @@ export interface CiteChoice { export interface DraftListProps { /** The draft's cited ids, in the order they will be saved. */ ids: readonly string[] + /** The references made in the draft (Rev 6): written only by « Enregistrer ». */ + pending: readonly Reference[] readOnly: boolean choice: CiteChoice onAdd: (id: string) => void onRemove: (id: string) => void - /** « Modifier la référence »: the reference dialog over this one. */ + /** « Modifier la référence »: the reference dialog over this one (a pending one too). */ onEditReference: (id: string, opener: HTMLElement) => void /** « Nouvelle référence »: the creation dialog over this one. */ onNew: (opener: HTMLElement) => void @@ -72,15 +76,28 @@ interface RowProps { onRemove: () => void } -/** One cited id: its citation (or « Référence introuvable »), its edit and its removal. */ +/** + * One cited id: its citation (or « Référence introuvable »), « Nouvelle » when the draft + * made it, its edit and its removal. + */ function DraftRow({ id, props, onRemove }: RowProps) { const t = useT() const doc = useSheetDocument() - const citation = doc?.references.find((r) => r.id === id)?.citation + const pending = props.pending.some((r) => r.id === id) + const citation = [...props.pending, ...(doc?.references ?? [])].find( + (r) => r.id === id, + )?.citation const shown = citation ?? `${t('editor.references.missing')} ${id}` return (
  • - {shown} + + {shown} + {pending && ( + + {t('editor.citations.pending')} + + )} + {citation !== undefined && (