From 1d119c368402fafb344b3d1561b1fc5caff63d3e Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 15 Nov 2026 20:00:28 +0100 Subject: [PATCH] fix(editor): stale cite choice reset, pending line under the add row --- apps/app/e2e/shell/editor-citations.spec.ts | 19 ++++++- .../editor/references/CitationsDraftList.tsx | 53 +++++++++++-------- .../editor/references/CitationsEditForm.tsx | 3 ++ .../editor/references/CitersList.tsx | 11 ++-- .../editor/references/useReferenceLibrary.ts | 6 ++- .../tests/unit/editor-citations-edit.test.tsx | 28 ++++++++++ 6 files changed, 91 insertions(+), 29 deletions(-) diff --git a/apps/app/e2e/shell/editor-citations.spec.ts b/apps/app/e2e/shell/editor-citations.spec.ts index 89eba4c3..73adee2a 100644 --- a/apps/app/e2e/shell/editor-citations.spec.ts +++ b/apps/app/e2e/shell/editor-citations.spec.ts @@ -493,7 +493,7 @@ test.describe('references dialog, edit mode', () => { expect(nodeOf(saved).reference_ids).toEqual(['ref-a', 'ref-b', 'ref-c']) }) - test('keyboard: ArrowDown on the select only chooses, ✕ closes without asking; axe', async ({ + test('ArrowDown only chooses, a refused save stays level, ✕ asks nothing; axe', async ({ page, }) => { test.setTimeout(150_000) @@ -507,6 +507,23 @@ test.describe('references dialog, edit mode', () => { await expect(cite).toBeEnabled() await expect(draftRows(page)).toHaveCount(3) await expectAccessible(page, 'the edit mode with a choice not cited') + // « Enregistrer » refuses the pending choice; its line leaves both buttons level. + await inDialog(page, dict['editor.findings.save']).click() + await expect(citationsDialog(page).getByRole('alert')).toHaveText( + dict['editor.citations.pending_choice'], + ) + await expect(cite).toBeFocused() + const middle = async (target: Locator) => { + const box = (await target.boundingBox())! + return box.y + box.height / 2 + } + const level = await middle(citeSelect(page)) + for (const control of [ + cite, + inDialog(page, dict['editor.citations.new_reference']), + ]) { + expect(Math.abs((await middle(control)) - level)).toBeLessThanOrEqual(2) + } await inDialog(page, dict['common.close']).click() await expect(page.locator('dialog[open]')).toHaveCount(1) await expect(citationsDialog(page).getByText(confirmText)).toHaveCount(0) diff --git a/apps/app/src/components/editor/references/CitationsDraftList.tsx b/apps/app/src/components/editor/references/CitationsDraftList.tsx index 2a38304f..33c8bcc6 100644 --- a/apps/app/src/components/editor/references/CitationsDraftList.tsx +++ b/apps/app/src/components/editor/references/CitationsDraftList.tsx @@ -2,7 +2,7 @@ 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 FormField from '@/components/ui/FormField' import Select from '@/components/ui/Select' import type { SelectOption } from '@/components/editor/fields/SelectField' import { useSheetDocument } from '@/editor/sheetDocument' @@ -37,6 +37,9 @@ export interface DraftListProps { /** The add choice: its id, so the focus can land on it once the last row is removed. */ const ADD_ID = 'citations-add-reference' +/** The line of a choice not cited at « Enregistrer » (Rev 6), described by the select. */ +const PENDING_ID = 'citations-pending-choice' + /** « Citer »: its id, where a refused save puts the focus. */ export const CITE_ID = 'citations-cite-reference' @@ -131,9 +134,6 @@ function DraftRow({ id, props, onRemove }: RowProps) { function CiteField({ props }: { props: DraftListProps }) { const t = useT() const { choice } = props - const error = choice.pending - ? t('editor.citations.pending_choice') - : undefined const cite = () => { props.onAdd(choice.chosen) choice.onChoose('') @@ -141,18 +141,14 @@ function CiteField({ props }: { props: DraftListProps }) { } return (
- +