From 8c3fcca0b987226d771ecb901bd69349dafd0c82 Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 15 Nov 2026 19:40:47 +0100 Subject: [PATCH] =?UTF-8?q?feat(editor):=20=C2=AB=20Citer=20=C2=BB=20butto?= =?UTF-8?q?n=20and=20family=20labels=20in=20references?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/app/e2e/shell/editor-citations.spec.ts | 82 +++++++++++- .../editor/references/CitationsDialog.tsx | 4 +- .../editor/references/CitationsDraftList.tsx | 88 ++++++++++--- .../editor/references/CitationsEditForm.tsx | 47 ++++++- .../editor/references/CitationsPanel.tsx | 23 +++- .../editor/references/CitersList.tsx | 16 ++- .../components/editor/references/NoResult.tsx | 7 +- .../editor/references/ReferenceToolbar.tsx | 12 +- .../editor/references/useReferenceLibrary.ts | 4 +- .../components/editor/tabs/FindingsTab.tsx | 6 +- .../components/editor/tabs/ReferencesTab.tsx | 7 +- apps/app/src/editor/navigation.ts | 10 ++ apps/app/src/i18n/en.ts | 13 ++ apps/app/src/i18n/fr.ts | 13 ++ .../tests/unit/editor-citations-edit.test.tsx | 108 +++++++++++++++- .../unit/editor-references-panel.test.tsx | 120 +++++++++++++++++- 16 files changed, 507 insertions(+), 53 deletions(-) diff --git a/apps/app/e2e/shell/editor-citations.spec.ts b/apps/app/e2e/shell/editor-citations.spec.ts index f7d098ab..5dd29e28 100644 --- a/apps/app/e2e/shell/editor-citations.spec.ts +++ b/apps/app/e2e/shell/editor-citations.spec.ts @@ -277,8 +277,9 @@ test.describe('references dialog, view mode', () => { ) await showCitations(page) await expect(heads(page)).toHaveCount(0) + // Rev 6: « Dysfonction A » is a family, its empty line says so. await expect(panel(page)).toContainText( - dict['editor.references.panel_empty'], + dict['editor.references.panel_empty_family'], ) }) @@ -419,6 +420,33 @@ const removeRow = (page: Page, citation: string) => page, new RegExp(`^${dict['editor.action.remove']} ${citation}`), ).click() +const citeSelect = (page: Page) => + citationsDialog(page).getByLabel(dict['editor.findings.reference_add']) + +/** « Constat A » carries a name long enough to wrap in a dialog title at 320 px. */ +const LONG_NAME = + 'Constat A au nom particulièrement long, qui ne tient pas sur une seule ligne du titre' +function longNameShape(document: Record) { + shape(document) + const zone = (document.finding_zones as { categories: unknown[] }[])[0] + const family = zone.categories[0] as { children: { name: unknown }[] } + family.children[0].name = { fr: LONG_NAME, en: LONG_NAME } +} + +/** The ✕ of `dialog`: a box of at least 44 × 44 px, inside the viewport (Rev 6). */ +async function expectCloseBox(page: Page, dialog: Locator, at: string) { + const close = dialog.getByRole('button', { name: dict['common.close'] }) + const box = async () => (await close.boundingBox())! + // Polled: the panel scales in (0.96 to 1) right after it opens. + await expect + .poll(async () => (await box()).width, { message: `✕ width at ${at}` }) + .toBeGreaterThanOrEqual(44) + expect((await box()).height, `✕ height at ${at}`).toBeGreaterThanOrEqual(44) + const { x, width } = await box() + expect(x + width, `✕ inside at ${at}`).toBeLessThanOrEqual( + page.viewportSize()!.width + 0.5, + ) +} test.describe('references dialog, edit mode', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) @@ -438,9 +466,9 @@ test.describe('references dialog, edit mode', () => { await editCitations(page) await expectAccessible(page, 'the references dialog, edit mode') await removeRow(page, 'Référence A') - await citationsDialog(page) - .getByLabel(dict['editor.findings.reference_add']) - .selectOption('ref-d') + await citeSelect(page).selectOption('ref-d') + await expect(draftRows(page)).toHaveCount(2) + await inDialog(page, dict['editor.citations.cite']).click() await expect(draftRows(page)).toHaveCount(3) await inDialog(page, dict['editor.findings.save']).click() await expect(editButton(page)).toBeFocused() @@ -465,6 +493,40 @@ 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 ({ + page, + }) => { + test.setTimeout(150_000) + await open(page) + await editCitations(page) + const cite = inDialog(page, dict['editor.citations.cite']) + await expect(cite).toBeDisabled() + await citeSelect(page).focus() + await page.keyboard.press('ArrowDown') + await expect(citeSelect(page)).not.toHaveValue('') + await expect(cite).toBeEnabled() + await expect(draftRows(page)).toHaveCount(3) + await expectAccessible(page, 'the edit mode with a choice not cited') + await inDialog(page, dict['common.close']).click() + await expect(page.locator('dialog[open]')).toHaveCount(1) + await expect(citationsDialog(page).getByText(confirmText)).toHaveCount(0) + await expect(historyButton(page, dict, 'undo')).toHaveAttribute( + 'aria-disabled', + 'true', + ) + }) + + test('the ✕ is a 44 px box beside a long title at 1280 px', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page, longNameShape) + await openFinding(page, dict, 'Constat A') + await expectCloseBox(page, findingDialog(page), '1280 px') + await showCitations(page) + await expectCloseBox(page, citationsDialog(page), '1280 px, references') + }) + test('a dirty draft: ✕ and Back ask, « Abandonner » writes nothing', async ({ page, }) => { @@ -718,6 +780,18 @@ test.describe('references dialog, read-only at 375 px', () => { await expect(place(page, 'findings')).toBeVisible() }) + test('the ✕ is a 44 px box beside a long title at 375 and 320 px @phone', async ({ + page, + }) => { + test.setTimeout(150_000) + await open(page, longNameShape) + await openFinding(page, dict, 'Constat A') + await expectCloseBox(page, findingDialog(page), '375 px') + await page.setViewportSize({ width: 320, height: 640 }) + await expectCloseBox(page, findingDialog(page), '320 px') + await expectNoHorizontalOverflow(page, 'the finding dialog at 320 px') + }) + test('by touch: taps act on the references dialog only, the finding dialog under it stays @phone', async ({ page, }) => { diff --git a/apps/app/src/components/editor/references/CitationsDialog.tsx b/apps/app/src/components/editor/references/CitationsDialog.tsx index c7d0d0ea..e292766d 100644 --- a/apps/app/src/components/editor/references/CitationsDialog.tsx +++ b/apps/app/src/components/editor/references/CitationsDialog.tsx @@ -4,7 +4,7 @@ import ActionButton from '@/components/editor/fields/ActionButton' import { useItemMode } from '@/components/editor/findings/useItemMode' import Dialog from '@/components/ui/Dialog' import { useEditorReadOnly } from '@/editor/editingContext' -import type { EditorTarget } from '@/editor/navigation' +import { elementLabel, type EditorTarget } from '@/editor/navigation' import { findingPath } from '@/editor/references/panel' import { useSheetDocument } from '@/editor/sheetDocument' import type { Guards } from '@/editor/useEditorNavigation' @@ -141,7 +141,7 @@ export default function CitationsDialog(props: CitationsDialogProps) { open={citedBy !== null} layer size="lg" - title={t(title)} + title={t(elementLabel(title, citedBy))} titleId={CITATIONS_TITLE_ID} returnFocus={props.returnFocus} onClose={() => (onClose() ? undefined : 'kept')} diff --git a/apps/app/src/components/editor/references/CitationsDraftList.tsx b/apps/app/src/components/editor/references/CitationsDraftList.tsx index db466981..876ab6a8 100644 --- a/apps/app/src/components/editor/references/CitationsDraftList.tsx +++ b/apps/app/src/components/editor/references/CitationsDraftList.tsx @@ -1,13 +1,27 @@ import { useEffect, useRef } from 'react' -import SelectField from '@/components/editor/fields/SelectField' import Button from '@/components/ui/Button' +import FormField, { fieldDescribedBy } from '@/components/ui/FormField' +import Select from '@/components/ui/Select' +import type { SelectOption } from '@/components/editor/fields/SelectField' import { useSheetDocument } from '@/editor/sheetDocument' import { useT } from '@/i18n/useT' +/** The select's choice (Rev 6): local to the form, never in the draft until « Citer ». */ +export interface CiteChoice { + /** The placeholder, then the references the draft does not cite yet. */ + options: readonly SelectOption[] + /** The chosen id while it is still offered, else '' (the placeholder). */ + chosen: string + onChoose: (id: string) => void + /** « Enregistrer » found it chosen but not cited: the line at the select. */ + pending: boolean +} + export interface DraftListProps { /** The draft's cited ids, in the order they will be saved. */ ids: readonly string[] readOnly: boolean + choice: CiteChoice onAdd: (id: string) => void onRemove: (id: string) => void /** « Modifier la référence »: the reference dialog over this one. */ @@ -19,8 +33,11 @@ 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' +/** « Citer »: its id, where a refused save puts the focus. */ +export const CITE_ID = 'citations-cite-reference' + /** The references the draft does not cite yet, after the « choose » placeholder. */ -function useCitableOptions(ids: readonly string[]) { +export function useCitableOptions(ids: readonly string[]) { const t = useT() const doc = useSheetDocument() const options = (doc?.references ?? []) @@ -90,23 +107,64 @@ function DraftRow({ id, props, onRemove }: RowProps) { ) } -/** « Citer une référence existante » among those not cited yet, and « Nouvelle référence ». */ +/** + * « Citer une référence existante »: browsing or picking only chooses; « Citer » cites the + * choice, empties the select and gives it the focus back. + */ +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('') + document.getElementById(ADD_ID)?.focus() + } + return ( +
+ +
+ + +
+
+
+ ) +} + +/** The way to cite an existing reference (edit tier only), and « Nouvelle référence ». */ function AddRow({ props }: { props: DraftListProps }) { const t = useT() - const options = useCitableOptions(props.ids) return (
- {!props.readOnly && ( -
- id !== '' && props.onAdd(id)} - /> -
- )} + {!props.readOnly && }
) diff --git a/apps/app/src/components/editor/references/useReferenceLibrary.ts b/apps/app/src/components/editor/references/useReferenceLibrary.ts index 5843f37d..747082f3 100644 --- a/apps/app/src/components/editor/references/useReferenceLibrary.ts +++ b/apps/app/src/components/editor/references/useReferenceLibrary.ts @@ -6,6 +6,7 @@ import { useFocusRequest, type FocusRequest, } from '@/editor/focusRequest' +import { elementLabel } from '@/editor/navigation' import { citersOf } from '@/editor/references/citations' import { citedIds, @@ -33,7 +34,8 @@ function useFilterFinding(layer: ReferenceLayer) { const gone = doc !== null && layer.filter !== null && finding === null // The vanished finding is the trigger; the move and its wording are the latest ones. const clear = useRef<() => void>(() => undefined) - clear.current = () => layer.clearFilter(t('editor.references.filter_gone')) + const gonePhrase = elementLabel('editor.references.filter_gone', layer.filter) + clear.current = () => layer.clearFilter(t(gonePhrase)) useEffect(() => { if (gone) clear.current() }, [gone]) diff --git a/apps/app/src/components/editor/tabs/FindingsTab.tsx b/apps/app/src/components/editor/tabs/FindingsTab.tsx index 420290b7..78fefefc 100644 --- a/apps/app/src/components/editor/tabs/FindingsTab.tsx +++ b/apps/app/src/components/editor/tabs/FindingsTab.tsx @@ -20,6 +20,7 @@ import { type FindingKind, } from '@/editor/findings/tree' import { useFocusRequest, visibleElement } from '@/editor/focusRequest' +import { elementLabel } from '@/editor/navigation' import { useEditorStore } from '@/editor/state/editorStore' import { useSheetDocument } from '@/editor/sheetDocument' import type { EditorPlaceProps, FindingLayer } from '@/editor/tabs' @@ -109,9 +110,12 @@ function useGoneRule(layer: FindingLayer, loaded: boolean) { if (key === null || currentItems().some(present)) return if (handled.current === stamp) return handled.current = stamp + // A family's own dialog names the family; a creation keeps the finding wording. + const shown = 'key' in view ? view.key : null + const gone = t(elementLabel('editor.findings.gone', shown)) // After this commit's effects: a tile in edit re-registers its guard in them, and the // forced close below must still be able to ask it. - queueMicrotask(() => layer.replace(null, t('editor.findings.gone'))) + queueMicrotask(() => layer.replace(null, gone)) }, [loaded, view, layer, t]) } diff --git a/apps/app/src/components/editor/tabs/ReferencesTab.tsx b/apps/app/src/components/editor/tabs/ReferencesTab.tsx index 1b1187bd..889d268d 100644 --- a/apps/app/src/components/editor/tabs/ReferencesTab.tsx +++ b/apps/app/src/components/editor/tabs/ReferencesTab.tsx @@ -61,6 +61,7 @@ function useFilterChip(lib: ReferenceLibraryState, layer: ReferenceLayer) { const key = layer.filter return { name: finding.name[locale], + key, onRemove: () => layer.clearFilter(), onBack: () => layer.backToFinding(key), } @@ -90,7 +91,11 @@ function LibraryNotices(body: BodyProps) { )} {body.lib.all.length === 0 && } {body.lib.all.length > 0 && shown.positions.length === 0 && ( - + )} {reorderable && shown.positions.length > 0 && (

diff --git a/apps/app/src/editor/navigation.ts b/apps/app/src/editor/navigation.ts index 0341e15b..7157fa29 100644 --- a/apps/app/src/editor/navigation.ts +++ b/apps/app/src/editor/navigation.ts @@ -198,6 +198,16 @@ export function isCitable(key: ElementKey): boolean { return key.kind === 'finding' && key.path.length > 0 } +/** A family: a finding key of one id (read from the key, so a vanished family is one too). */ +export function isFamilyKey(key: ElementKey): boolean { + return key.kind === 'finding' && key.path.length === 1 +} + +/** The label key that names `key`: its `_family` variant for a family (Rev 6). */ +export function elementLabel(label: string, key: ElementKey | null): string { + return key && isFamilyKey(key) ? `${label}_family` : label +} + /** Only a citable element has a citations dialog: any other key leaves the state as it is. */ function openCitations(state: NavigationState, citedBy: ElementKey) { const finding = { key: citedBy, citations: true } diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 0b9e1901..d11bac05 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -1229,15 +1229,23 @@ export const en: Dict = { 'editor.annotations.deselected': 'No annotation selected.', 'editor.references.search': 'Search a reference', 'editor.references.dialog_title': 'References of the finding', + 'editor.references.dialog_title_family': 'References of the family', 'editor.citations.edit': 'Edit', 'editor.citations.edit_title': 'Edit the references of the finding', + 'editor.citations.edit_title_family': 'Edit the references of the family', 'editor.citations.edit_reference': 'Edit the reference', 'editor.citations.new_reference': 'New reference', + 'editor.citations.cite': 'Cite', + 'editor.citations.pending_choice': 'Reference chosen but not cited yet: choose « Cite » or go back to the empty choice.', 'editor.references.panel_count_one': '{count} reference cited by this finding', 'editor.references.panel_count_other': '{count} references cited by this finding', + 'editor.references.panel_count_family_one': '{count} reference cited by this family', + 'editor.references.panel_count_family_other': '{count} references cited by this family', 'editor.references.panel_show_all': 'Show all in the References tab', 'editor.references.panel_empty': 'This finding cites no reference.', + 'editor.references.panel_empty_family': 'This family cites no reference.', 'editor.references.this_finding': 'this finding', + 'editor.references.this_finding_family': 'this family', 'editor.references.missing': 'Reference not found', 'editor.references.cited_one': 'Cited {count} time', 'editor.references.cited_other': 'Cited {count} times', @@ -1259,9 +1267,13 @@ export const en: Dict = { 'editor.references.added_show': 'Show', 'editor.references.gone': 'This reference no longer exists', 'editor.references.filter_chip': 'References of the finding: {name}', + 'editor.references.filter_chip_family': 'References of the family: {name}', 'editor.references.filter_remove': 'Remove the filter of the finding {name}', + 'editor.references.filter_remove_family': 'Remove the filter of the family {name}', 'editor.references.filter_back': 'Back to the finding', + 'editor.references.filter_back_family': 'Back to the family', 'editor.references.filter_gone': 'The finding no longer exists: the filter is removed', + 'editor.references.filter_gone_family': 'The family no longer exists: the filter is removed', 'editor.references.clear_search': 'Clear the search', 'editor.references.sort_by': 'Sort by', 'editor.references.sort.sheet': 'Sheet order', @@ -1649,6 +1661,7 @@ export const en: Dict = { 'editor.findings.discard': 'Discard', 'editor.findings.draft_dropped': 'Entry discarded', 'editor.findings.gone': 'This finding no longer exists', + 'editor.findings.gone_family': 'This family no longer exists', // Provisional EN, pending the owner's wording. 'editor.leave.draft_dropped': 'An unsaved entry was discarded when you left the editor', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index 0165ee5c..ef6f3f31 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -1260,15 +1260,23 @@ export const fr: Dict = { 'editor.annotations.deselected': 'Aucune annotation sélectionnée.', 'editor.references.search': 'Rechercher une référence', 'editor.references.dialog_title': 'Références du constat', + 'editor.references.dialog_title_family': 'Références de la famille', 'editor.citations.edit': 'Modifier', 'editor.citations.edit_title': 'Modifier les références du constat', + 'editor.citations.edit_title_family': 'Modifier les références de la famille', 'editor.citations.edit_reference': 'Modifier la référence', 'editor.citations.new_reference': 'Nouvelle référence', + 'editor.citations.cite': 'Citer', + 'editor.citations.pending_choice': 'Référence choisie mais pas encore citée : choisissez « Citer » ou revenez au choix vide.', 'editor.references.panel_count_one': '{count} référence citée par ce constat', 'editor.references.panel_count_other': '{count} références citées par ce constat', + 'editor.references.panel_count_family_one': '{count} référence citée par cette famille', + 'editor.references.panel_count_family_other': '{count} références citées par cette famille', 'editor.references.panel_show_all': 'Tout afficher dans l\'onglet Références', 'editor.references.panel_empty': 'Ce constat ne cite aucune référence.', + 'editor.references.panel_empty_family': 'Cette famille ne cite aucune référence.', 'editor.references.this_finding': 'ce constat', + 'editor.references.this_finding_family': 'cette famille', 'editor.references.missing': 'Référence introuvable', 'editor.references.cited_one': 'Citée {count} fois', 'editor.references.cited_other': 'Citée {count} fois', @@ -1290,9 +1298,13 @@ export const fr: Dict = { 'editor.references.added_show': 'Afficher', 'editor.references.gone': "Cette référence n'existe plus", 'editor.references.filter_chip': 'Références du constat : {name}', + 'editor.references.filter_chip_family': 'Références de la famille : {name}', 'editor.references.filter_remove': 'Retirer le filtre du constat {name}', + 'editor.references.filter_remove_family': 'Retirer le filtre de la famille {name}', 'editor.references.filter_back': 'Revenir au constat', + 'editor.references.filter_back_family': 'Revenir à la famille', 'editor.references.filter_gone': "Le constat n'existe plus : le filtre est retiré", + 'editor.references.filter_gone_family': "La famille n'existe plus : le filtre est retiré", 'editor.references.clear_search': 'Effacer la recherche', 'editor.references.sort_by': 'Trier par', 'editor.references.sort.sheet': 'Ordre de la fiche', @@ -1679,6 +1691,7 @@ export const fr: Dict = { 'editor.findings.discard': 'Abandonner', 'editor.findings.draft_dropped': 'Saisie abandonnée', 'editor.findings.gone': "Ce constat n'existe plus", + 'editor.findings.gone_family': "Cette famille n'existe plus", 'editor.leave.draft_dropped': "Une saisie non enregistrée a été abandonnée en quittant l'éditeur", 'editor.findings.flip_narrow': 'Élargissez la fenêtre pour poursuivre : votre saisie est conservée.', diff --git a/apps/app/tests/unit/editor-citations-edit.test.tsx b/apps/app/tests/unit/editor-citations-edit.test.tsx index 3028cbbf..9a0bd2d6 100644 --- a/apps/app/tests/unit/editor-citations-edit.test.tsx +++ b/apps/app/tests/unit/editor-citations-edit.test.tsx @@ -1,6 +1,13 @@ /** Rev 5 Task 12: the references dialog's edit mode (draft, save, guards, stacked dialogs). */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { act, cleanup, screen, waitFor, within } from '@testing-library/react' +import { + act, + cleanup, + fireEvent, + screen, + waitFor, + within, +} from '@testing-library/react' import userEvent from '@testing-library/user-event' import type { Location, NavigateFunction } from 'react-router-dom' import { flushAfterModals } from '@/components/ui/afterModalsClosed' @@ -182,11 +189,13 @@ const removeRow = (user: User, citation: RegExp) => name: new RegExp(`^Retirer ${citation.source}`), }), ) -const cite = (user: User, id: string) => - user.selectOptions( - inCitations().getByLabelText('Citer une référence existante'), - id, - ) +const select = () => + inCitations().getByLabelText('Citer une référence existante') +/** Rev 6: a choice in the select, then « Citer ». */ +async function cite(user: User, id: string) { + await user.selectOptions(select(), id) + await user.click(button('Citer')) +} describe('the « Modifier » of the references dialog', () => { it('edit mode: no history entry, no « Tout afficher », no « Aller à »', async () => { @@ -295,6 +304,93 @@ describe('the draft', () => { }) }) +describe('« Citer » (Rev 6)', () => { + const citeButton = () => button('Citer') + const pendingLine = + 'Référence choisie mais pas encore citée : choisissez « Citer » ou revenez au choix vide.' + + it('a choice or an arrow key leaves the draft clean: ✕ closes without a question', async () => { + const user = await mount() + await editCitations(user) + expect(citeButton()).toBeDisabled() + await user.selectOptions(select(), 'ref-b') + fireEvent.keyDown(select(), { key: 'ArrowDown' }) + fireEvent.change(select(), { target: { value: 'ref-b' } }) + expect(rows()).toEqual(['ref-a', 'ref-c']) + expect(citeButton()).toBeEnabled() + await user.click(button('Fermer')) + await waitFor(() => expect(citations()).toBeUndefined()) + expect(undos()).toBe(0) + }) + + it('« Citer » cites once, resets and focuses the select, stays in edit mode', async () => { + const user = await mount() + await editCitations(user) + await user.selectOptions(select(), 'ref-b') + expect(citeButton()).toHaveAttribute('type', 'button') + await user.click(citeButton()) + expect(rows()).toEqual(['ref-a', 'ref-c', 'ref-b']) + expect(select()).toHaveValue('') + expect(select()).toHaveFocus() + expect(citeButton()).toBeDisabled() + await user.click(citeButton()) + expect(rows()).toEqual(['ref-a', 'ref-c', 'ref-b']) + expect( + inCitations().getByRole('heading', { + name: 'Modifier les références du constat', + }), + ).toBeVisible() + expect(undos()).toBe(0) + }) + + it('a choice no longer offered goes back to the placeholder', async () => { + const user = await mount() + await editCitations(user) + await user.selectOptions(select(), 'ref-b') + act(() => { + store.getState().commit({ + op: 'remove', + key: { kind: 'reference', id: 'ref-b' }, + }) + }) + await waitFor(() => expect(select()).toHaveValue('')) + expect(citeButton()).toBeDisabled() + }) + + it('« Enregistrer » with a choice not cited refuses: the line, focus on « Citer »', async () => { + const user = await mount() + await editCitations(user) + await user.selectOptions(select(), 'ref-b') + await user.click(button('Enregistrer')) + expect(undos()).toBe(0) + expect(inCitations().getByRole('alert')).toHaveTextContent(pendingLine) + expect(citeButton()).toHaveFocus() + expect( + inCitations().getByRole('heading', { + name: 'Modifier les références du constat', + }), + ).toBeVisible() + await user.selectOptions(select(), '') + expect(inCitations().queryByText(pendingLine)).toBeNull() + await user.click(button('Enregistrer')) + await waitFor(() => expect(button('Modifier')).toHaveFocus()) + expect(undos()).toBe(0) + }) + + it('read only: no select and no « Citer »', async () => { + const user = await mount() + await editCitations(user) + act(() => { + setWidth(900) + window.dispatchEvent(new Event('resize')) + }) + expect(inCitations().queryByRole('button', { name: 'Citer' })).toBeNull() + expect( + inCitations().queryByLabelText('Citer une référence existante'), + ).toBeNull() + }) +}) + const live = () => document.querySelector('p.sr-only[aria-live="polite"]')!.textContent ?? '' diff --git a/apps/app/tests/unit/editor-references-panel.test.tsx b/apps/app/tests/unit/editor-references-panel.test.tsx index b442a439..9ed671f2 100644 --- a/apps/app/tests/unit/editor-references-panel.test.tsx +++ b/apps/app/tests/unit/editor-references-panel.test.tsx @@ -58,7 +58,7 @@ const ref = (id: string, citation: string, url = '', doi = '') => }, }) as const -function sheetText(): string { +function sheetText(family = ['ref-a', 'ref-b']): string { let text = baseText() text = insert(text, ref('ref-a', 'Barone, Ostéologie')) text = insert(text, ref('ref-b', 'Denoix', 'https://exemple.org/Épaule')) @@ -77,7 +77,7 @@ function sheetText(): string { kind: 'dysfunction', name: name('Cat A'), description: {}, - reference_ids: ['ref-a', 'ref-b'], + reference_ids: family, review_status: 'to_confirm', children: [], }, @@ -86,8 +86,8 @@ function sheetText(): string { } /** The sheet plus one finding node under Cat A (default: citing ref-a and ref-c). */ -function nodeText(ids = ['ref-a', 'ref-c']): string { - return edit(sheetText(), { +function nodeText(ids = ['ref-a', 'ref-c'], family?: string[]): string { + return edit(sheetText(family), { op: 'insert', parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] }, element: { @@ -590,3 +590,115 @@ describe('the panel review fixes', () => { await focusIs(heading) }) }) + +describe('the family wording (Rev 6)', () => { + const familyHeading = (name: string) => + within(citationsDialog()).getByRole('heading', { name }) + const chip = () => screen.getByTestId('editor-references-filter') + const showAll = (user: User) => + user.click( + within(panel()).getByRole('button', { + name: "Tout afficher dans l'onglet Références", + }), + ) + + it('a family: dialog title, count, its own tile row, edit title', async () => { + const user = await mount() + await select(user, /Cat A/) + await user.click(trigger()) + await focusIs(closeButton) + expect(familyHeading('Références de la famille')).toBeVisible() + expect(panel()).toHaveTextContent('2 références citées par cette famille') + await user.click(within(panel()).getByRole('button', { name: /^Barone/ })) + const tile = tiles()[0] as HTMLElement + expect(within(tile).getByText('cette famille')).toBeInTheDocument() + expect(within(tile).queryByText('famille')).toBeNull() + await user.click( + within(citationsDialog()).getByRole('button', { name: 'Modifier' }), + ) + await waitFor(() => + expect( + familyHeading('Modifier les références de la famille'), + ).toBeVisible(), + ) + }) + + it('a finding keeps the finding wording', async () => { + const user = await mount() + await openFromFinding(user) + expect(heading()).toBeVisible() + expect(panel()).toHaveTextContent('2 références citées par ce constat') + }) + + it('an empty family: the empty line, then the filtered tab names the family', async () => { + const user = await mount(1280, nodeText(['ref-a', 'ref-c'], [])) + await select(user, /Cat A/) + await user.click(trigger('0 référence')) + await focusIs(closeButton) + expect(panel()).toHaveTextContent('Cette famille ne cite aucune référence.') + await showAll(user) + await closed() + expect(chip()).toHaveTextContent('Références de la famille : Cat A') + expect( + within(chip()).getByRole('button', { + name: 'Retirer le filtre de la famille Cat A', + }), + ).toBeVisible() + expect( + within(chip()).getByRole('button', { name: 'Revenir à la famille' }), + ).toBeVisible() + expect(screen.getByTestId('editor-references-no-result')).toHaveTextContent( + 'Cette famille ne cite aucune référence.', + ) + }) + + it('a filtered family removed by an undo says the family is gone', async () => { + const user = await mount() + act(() => { + store.getState().commit({ + op: 'insert', + parent: { kind: 'zone', id: 'zone-a' }, + element: { + kind: 'finding_category', + value: { + id: 'fcat-b', + kind: 'dysfunction', + name: name('Cat B'), + description: {}, + reference_ids: ['ref-c'], + review_status: 'to_confirm', + children: [], + }, + }, + }) + }) + await select(user, /Cat B/) + await user.click(trigger('1 référence')) + await showAll(user) + await closed() + expect(chip()).toHaveTextContent('Références de la famille : Cat B') + act(() => { + store.getState().undoStep() + }) + await waitFor(() => + expect(live()).toHaveTextContent( + "La famille n'existe plus : le filtre est retiré", + ), + ) + }) + + it('a family that vanishes closes its dialog and says the family is gone', async () => { + const user = await mount() + await select(user, /Cat A/) + act(() => { + store.getState().commit({ + op: 'remove', + key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] }, + }) + }) + await waitFor(() => expect(findingDialog()).toBeNull()) + await waitFor(() => + expect(live()).toHaveTextContent("Cette famille n'existe plus"), + ) + }) +})