From 51fd3db608868e9206faa0a2ee8da3e4b6f41ca8 Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 6 Nov 2026 21:23:46 +0100 Subject: [PATCH] feat(editor): no silent loss on a 1 024 px crossing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drawing actions stay mounted and hidden while read-only: an upload in flight, a cleaning candidate, a repair offer and a parent choice come back on widening. Decision dialogs open only while editing, in a shown place, references panel closed; otherwise the decision is held per object, shown as a pending line, reopened by « Reprendre » (absent in read-only). Picker, file input and parent button are disabled while one is pending. Repair geometries move into RepairDialog, keyed on the offer. R-24: no existing assertion rewritten; editor-no-loss-decisions.test.tsx added (12 cases). --- .../components/editor/views/RepairDialog.tsx | 91 ++-- .../components/editor/views/ViewDrawing.tsx | 201 +++++++-- apps/app/src/i18n/en.ts | 4 + apps/app/src/i18n/fr.ts | 4 + .../unit/editor-no-loss-decisions.test.tsx | 411 ++++++++++++++++++ 5 files changed, 646 insertions(+), 65 deletions(-) create mode 100644 apps/app/tests/unit/editor-no-loss-decisions.test.tsx diff --git a/apps/app/src/components/editor/views/RepairDialog.tsx b/apps/app/src/components/editor/views/RepairDialog.tsx index af27f630..d77dc502 100644 --- a/apps/app/src/components/editor/views/RepairDialog.tsx +++ b/apps/app/src/components/editor/views/RepairDialog.tsx @@ -19,59 +19,77 @@ import { useT } from '@/i18n/useT' import { useLocaleStore } from '@/state/localeStore' export interface RepairDialogProps { - /** The refused attach to repair; null keeps the dialog closed. */ + /** The refused attach to repair; null when there is none. Never gated by the caller. */ offer: RepairOffer | null + /** The decision may be shown now (editing, place shown); the typed values stay held. */ + open?: boolean onApplied: () => void onCancel: () => void } +/** The offer, the annotations it lists and the geometries typed so far. */ +interface RepairDraft { + offer: RepairOffer + annotations: Annotation[] + geometries: Record +} + +/** + * The geometries live here, keyed on the offer, so a dialog closed for a width change + * and shown again finds what was typed. The state resets only when a different, non-null + * offer arrives. + */ +function useRepairDraft(offer: RepairOffer | null) { + const doc = useSheetDocument() + const [draft, setDraft] = useState(null) + if (offer !== null && draft?.offer !== offer) { + const annotations = doc ? listedAnnotations(offer, doc) : [] + const geometries = initialGeometries(offer, annotations) + setDraft({ offer, annotations, geometries }) + } + const change = (id: string, geometry: Geometry) => + setDraft((current) => + current + ? { ...current, geometries: { ...current.geometries, [id]: geometry } } + : current, + ) + return { draft: draft?.offer === offer ? draft : null, change } +} + /** * The temporary form of an attach refused for annotations outside the new frame (owner * decision 7). Values are proposals in the new frame; nothing reaches the document before * « Attacher et appliquer », which sends ONE batch the core judges on its end state. */ -export default function RepairDialog({ offer, ...actions }: RepairDialogProps) { +export default function RepairDialog({ + offer, + open = true, + ...actions +}: RepairDialogProps) { const t = useT() const plural = usePlural() + const { draft, change } = useRepairDraft(offer) const count = offer ? new Set(offer.refusal.annotationIds).size : 0 return ( - {offer && } + {draft && } ) } -/** The listed annotations and their temporary geometries (proposals, then typed edits). */ -function useRepairGeometries(offer: RepairOffer) { - const doc = useSheetDocument() - const [annotations] = useState(() => - doc ? listedAnnotations(offer, doc) : [], - ) - const [geometries, setGeometries] = useState(() => - initialGeometries(offer, annotations), - ) - const change = (id: string, geometry: Geometry) => - setGeometries((current) => ({ ...current, [id]: geometry })) - return { annotations, geometries, change } -} - /** « Attacher et appliquer »: one batch, the refusal kept for the rows. */ -function useRepairApply( - offer: RepairOffer, - geometries: Record, - onApplied: () => void, -) { +function useRepairApply(draft: RepairDraft, onApplied: () => void) { const t = useT() const locale = useLocaleStore((s) => s.locale) const [result, setResult] = useState(null) const apply = () => { - const applied = applyRepair(offer, geometries, { t, locale }) + const applied = applyRepair(draft.offer, draft.geometries, { t, locale }) if (applied.ok) onApplied() else setResult(applied) } @@ -93,33 +111,36 @@ function usePendingIds() { return { pending: ids, report } } -function useRepairState(offer: RepairOffer, onApplied: () => void) { - const geometry = useRepairGeometries(offer) - const applied = useRepairApply(offer, geometry.geometries, onApplied) +function useRepairState(draft: RepairDraft, onApplied: () => void) { + const applied = useRepairApply(draft, onApplied) const pending = usePendingIds() const blocked = - blockedIds(geometry.geometries).length > 0 || pending.pending.size > 0 - return { ...geometry, ...applied, report: pending.report, blocked } + blockedIds(draft.geometries).length > 0 || pending.pending.size > 0 + return { ...applied, report: pending.report, blocked } } function RepairForm({ - offer, + draft, + onChange, onApplied, onCancel, -}: Omit & { offer: RepairOffer }) { +}: Pick & { + draft: RepairDraft + onChange: (id: string, geometry: Geometry) => void +}) { const t = useT() - const state = useRepairState(offer, onApplied) + const state = useRepairState(draft, onApplied) const refused = state.result && !state.result.ok ? state.result : null return (
    - {state.annotations.map((annotation) => ( + {draft.annotations.map((annotation) => ( state.change(annotation.id, geometry)} + onChange={(geometry) => onChange(annotation.id, geometry)} onPending={state.report} /> ))} diff --git a/apps/app/src/components/editor/views/ViewDrawing.tsx b/apps/app/src/components/editor/views/ViewDrawing.tsx index c7ac73b0..f7da152b 100644 --- a/apps/app/src/components/editor/views/ViewDrawing.tsx +++ b/apps/app/src/components/editor/views/ViewDrawing.tsx @@ -1,12 +1,18 @@ -import { useRef, useState, type ChangeEvent } from 'react' +import { useId, useRef, useState, type ChangeEvent } from 'react' import type { SheetView } from '@faunosteo/core-wasm/types' import ActionButton from '@/components/editor/fields/ActionButton' +import KeptPlace from '@/components/editor/KeptPlace' import Notice from '@/components/ui/Notice' import { drawingStatusOf, drawingStatusText, type DrawingStatus, } from '@/editor/drawingStatus' +import { + useDecisionGate, + useDecisionsOpen, + useEverEditable, +} from '@/editor/editingContext' import { unmeasuredViews } from '@/editor/issues' import { useDrawingUpload, type DrawingUpload } from '@/editor/useDrawingUpload' import { uploadErrorMessage } from '@/editor/uploadMessages' @@ -33,6 +39,7 @@ export default function ViewDrawing({ }) { const state = useEditorStore((s) => s.previewState) const failures = useEditorStore((s) => s.drawingFailures) + const kept = useEverEditable(readOnly) if (!state) return null const status = drawingStatusOf(view, state, failures) const unmeasured = unmeasuredViews(state).has(view.id) @@ -44,8 +51,12 @@ export default function ViewDrawing({ unmeasured={unmeasured} readOnly={readOnly} /> - {!readOnly && ( - + {kept && ( + )}
) @@ -84,52 +95,140 @@ function DrawingLines({ ) } +type Views = ReturnType + +/** « Utiliser l'illustration de la vue parente »: one token per click is one decision. */ +function useParentChoice(viewId: string, ownDrawing: boolean, views: Views) { + const [asking, setAsking] = useState(null) + if (!ownDrawing && asking !== null) setAsking(null) + const cancel = () => setAsking(null) + const confirm = () => { + cancel() + views.update('drawing', viewId, { svg_asset_id: null }, true) + } + return { asking, ask: () => setAsking({}), confirm, cancel } +} + +/** The three decisions of the section, each held back while it cannot be shown. */ +function useDrawingDecisions( + upload: DrawingUpload, + parent: ReturnType, +) { + const open = useDecisionsOpen() + const { ui } = upload + return { + cleaning: useDecisionGate( + ui.phase === 'cleaning' ? ui.candidate : null, + open, + ), + repair: useDecisionGate(ui.phase === 'repair' ? ui.offer : null, open), + parent: useDecisionGate(parent.asking, open), + } +} + +type Decisions = ReturnType + +/** The id of the pending line, as `hold` while any decision is held back, else null. */ +function useHold(decisions: Decisions) { + const pendingId = `${useId()}-pending` + const pending = Object.values(decisions).some((gate) => gate.withheld) + return { pendingId, hold: pending ? pendingId : null } +} + +/** + * The drawing actions: mounted at the first editable render, then kept and hidden while + * the editor is read-only, so an upload in flight, a pending cleaning, a repair offer + * and a parent choice come back on widening. Their notices stay outside the hidden part. + */ function DrawingActions({ view, ownDrawing, + readOnly, }: { view: SheetView ownDrawing: boolean + readOnly: boolean }) { - const t = useT() const upload = useDrawingUpload(view.id) const views = useViewUpdate() - const [asking, setAsking] = useState(false) - const usesParent = () => { - setAsking(false) - views.update('drawing', view.id, { svg_asset_id: null }, true) - } + const parent = useParentChoice(view.id, ownDrawing, views) + const decisions = useDrawingDecisions(upload, parent) + const { pendingId, hold } = useHold(decisions) return ( <> -
- - {view.kind === 'detail' && ownDrawing && ( - setAsking(true)} - > - {t('editor.views.drawing.use_parent')} - - )} -
- setAsking(false)} - /> + +
+ + {view.kind === 'detail' && ownDrawing && ( + + )} +
+ +
{views.error('drawing') && ( {views.error('drawing')} )} + + + ) +} + +function UseParentButton({ + onClick, + hold, +}: { + onClick: () => void + hold: string | null +}) { + const t = useT() + return ( + + {t('editor.views.drawing.use_parent')} + + ) +} + +function DecisionDialogs({ + upload, + parent, + decisions, +}: { + upload: DrawingUpload + parent: ReturnType + decisions: Decisions +}) { + const { ui } = upload + return ( + <> + void upload.confirmCleaning()} onCancel={upload.cancelCleaning} /> @@ -137,12 +236,52 @@ function DrawingActions({ ) } +/** A decision held back shows as a pending line; « Reprendre » (editing only) reopens it. */ +function PendingNotices({ + id, + decisions, + readOnly, +}: { + id: string + decisions: Decisions + readOnly: boolean +}) { + const t = useT() + const open = useDecisionsOpen() + const kinds = (Object.keys(decisions) as (keyof Decisions)[]).filter( + (kind) => decisions[kind].withheld, + ) + if (kinds.length === 0) return null + return ( +
+ {kinds.map((kind) => ( + +

{t(`editor.views.pending.${kind}`)}

+ + {t('editor.views.pending.resume')} + +
+ ))} +
+ ) +} + function FilePicker({ viewId, upload, + hold, }: { viewId: string upload: DrawingUpload + /** The id of the pending line while a decision is pending: no pick replaces it. */ + hold: string | null }) { const t = useT() const input = useRef(null) @@ -161,13 +300,15 @@ function FilePicker({ tabIndex={-1} aria-label={t('editor.views.drawing.file')} data-testid={`view-${viewId}-file`} + disabled={hold !== null} onChange={pick} /> input.current?.click()} > {t('editor.views.drawing.choose')} diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 0ddf5c15..9703cab3 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -1393,6 +1393,10 @@ export const en: Dict = { 'editor.views.drawing.use_parent_body': "The view will show the parent view's drawing through its crop. Its own drawing file stays stored, and you can undo this change (Undo). The view's annotations go back to \"to confirm\".", 'editor.views.drawing.use_parent_confirm': "Use the parent drawing", 'editor.views.drawing.use_parent_cancel': 'Cancel', + 'editor.views.pending.cleaning': 'A drawing cleaning is waiting for your decision.', + 'editor.views.pending.repair': 'An annotation repair is waiting for your decision.', + 'editor.views.pending.parent': "Going back to the parent view's drawing is waiting for your confirmation.", + 'editor.views.pending.resume': 'Resume', 'editor.views.crop.title': 'Crop', 'editor.views.crop.toggle': 'Edit the crop', 'editor.views.crop.min_x': 'Crop: minimum x', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index e9e006ea..0b62d610 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -1424,6 +1424,10 @@ export const fr: Dict = { 'editor.views.drawing.use_parent_body': "La vue affichera l'illustration de la vue parente à travers son recadrage. Son propre fichier d'illustration reste enregistré, et vous pouvez annuler ce changement (Annuler). Les annotations de la vue repassent « à confirmer ».", 'editor.views.drawing.use_parent_confirm': "Utiliser l'illustration parente", 'editor.views.drawing.use_parent_cancel': 'Annuler', + 'editor.views.pending.cleaning': "Un nettoyage de l'illustration attend votre décision.", + 'editor.views.pending.repair': 'Une réparation des annotations attend votre décision.', + 'editor.views.pending.parent': "Le retour à l'illustration de la vue parente attend votre confirmation.", + 'editor.views.pending.resume': 'Reprendre', 'editor.views.crop.title': 'Recadrage', 'editor.views.crop.toggle': 'Modifier le recadrage', 'editor.views.crop.min_x': 'Recadrage : x minimum', diff --git a/apps/app/tests/unit/editor-no-loss-decisions.test.tsx b/apps/app/tests/unit/editor-no-loss-decisions.test.tsx new file mode 100644 index 00000000..f18d523a --- /dev/null +++ b/apps/app/tests/unit/editor-no-loss-decisions.test.tsx @@ -0,0 +1,411 @@ +/** U1 Lot B2b: the drawing actions of the views section across a crossing and a held decision. */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { + act, + cleanup, + fireEvent, + screen, + waitFor, + within, +} from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import type { Annotation } from '@faunosteo/core-wasm/types' +import { cleanSvg } from '@/editor/core/cleaning' +import { useLocaleStore } from '@/state/localeStore' +import { emptyText, insert, point, svgBytes } from '../helpers/editorFixtures' +import { + baseText, + resetStore, + sb, + serverHas, + store, +} from '../helpers/editorHarness' +import { + adminAnswer, + mountDraft, + round, + setWidth, +} from '../helpers/editorRoute' + +vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) })) +vi.mock('@faunosteo/supabase', async (orig) => ({ + ...(await orig()), + getSheetVersion: vi.fn(), + downloadSheetDrawing: vi.fn(), + saveSheetDraft: vi.fn(), + getOfficialSheetAdmin: vi.fn(), + submitSheetReview: vi.fn(), + registerSheetAsset: vi.fn(), + listSheetAssets: vi.fn(), + uploadSheetDrawing: vi.fn(), + confirmSheetAssetUpload: vi.fn(), +})) + +const NEW_ASSET = '22222222-2222-4222-8222-222222222222' +const svg = (inner = '') => + `${inner}` +const CLEAN = svg() +const DIRTY = svg( + '', +) + +beforeEach(() => { + useLocaleStore.setState({ locale: 'fr' }) + const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 } + Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', { + configurable: true, + value: () => ({ ...identity, inverse: () => identity }), + }) +}) +afterEach(() => { + cleanup() + resetStore() + setWidth(1024) +}) + +const tab = (name: string | RegExp) => screen.getByRole('tab', { name }) +const button = (name: string | RegExp) => screen.getByRole('button', { name }) +const maybeButton = (name: string | RegExp) => + screen.queryByRole('button', { name }) +const dialogs = () => document.querySelectorAll('dialog[open]').length +const doc = () => JSON.parse(store.getState().documentText) +const mainAsset = () => doc().views[0].svg_asset_id +const fileInput = (view = 'main') => + screen.getByTestId(`view-view-${view}-file`) as HTMLInputElement + +function cross(width: number) { + act(() => { + setWidth(width) + window.dispatchEvent(new Event('resize')) + }) +} + +function serverGets(text: string) { + const cleaned = cleanSvg(new TextEncoder().encode(text)) + if (!cleaned.ok || !cleaned.value.stored) throw new Error('bad svg') + const bytes = new TextEncoder().encode(cleaned.value.stored) + sb.registerSheetAsset.mockResolvedValue(NEW_ASSET) + sb.listSheetAssets.mockResolvedValue([ + { + id: NEW_ASSET, + sha256: cleaned.value.sha256!, + byte_size: cleaned.value.byte_size!, + uploaded_at: null, + }, + ]) + sb.uploadSheetDrawing.mockResolvedValue('uploaded') + sb.confirmSheetAssetUpload.mockResolvedValue(NEW_ASSET) + sb.downloadSheetDrawing.mockImplementation(async (_c, hash) => + hash === cleaned.value.sha256 ? bytes : svgBytes().bytes, + ) +} + +/** A file whose bytes arrive when `release` runs: the decision settles at a chosen time. */ +function heldFile(text: string) { + let release: () => void = () => undefined + const gate = new Promise((resolve) => (release = resolve)) + const file = new File([text], 'd.svg', { type: 'image/svg+xml' }) + Object.defineProperty(file, 'arrayBuffer', { + value: async () => { + await gate + return new TextEncoder().encode(text).buffer + }, + }) + return { file, release } +} + +const pick = (file: File, view = 'main') => + fireEvent.change(fileInput(view), { target: { files: [file] } }) +const plain = (text: string) => + new File([text], 'd.svg', { type: 'image/svg+xml' }) + +async function mountViews(text = baseText()) { + serverHas(text, 3) + serverGets(CLEAN) + const user = userEvent.setup() + mountDraft() + await screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' }) + await user.click(tab('Annotations')) + await user.click(button('Gérer les vues')) + return user +} + +const PENDING = /nettoyage de l'illustration attend votre décision/ +const RESUME = 'Reprendre' + +describe('a cleaning decision across a crossing', () => { + it('closes with the editor, shows as pending, reopens only through « Reprendre »', async () => { + const user = await mountViews() + serverGets(DIRTY) + pick(plain(DIRTY)) + await screen.findByRole('dialog') + cross(800) + await waitFor(() => expect(dialogs()).toBe(0)) + expect(screen.getByText(PENDING)).toBeVisible() + expect(maybeButton(RESUME)).toBeNull() + cross(1280) + expect(dialogs()).toBe(0) + expect(screen.getByText(PENDING)).toBeVisible() + await user.click(button(RESUME)) + const dialog = within(await screen.findByRole('dialog')) + expect(dialog.getByText('style')).toBeVisible() + await user.click( + dialog.getByRole('button', { + name: 'Nettoyer et utiliser cette version', + }), + ) + await waitFor(() => expect(mainAsset()).toBe(NEW_ASSET)) + expect(screen.queryByText(PENDING)).toBeNull() + }) + + it('disables the picker, the file input and the parent button while it is pending', async () => { + const user = await mountViews() + pick(plain(DIRTY)) + await screen.findByRole('dialog') + cross(800) + cross(1280) + const picker = button('Choisir une illustration') + expect(picker).toBeDisabled() + expect(fileInput()).toBeDisabled() + const note = screen.getByText(PENDING).closest('[id]')! + expect(picker).toHaveAttribute('aria-describedby', note.id) + await user.click(button(RESUME)) + await user.click( + within(await screen.findByRole('dialog')).getByRole('button', { + name: 'Annuler', + }), + ) + expect(button('Choisir une illustration')).toBeEnabled() + expect(fileInput()).toBeEnabled() + }) + + it('a new decision opens on its own once the held one has ended', async () => { + const user = await mountViews() + pick(plain(DIRTY)) + await screen.findByRole('dialog') + cross(800) + cross(1280) + await user.click(button(RESUME)) + await user.click( + within(await screen.findByRole('dialog')).getByRole('button', { + name: 'Annuler', + }), + ) + pick(plain(DIRTY)) + expect(await screen.findByRole('dialog')).toBeVisible() + expect(screen.queryByText(PENDING)).toBeNull() + }) + + it('narrow with a held decision: the pending text, no « Reprendre »; none after widening until clicked', async () => { + const user = await mountViews() + pick(plain(DIRTY)) + await screen.findByRole('dialog') + cross(800) + await waitFor(() => expect(dialogs()).toBe(0)) + expect(screen.getByText(PENDING)).toBeVisible() + expect(maybeButton(RESUME)).toBeNull() + expect( + screen.queryByRole('button', { name: 'Choisir une illustration' }), + ).toBeNull() + cross(1280) + expect(dialogs()).toBe(0) + await user.click(button(RESUME)) + expect(await screen.findByRole('dialog')).toBeVisible() + }) +}) + +describe('a decision that settles in a place that is not shown', () => { + it('an offer settling with the section hidden opens nothing until « Reprendre »', async () => { + const user = await mountViews() + const held = heldFile(DIRTY) + pick(held.file) + await user.click(button('Retour au dessin')) + await act(async () => held.release()) + await waitFor(() => expect(sb.registerSheetAsset).not.toHaveBeenCalled()) + expect(dialogs()).toBe(0) + await user.click(button('Gérer les vues')) + expect(dialogs()).toBe(0) + expect(screen.getByText(PENDING)).toBeVisible() + await user.click(button(RESUME)) + expect(await screen.findByRole('dialog')).toBeVisible() + }) + + it('a widening on another tab opens nothing; the tab keeps its focus', async () => { + const user = await mountViews() + const held = heldFile(DIRTY) + pick(held.file) + await user.click(tab('Général')) + await act(async () => held.release()) + cross(800) + cross(1280) + expect(dialogs()).toBe(0) + await user.click(tab('Annotations')) + expect(document.activeElement).toBe(tab('Annotations')) + expect(dialogs()).toBe(0) + expect(screen.getByText(PENDING)).toBeVisible() + }) + + it('the open references panel holds the decision back, « Reprendre » waits for it to close', async () => { + const user = await mountViews() + const held = heldFile(DIRTY) + pick(held.file) + await user.click(button('Références')) + await act(async () => held.release()) + expect(dialogs()).toBe(0) + expect(button(RESUME)).toBeDisabled() + await user.click(button('Références')) + await user.click(button(RESUME)) + expect(await screen.findByRole('dialog')).toBeVisible() + }) + + it('an upload settling while read-only lands in the live hook, its notice shown', async () => { + const user = await mountViews() + let finish: (value: string) => void = () => undefined + sb.registerSheetAsset.mockReturnValue( + new Promise((resolve) => (finish = resolve)), + ) + pick(plain(CLEAN)) + expect(await screen.findByText(/Vérification et envoi/)).toBeVisible() + cross(800) + expect(screen.getByText(/Vérification et envoi/)).toBeVisible() + await act(async () => finish(NEW_ASSET)) + await waitFor(() => expect(mainAsset()).toBe(NEW_ASSET)) + expect(store.getState().unsaved).toBe(true) + cross(1280) + expect(await screen.findByText(/est ajoutée à la vue/)).toBeVisible() + void user + }) +}) + +const detailOwn = (assetId: string | null) => + ({ + kind: 'view', + value: { + kind: 'detail', + id: 'view-d', + name: { fr: 'Détail', en: 'Detail' }, + svg_asset_id: assetId, + view_box: { min_x: 0, min_y: 0, width: 50, height: 50 }, + parent_view_id: 'view-main', + }, + }) as Parameters[1] + +describe('the parent choice', () => { + const USE_PARENT = "Utiliser l'illustration de la vue parente" + + async function mountDetail() { + const user = await mountViews(insert(baseText(), detailOwn(NEW_ASSET))) + return user + } + + it('is a decision per click: held across a crossing, a new click opens on its own', async () => { + const user = await mountDetail() + await user.click(button(USE_PARENT)) + expect(await screen.findByRole('dialog')).toBeVisible() + cross(800) + await waitFor(() => expect(dialogs()).toBe(0)) + expect( + screen.getByText(/retour à l'illustration de la vue parente/), + ).toBeVisible() + cross(1280) + expect(button(USE_PARENT)).toBeDisabled() + await user.click(button(RESUME)) + await user.click( + within(await screen.findByRole('dialog')).getByRole('button', { + name: 'Annuler', + }), + ) + await user.click(button(USE_PARENT)) + expect(await screen.findByRole('dialog')).toBeVisible() + }) +}) + +/** An unmeasured main view with annotations far outside a 100 x 100 frame. */ +function unmeasuredText(): string { + let text = insert(emptyText(), { + kind: 'category', + value: { id: 'cat-a', name: { fr: 'N', en: 'N' }, color: null }, + }) + text = insert(text, point('anno-a', 500, 400, 5)) + const zone = { + ...(point('anno-z', 0, 0, 1).value as Annotation), + kind: 'zone' as const, + geometry: { + type: 'polygon' as const, + points: [ + [10, 10], + [400, 10], + [400, 400], + ] as [number, number][], + }, + } + return insert(text, { kind: 'annotation', value: zone as Annotation }) +} + +describe('the repair offer', () => { + it('keeps its typed geometries across a crossing and « Reprendre »', async () => { + const user = await mountViews(unmeasuredText()) + pick(plain(CLEAN)) + const first = await screen.findByRole('dialog') + const row = within(within(first).getByTestId('repair-anno-a')) + const x = row.getByLabelText('Centre x') + await user.clear(x) + await user.type(x, '60{Enter}') + cross(800) + await waitFor(() => expect(dialogs()).toBe(0)) + expect(screen.getByText(/réparation des annotations attend/)).toBeVisible() + cross(1280) + expect(dialogs()).toBe(0) + await user.click(button(RESUME)) + const again = within(await screen.findByRole('dialog')) + expect( + within(again.getByTestId('repair-anno-a')).getByLabelText('Centre x'), + ).toHaveValue('60') + expect(mainAsset()).toBeNull() + }) +}) + +describe('limits of a held decision', () => { + it('is lost with its view (undo), redo does not bring it back', async () => { + const user = await mountViews(baseText()) + const added = store.getState().commit({ + op: 'insert', + element: detailOwn(null) as never, + } as never) + expect(added.ok).toBe(true) + await screen.findByTestId('view-view-d-file') + pick(plain(DIRTY), 'd') + await screen.findByRole('dialog') + cross(800) + cross(1280) + expect(screen.getByText(PENDING)).toBeVisible() + act(() => void store.getState().undoStep()) + await waitFor(() => expect(screen.queryByText(PENDING)).toBeNull()) + act(() => void store.getState().redoStep()) + await screen.findByTestId('view-view-d-file') + expect(screen.queryByText(PENDING)).toBeNull() + expect(maybeButton(RESUME)).toBeNull() + void user + }) + + it('stays a pending line without action once the draft is frozen by a submission', async () => { + const user = await mountViews() + const held = heldFile(DIRTY) + pick(held.file) + await user.click(tab(/Vérification/)) + await act(async () => held.release()) + sb.submitSheetReview.mockResolvedValue('review-1' as never) + await user.type( + screen.getByLabelText('Note de soumission (obligatoire)'), + 'Prête', + ) + sb.getOfficialSheetAdmin.mockResolvedValue( + adminAnswer({ rounds: [round('open')] }) as never, + ) + await user.click(button('Soumettre à la revue')) + await user.click(tab('Annotations')) + await waitFor(() => expect(screen.getByText(PENDING)).toBeVisible()) + expect(maybeButton(RESUME)).toBeNull() + expect(dialogs()).toBe(0) + }) +})