From 05c9b3e10b11aa7b46fbdf8025bc5945507ed408 Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 4 Nov 2026 18:06:40 +0100 Subject: [PATCH] fix(editor): read-only undo, upload session check, restore and submit guards --- .../2026-11-03-v1-2-6-label-proposals.md | 10 ++++++-- apps/app/e2e/shell/editor-access.spec.ts | 2 +- apps/app/e2e/shell/editor-annotations.spec.ts | 2 +- apps/app/e2e/shell/editor-drawings.spec.ts | 2 +- apps/app/e2e/shell/editor-equine.spec.ts | 2 +- apps/app/e2e/shell/editor-geometry.spec.ts | 7 ++---- apps/app/e2e/shell/editor-journey.spec.ts | 2 +- apps/app/e2e/shell/editor-recovery.spec.ts | 4 ++-- apps/app/e2e/shell/editor-structures.spec.ts | 2 +- .../routes/app/admin/AdminSheetDraftRoute.tsx | 2 +- apps/app/src/editor/drawingUpload.ts | 4 +++- apps/app/src/editor/state/editorEdit.ts | 2 +- apps/app/src/editor/state/editorSave.ts | 2 +- apps/app/src/editor/state/recoveryFlow.ts | 4 ++-- apps/app/src/i18n/en.ts | 8 +++---- apps/app/src/i18n/fr.ts | 8 +++---- .../tests/unit/editor-drawing-upload.test.tsx | 22 +++++++++++++++++ apps/app/tests/unit/editor-recovery.test.ts | 24 +++++++++++++++++++ apps/app/tests/unit/editor-store.test.ts | 12 ++++++++++ .../tests/unit/editor-undo-shortcuts.test.tsx | 14 +++++++---- 20 files changed, 102 insertions(+), 33 deletions(-) diff --git a/.claude/audits/2026-11-03-v1-2-6-label-proposals.md b/.claude/audits/2026-11-03-v1-2-6-label-proposals.md index 77cd15fb..951538cc 100644 --- a/.claude/audits/2026-11-03-v1-2-6-label-proposals.md +++ b/.claude/audits/2026-11-03-v1-2-6-label-proposals.md @@ -437,8 +437,8 @@ Every key below is a proposal for the owner's separate review; none is declared | `editor.verification.issue.annotation.no_findings` | Cette annotation n'est liée à aucune zone de constats : un clic dessus ne proposera rien. | This annotation is linked to no findings zone: a click on it will offer nothing. | Warning | proposal | | `editor.verification.issue.annotation.geometry.missing` | Cette annotation n'a pas de géométrie. | This annotation has no geometry. | Issue | proposal | | `editor.verification.issue.annotation.geometry.out_of_frame` | Cette annotation n'est pas entièrement dans le cadre de sa vue. | This annotation is not entirely inside the frame of its view. | Issue | proposal | -| `editor.verification.issue.annotation.geometry.too_small` | Cette annotation s'affiche trop petite sur l'aperçu téléphone. | This annotation shows too small on the phone preview. | Issue | proposal | -| `editor.verification.issue.annotation.geometry.interior_too_small` | L'intérieur de cette zone est trop étroit pour être touché sur l'aperçu téléphone. | The inside of this zone is too narrow to tap on the phone preview. | Issue | proposal | +| `editor.verification.issue.annotation.geometry.too_small` | Un repère est trop petit pour être touché sur mobile. | A marker is too small to tap on a phone. | Issue | ratified, reused (REVUE.md Arbitrages `marker_too_small`, §17.9) | +| `editor.verification.issue.annotation.geometry.interior_too_small` | L'intérieur d'une zone est trop étroit pour être touché sur mobile. | A zone's interior is too narrow to tap on a phone. | Issue | ratified, reused (REVUE.md `marker_interior_too_small`) | | `editor.verification.issue.region.code.duplicate` | Deux régions vertébrales ont le même code. | Two vertebral regions have the same code. | Issue | proposal | | `editor.verification.issue.region.count_range.invalid` | Le nombre habituel de cette région n'est pas dans la variation indiquée. | The usual count of this region is outside the stated variation. | Issue | proposal | | `editor.verification.issue.category.id.duplicate` | Deux catégories d'annotation ont le même identifiant. | Two annotation categories have the same id. | Issue | proposal | @@ -472,3 +472,9 @@ about the local copy says it is temporary, limited to this tab and not saved on | `editor.refusal.recovery` | Répondez d'abord à la copie locale temporaire de cet onglet proposée en haut de page : elle n'est pas enregistrée sur le serveur. | First answer this tab's temporary local copy offered at the top of the page: it is not saved on the server. | Three facts (C25) | | `admin.failure.round.open` | Une revue est déjà en cours sur ce brouillon : il ne peut pas être soumis de nouveau. | A review is already under way on this draft: it cannot be submitted again. | New: `submit_sheet_review` raises `round.open`; it read « Le service ne répond pas » | | `admin.failure.view.asset.unknown` | Une illustration du brouillon n'est pas enregistrée pour cette fiche : choisissez-la de nouveau dans l'onglet Vues et illustrations. | A drawing of the draft is not registered for this sheet: choose it again in the Views and drawings tab. | New: raised by `submit_sheet_review` and publication | + +### Lot M fix 3 +| Key | FR | EN | Why | +|---|---|---|---| +| `editor.draft.status.copy_quota` | Copie locale temporaire impossible (onglet plein) : non enregistré sur le serveur | Temporary local copy impossible (tab full): not saved on the server | C25: header status said nothing about the server (was « …(stockage de l'onglet plein) ») | +| `editor.draft.status.copy_cap` | Copie locale temporaire impossible (deux autres copies dans cet onglet) : non enregistré sur le serveur | Temporary local copy impossible (two other copies in this tab): not saved on the server | C25 (was « …: deux autres brouillons ont déjà une copie dans cet onglet ») | diff --git a/apps/app/e2e/shell/editor-access.spec.ts b/apps/app/e2e/shell/editor-access.spec.ts index 9bf5471e..6a9704c2 100644 --- a/apps/app/e2e/shell/editor-access.spec.ts +++ b/apps/app/e2e/shell/editor-access.spec.ts @@ -72,7 +72,7 @@ async function expectReadOnly(page: Page) { test.describe('editor access, narrow screens and axe', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'the widths are set by the tests themselves') + test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { diff --git a/apps/app/e2e/shell/editor-annotations.spec.ts b/apps/app/e2e/shell/editor-annotations.spec.ts index 96f140d4..36a52eb9 100644 --- a/apps/app/e2e/shell/editor-annotations.spec.ts +++ b/apps/app/e2e/shell/editor-annotations.spec.ts @@ -68,7 +68,7 @@ async function openAnnotations(page: Page) { test.describe('editor annotations (A3)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'editing needs 1 024 px') + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { diff --git a/apps/app/e2e/shell/editor-drawings.spec.ts b/apps/app/e2e/shell/editor-drawings.spec.ts index 9027e828..3e3203a9 100644 --- a/apps/app/e2e/shell/editor-drawings.spec.ts +++ b/apps/app/e2e/shell/editor-drawings.spec.ts @@ -39,7 +39,7 @@ const mainDrawing = (page: Page) => page.getByTestId('view-main-drawing') test.describe('editor drawings (A2)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'editing needs 1 024 px') + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { diff --git a/apps/app/e2e/shell/editor-equine.spec.ts b/apps/app/e2e/shell/editor-equine.spec.ts index 2a7c0639..6522ff18 100644 --- a/apps/app/e2e/shell/editor-equine.spec.ts +++ b/apps/app/e2e/shell/editor-equine.spec.ts @@ -211,7 +211,7 @@ test.describe('equine working copy and commit latency', () => { test.use({ locale: 'fr-FR', actionTimeout: 30_000 }) // Skipped as a whole on the phone project: beforeAll and afterAll toggle the copies' // status and must run in one worker only. - test.skip(({ isMobile }) => isMobile, 'editing needs 1 024 px') + test.skip(({ isMobile }) => isMobile, 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access let actor: Actor let setAside: string[] = [] let copyId = '' diff --git a/apps/app/e2e/shell/editor-geometry.spec.ts b/apps/app/e2e/shell/editor-geometry.spec.ts index 10a0c864..e98652f8 100644 --- a/apps/app/e2e/shell/editor-geometry.spec.ts +++ b/apps/app/e2e/shell/editor-geometry.spec.ts @@ -67,7 +67,7 @@ async function open(page: Page, ...annotations: unknown[]) { test.describe('editor geometry (adversarial)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'editing needs 1 024 px') + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { @@ -255,10 +255,7 @@ test.describe('editor touch path (real browser)', () => { viewport: { width: 1280, height: 800 }, }) test.beforeEach(async ({ context }, info) => { - test.skip( - isPhone(info), - 'a 1 024 px touch screen runs on the desktop project', - ) + test.skip(isPhone(info), 'touch at 1 024 px runs on desktop') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { diff --git a/apps/app/e2e/shell/editor-journey.spec.ts b/apps/app/e2e/shell/editor-journey.spec.ts index 68b8db70..311a022b 100644 --- a/apps/app/e2e/shell/editor-journey.spec.ts +++ b/apps/app/e2e/shell/editor-journey.spec.ts @@ -242,7 +242,7 @@ async function reloadAndRestore(page: Page, sheetId: string) { test.describe('editor journey (owner trial steps)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'editing needs 1 024 px') + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { diff --git a/apps/app/e2e/shell/editor-recovery.spec.ts b/apps/app/e2e/shell/editor-recovery.spec.ts index d8546374..0d41e079 100644 --- a/apps/app/e2e/shell/editor-recovery.spec.ts +++ b/apps/app/e2e/shell/editor-recovery.spec.ts @@ -83,7 +83,7 @@ async function advanceServer(actor: Actor, draftId: string, revision: number) { test.describe('editor recovery and concurrency', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'editing needs 1 024 px') + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { @@ -313,7 +313,7 @@ test.describe('editor recovery and concurrency', () => { test.describe('rights changing under an open editing session', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'editing needs 1 024 px') + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { diff --git a/apps/app/e2e/shell/editor-structures.spec.ts b/apps/app/e2e/shell/editor-structures.spec.ts index 48faccb6..d463927f 100644 --- a/apps/app/e2e/shell/editor-structures.spec.ts +++ b/apps/app/e2e/shell/editor-structures.spec.ts @@ -41,7 +41,7 @@ async function commitText(field: Locator, value: string) { test.describe('editor structures (A4)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { - test.skip(isPhone(info), 'editing needs 1 024 px') + test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { diff --git a/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx b/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx index cee555be..befd22ee 100644 --- a/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx +++ b/apps/app/src/app/routes/app/admin/AdminSheetDraftRoute.tsx @@ -106,7 +106,7 @@ function DraftEditor({ }, [versionId, userId]) useEffect(() => useEditorStore.getState().setCanEdit(canEdit), [canEdit]) useLeaveGuard(useEditorStore(leaveGuardArmed)) - useUndoShortcuts(canEdit && recovery === 'none') + useUndoShortcuts(mode === 'edit' && recovery === 'none') if (status === 'failed' && failure !== null) { if (failure === 'denied') return diff --git a/apps/app/src/editor/drawingUpload.ts b/apps/app/src/editor/drawingUpload.ts index 0b6e51ee..152cf095 100644 --- a/apps/app/src/editor/drawingUpload.ts +++ b/apps/app/src/editor/drawingUpload.ts @@ -147,10 +147,12 @@ export async function registerAndUpload( export async function downloadAndHold( assetId: string, sha256: string, + live: () => boolean, ): Promise> { const client = getSupabaseClient() if (!client) return fail({ code: 'sheet', kind: 'unavailable' }) const fetched = await fetchDrawing(client, { asset_id: assetId, sha256 }) + if (!live()) return fail({ code: 'stale' }) if (!fetched.ok) return fail({ code: 'catalogue', failure: fetched.failure }) const held = useEditorStore.getState().addDrawing(fetched.drawing) if (held.ok) return done(null) @@ -193,7 +195,7 @@ export async function uploadDrawing( const stored = await registerAndUpload(sheetId, drawing) if (!live()) return fail({ code: 'stale' }) if (!stored.ok) return stored - const held = await downloadAndHold(stored.value, drawing.sha256) + const held = await downloadAndHold(stored.value, drawing.sha256, live) if (!live()) return fail({ code: 'stale' }) return held.ok ? attachToView(viewId, stored.value) : held } diff --git a/apps/app/src/editor/state/editorEdit.ts b/apps/app/src/editor/state/editorEdit.ts index bb468b1b..f49076d6 100644 --- a/apps/app/src/editor/state/editorEdit.ts +++ b/apps/app/src/editor/state/editorEdit.ts @@ -31,7 +31,7 @@ function replacedPatch( documentText: text, previewState: next, handleVersion: state.handleVersion + 1, - unsaved: !sameDocument(text, state.savedText), + unsaved: state.staleBase || !sameDocument(text, state.savedText), undo: history.undo, redo: history.redo, } diff --git a/apps/app/src/editor/state/editorSave.ts b/apps/app/src/editor/state/editorSave.ts index 70d16427..d97a995c 100644 --- a/apps/app/src/editor/state/editorSave.ts +++ b/apps/app/src/editor/state/editorSave.ts @@ -164,7 +164,7 @@ export async function submit(api: StoreApi, note?: string): Promise { - const text = copyText(copy) + const text = JSON.stringify(next.document) return { documentText: text, previewState: next, @@ -183,7 +183,7 @@ function restoredPatch( drawingFailures: { ...now.drawingFailures, ...attached.failures }, savedRevision: copy.revision, staleBase: copy.revision < now.savedRevision, - unsaved: !sameDocument(text, now.savedText), + unsaved: copy.revision < now.savedRevision || !sameDocument(text, now.savedText), ...emptyHistory(), ...NO_RECOVERY, } diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 0281c1d1..6d3c2eba 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -1205,8 +1205,8 @@ export const en: Dict = { 'editor.draft.status.revision': 'Revision {revision}', 'editor.draft.status.unsaved': 'unsaved changes', 'editor.draft.status.saving': 'Saving…', - 'editor.draft.status.copy_quota': "Temporary local copy impossible (this tab's storage is full)", - 'editor.draft.status.copy_cap': "Temporary local copy impossible: two other drafts already have a copy in this tab", + 'editor.draft.status.copy_quota': "Temporary local copy impossible (tab full): not saved on the server", + 'editor.draft.status.copy_cap': "Temporary local copy impossible (two other copies in this tab): not saved on the server", 'editor.draft.copy_kept': "A temporary local copy, limited to this tab, is kept; it is not saved on the server.", 'editor.draft.copy_not_kept': "No temporary local copy could be written in this tab: these changes are saved nowhere, neither in the tab nor on the server.", 'editor.draft.mode.narrow': 'Editing requires a screen at least 1,024 px wide.', @@ -1574,8 +1574,8 @@ export const en: Dict = { 'editor.verification.issue.annotation.no_findings': 'This annotation is linked to no findings zone: a click on it will offer nothing.', 'editor.verification.issue.annotation.geometry.missing': 'This annotation has no geometry.', 'editor.verification.issue.annotation.geometry.out_of_frame': 'This annotation is not entirely inside the frame of its view.', - 'editor.verification.issue.annotation.geometry.too_small': 'This annotation shows too small on the phone preview.', - 'editor.verification.issue.annotation.geometry.interior_too_small': 'The inside of this zone is too narrow to tap on the phone preview.', + 'editor.verification.issue.annotation.geometry.too_small': 'A marker is too small to tap on a phone.', + 'editor.verification.issue.annotation.geometry.interior_too_small': "A zone's interior is too narrow to tap on a phone.", 'editor.verification.issue.region.code.duplicate': 'Two vertebral regions have the same code.', 'editor.verification.issue.region.count_range.invalid': 'The usual count of this region is outside the stated variation.', 'editor.verification.issue.category.id.duplicate': 'Two annotation categories have the same id.', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index 31ad1dbb..60390b54 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -1236,8 +1236,8 @@ export const fr: Dict = { 'editor.draft.status.revision': 'Révision {revision}', 'editor.draft.status.unsaved': 'modifications non enregistrées', 'editor.draft.status.saving': 'Enregistrement…', - 'editor.draft.status.copy_quota': "Copie locale temporaire impossible (stockage de l'onglet plein)", - 'editor.draft.status.copy_cap': "Copie locale temporaire impossible : deux autres brouillons ont déjà une copie dans cet onglet", + 'editor.draft.status.copy_quota': "Copie locale temporaire impossible (onglet plein) : non enregistré sur le serveur", + 'editor.draft.status.copy_cap': "Copie locale temporaire impossible (deux autres copies dans cet onglet) : non enregistré sur le serveur", 'editor.draft.copy_kept': "Une copie locale temporaire, propre à cet onglet, est conservée ; elle n'est pas enregistrée sur le serveur.", 'editor.draft.copy_not_kept': "Aucune copie locale temporaire n'a pu être écrite dans cet onglet : ces modifications ne sont enregistrées nulle part, ni dans l'onglet ni sur le serveur.", 'editor.draft.mode.narrow': "L'édition nécessite une largeur d'écran d'au moins 1 024 px.", @@ -1605,8 +1605,8 @@ export const fr: Dict = { 'editor.verification.issue.annotation.no_findings': "Cette annotation n'est liée à aucune zone de constats : un clic dessus ne proposera rien.", 'editor.verification.issue.annotation.geometry.missing': "Cette annotation n'a pas de géométrie.", 'editor.verification.issue.annotation.geometry.out_of_frame': "Cette annotation n'est pas entièrement dans le cadre de sa vue.", - 'editor.verification.issue.annotation.geometry.too_small': "Cette annotation s'affiche trop petite sur l'aperçu téléphone.", - 'editor.verification.issue.annotation.geometry.interior_too_small': "L'intérieur de cette zone est trop étroit pour être touché sur l'aperçu téléphone.", + 'editor.verification.issue.annotation.geometry.too_small': "Un repère est trop petit pour être touché sur mobile.", + 'editor.verification.issue.annotation.geometry.interior_too_small': "L'intérieur d'une zone est trop étroit pour être touché sur mobile.", 'editor.verification.issue.region.code.duplicate': 'Deux régions vertébrales ont le même code.', 'editor.verification.issue.region.count_range.invalid': "Le nombre habituel de cette région n'est pas dans la variation indiquée.", 'editor.verification.issue.category.id.duplicate': "Deux catégories d'annotation ont le même identifiant.", diff --git a/apps/app/tests/unit/editor-drawing-upload.test.tsx b/apps/app/tests/unit/editor-drawing-upload.test.tsx index 3f67721a..607eef16 100644 --- a/apps/app/tests/unit/editor-drawing-upload.test.tsx +++ b/apps/app/tests/unit/editor-drawing-upload.test.tsx @@ -127,6 +127,28 @@ describe('drawing upload flow', () => { ).toBeTruthy() }) + it('a download that ends after another draft opened holds nothing in the new session', async () => { + const stored = serverGets(svg('0 0 200 100')) + let release: (bytes: Uint8Array) => void = () => {} + const held = new Promise((resolve) => (release = resolve)) + sb.downloadSheetDrawing.mockImplementation(async (_c, hash) => + hash === stored.sha256 ? held : await baseBytes(), + ) + await pick(svg('0 0 200 100')) + await waitFor(() => + expect(sb.downloadSheetDrawing).toHaveBeenCalledWith({}, stored.sha256), + ) + store.getState().close() + await openReady() + const session = store.getState().session + release(stored.bytes) + await new Promise((done) => setTimeout(done, 50)) + expect(store.getState().session).toBe(session) + expect(store.getState().drawings.map((d) => d.asset_id)).not.toContain( + NEW_ASSET, + ) + }) + it('a cleanable file shows the dialog with the core-composed drawing, then uploads on accept', async () => { const dirty = svg( '0 0 200 100', diff --git a/apps/app/tests/unit/editor-recovery.test.ts b/apps/app/tests/unit/editor-recovery.test.ts index 70684a99..0e06c490 100644 --- a/apps/app/tests/unit/editor-recovery.test.ts +++ b/apps/app/tests/unit/editor-recovery.test.ts @@ -147,6 +147,30 @@ describe('restore', () => { expect(store.getState().conflict).toMatchObject({ status: 'known', revision: 5 }) }) + it('stays unsaved under staleBase when edited back to the server text (no dead end)', async () => { + seed(movedText(10), 2) + await openReady({ revision: 5 }) + await store.getState().restoreCopy() + expect(commitMove(50)).toMatchObject({ ok: true }) + expect(store.getState().documentText).toBe(store.getState().savedText) + expect(store.getState()).toMatchObject({ staleBase: true, unsaved: true }) + }) + + it('a restored copy holding bare nodes takes the core defaults-filled document', async () => { + const bare = JSON.parse(baseText()) + bare.finding_zones = [ + { + id: 'z', name: { fr: 'Z', en: 'Z' }, + categories: [{ id: 'c', kind: 'dysfunction', name: { fr: 'C', en: 'C' }, children: [{ id: 'n', name: { fr: 'N', en: 'N' } }] }], + }, + ] + seed(JSON.stringify(bare), 3) + await openReady({ revision: 3 }) + await store.getState().restoreCopy() + const node = JSON.parse(store.getState().documentText).finding_zones[0].categories[0].children[0] + expect(node).toMatchObject({ reference_ids: [], children: [], review_status: 'inherited' }) + }) + it('takes the reload path for « Annuler les modifications » under staleBase', async () => { seed(movedText(10), 2) await openReady({ revision: 5 }) diff --git a/apps/app/tests/unit/editor-store.test.ts b/apps/app/tests/unit/editor-store.test.ts index 1d285a50..fb6c98cd 100644 --- a/apps/app/tests/unit/editor-store.test.ts +++ b/apps/app/tests/unit/editor-store.test.ts @@ -334,6 +334,8 @@ describe('discard and submit', () => { sb.submitSheetReview.mockResolvedValue('review-1' as never) expect(await store.getState().submit()).toEqual({ ok: true, reviewId: 'review-1' }) expect(sb.submitSheetReview).toHaveBeenCalledWith(expect.anything(), { version_id: VERSION, expected_revision: 3 }) + // The accepted submission froze the store; a fresh session meets the conflict. + await openReady({ revision: 3 }) sb.submitSheetReview.mockRejectedValue(new SheetFailure('draft_conflict')) sb.getOfficialSheetAdmin.mockRejectedValue(new SheetFailure('network')) expect(await store.getState().submit()).toMatchObject({ kind: 'draft_conflict' }) @@ -342,6 +344,16 @@ describe('discard and submit', () => { }) }) +describe('after the server accepted the submission', () => { + it('takes no further change before the sheet reload turns the draft frozen', async () => { + await openReady({ revision: 3 }) + sb.submitSheetReview.mockResolvedValue('review-1' as never) + expect(await store.getState().submit()).toMatchObject({ ok: true }) + expect(commitMove(40)).toMatchObject({ ok: false, reason: 'blocked', kind: 'read_only' }) + expect(store.getState().unsaved).toBe(false) + }) +}) + describe('guards', () => { it('refuses a submit while the document differs from the saved text', async () => { await openReady() diff --git a/apps/app/tests/unit/editor-undo-shortcuts.test.tsx b/apps/app/tests/unit/editor-undo-shortcuts.test.tsx index 7462a7fd..73e264a6 100644 --- a/apps/app/tests/unit/editor-undo-shortcuts.test.tsx +++ b/apps/app/tests/unit/editor-undo-shortcuts.test.tsx @@ -67,13 +67,19 @@ describe('editor-wide undo', () => { dialog.remove() }) - it('is off in a read-only mode', async () => { - mountDraft({ width: 800 }) + it("is off in the narrow read-only mode, with the route's own store state", async () => { + mountDraft({ width: 1280 }) await ready() - store.getState().setCanEdit(true) act(() => void commitMove(40)) - store.getState().setCanEdit(false) + act(() => { + setWidth(800) + window.dispatchEvent(new Event('resize')) + }) + await screen.findByText(/L'édition nécessite une largeur/) + // The route keeps the store able to hold a recovery copy in `narrow`: no forced flag. + expect(store.getState().canEdit).toBe(true) ctrlZ(document.body) expect(cx()).toMatchObject({ cx: 40 }) + expect(store.getState().unsaved).toBe(true) }) })