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 ceb49f6c..90145b14 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
@@ -177,3 +177,80 @@ Status column: `ratified` = REVUE.md wording; `plan wording` = quoted in the pla
| `editor.vertebra.new` | Nouvelle région vertébrale | New vertebral region | Region creation form | proposal |
| `editor.vertebra.add` | Ajouter la région | Add the region | Region creation button | proposal |
| `editor.vertebra.required` | Renseignez le code et les noms français et anglais. | Fill in the code and the French and English names. | Region creation, missing field | proposal |
+
+## Lot G (Vues et illustrations, upload, cleaning dialog)
+
+Status: `plan wording` = quoted in the plan or the brief (EN proposed unless noted); `proposal` = new.
+
+| Key | FR | EN | Where | Status |
+|---|---|---|---|---|
+| `editor.views.main_title` | Vue principale | Main view | Views tab, main view card | proposal |
+| `editor.views.details_title` | Vues de détail | Detail views | Views tab, section title | proposal |
+| `editor.views.empty` | Aucune vue de détail pour l'instant. | No detail view yet. | Views tab, empty list | proposal |
+| `editor.views.name_fr` | Nom de la vue (FR) | View name (FR) | View field | proposal |
+| `editor.views.name_en` | Nom de la vue (EN) | View name (EN) | View field | proposal |
+| `editor.views.parent` | Vue parente | Parent view | Detail view field | proposal |
+| `editor.views.drawing` | Illustration | Drawing | View drawing section title | plan wording |
+| `editor.views.drawing.none` | Aucune illustration | No drawing | Drawing state | proposal |
+| `editor.views.drawing.ok` | Illustration valide | Drawing valid | Drawing state | plan wording (state ok) |
+| `editor.views.drawing.missing` | Illustration introuvable | Drawing not found | Drawing state | plan wording (state missing) |
+| `editor.views.drawing.rejected` | Illustration refusée | Drawing rejected | Drawing state | plan wording (state rejected) |
+| `editor.views.drawing.detail` | Détail : {detail} | Detail: {detail} | Drawing state, the core's detail | proposal |
+| `editor.views.drawing.inherited` | Utilise l'illustration de la vue parente. | Uses the parent view's drawing. | Detail view without own drawing | proposal |
+| `editor.views.drawing.hint` | Utilisez « Choisir une illustration » pour ajouter ou remplacer le dessin de cette vue. | Use « Choose a drawing » to add or replace this view's drawing. | Hint when the drawing is not usable (edit mode) | proposal |
+| `editor.views.drawing.unmeasured` | Cette vue n'est pas mesurable : ajoutez ou corrigez son illustration avant de placer ou de déplacer des éléments. | This view cannot be measured: add or fix its drawing before placing or moving elements. | Hint on an unmeasured view | proposal (adapted from the plan's Annotations hint) |
+| `editor.views.drawing.choose` | Choisir une illustration | Choose a drawing | Button (brief wording) | brief wording FR; EN proposal |
+| `editor.views.drawing.file` | Fichier d'illustration (SVG) | Drawing file (SVG) | File input accessible name | proposal |
+| `editor.views.drawing.use_parent` | Utiliser l'illustration de la vue parente | Use the parent view's drawing | Detail view, removes its own drawing (frame change) | proposal |
+| `editor.views.crop.title` | Recadrage | Crop | Detail view crop section | proposal |
+| `editor.views.crop.toggle` | Modifier le recadrage | Edit the crop | Button, opens the crop fields and the parent canvas | proposal |
+| `editor.views.crop.min_x` | Recadrage : x minimum | Crop: minimum x | Crop field (view_box.min_x) | proposal |
+| `editor.views.crop.min_y` | Recadrage : y minimum | Crop: minimum y | Crop field (view_box.min_y) | proposal |
+| `editor.views.crop.width` | Recadrage : largeur | Crop: width | Crop field (view_box.width) | proposal |
+| `editor.views.crop.height` | Recadrage : hauteur | Crop: height | Crop field (view_box.height) | proposal |
+| `editor.views.crop.hint` | Rectangle en unités du dessin parent. Quatre valeurs, ou aucune pour ne pas recadrer. Elles s'appliquent ensemble. | Rectangle in the parent drawing's units. Four values, or none for no crop. They apply together. | Crop group hint | proposal |
+| `editor.views.crop.incomplete` | Indiquez les quatre valeurs du recadrage, ou aucune. | Fill in all four crop values, or none. | Crop group, a value missing | proposal |
+| `editor.views.crop.number` | Les valeurs du recadrage sont des nombres. | The crop values are numbers. | Crop group, not a number | proposal |
+| `editor.views.crop.not_applied` | Non appliqué | Not applied | Crop group refused (board wording « non appliqué ») | ratified FR (plan); EN proposal |
+| `editor.views.crop.revert` | Revenir aux valeurs enregistrées | Revert to the saved values | Crop group refused | plan wording FR; EN proposal |
+| `editor.views.crop.canvas` | Vue parente avec le rectangle de recadrage | Parent view with the crop rectangle | Crop canvas accessible name | proposal |
+| `editor.views.crop.canvas_failed` | La vue parente ne peut pas être affichée. | The parent view cannot be displayed. | Crop canvas failure | proposal |
+| `editor.views.new` | Nouvelle vue de détail | New detail view | Creation form | proposal |
+| `editor.views.new_hint` | Saisissez le recadrage pour une vue recadrée ; laissez-le vide pour une vue qui aura sa propre illustration (à choisir une fois la vue ajoutée). | Fill in the crop for a cropped view; leave it empty for a view that will have its own drawing (chosen once the view is added). | Creation form hint | proposal |
+| `editor.views.add` | Ajouter la vue | Add the view | Creation button | proposal |
+| `editor.views.required` | Renseignez les noms français et anglais de la vue. | Fill in the French and English names of the view. | Creation, missing field | proposal |
+| `editor.views.frame.newly_invalid` | Ce changement de cadre mettrait en erreur la géométrie de : {names}. Déplacez d'abord ces éléments (onglet Annotations). | This frame change would put the geometry of these elements in error: {names}. Move them first (Annotations tab). | Refused frame change (crop, drawing, parent) | proposal |
+| `editor.views.frame.view_unmeasured` | Ce changement rendrait non mesurable une vue qui porte des annotations : {names}. | This change would make a view that holds annotations unmeasurable: {names}. | Refused frame change | proposal |
+| `editor.views.frame.kept` | L'illustration reste téléversée ; la vue garde son illustration précédente. | The drawing stays uploaded; the view keeps its previous drawing. | Refused attach after an upload | proposal |
+| `editor.upload.working` | Vérification et envoi de l'illustration… | Checking and sending the drawing… | Upload in progress | proposal |
+| `editor.upload.done` | L'illustration est ajoutée à la vue. | The drawing is added to the view. | Upload done | proposal |
+| `editor.upload.err.too_large` | Ce fichier dépasse 2 Mio. | This file is larger than 2 MiB. | Upload refused | plan code too_large |
+| `editor.upload.err.svg_active_content` | Ce fichier contient du contenu actif ou externe (script, lien, image distante) : il est refusé. | This file contains active or external content (script, link, remote image): it is refused. | Upload refused | plan code svg_active_content |
+| `editor.upload.err.svg_rejected` | Ce fichier n'est pas un dessin SVG utilisable ({reason}). | This file is not a usable SVG drawing ({reason}). | Upload refused, with the reader's reason | plan code svg_rejected |
+| `editor.upload.err.size_mismatch` | La taille du fichier envoyé ne correspond pas à celle annoncée. Réessayez. | The size of the file sent does not match the announced size. Try again. | Confirm refused | plan code size_mismatch |
+| `editor.upload.err.upload_missing` | Le fichier n'est pas arrivé sur le serveur. Réessayez. | The file did not reach the server. Try again. | Confirm refused | plan code upload_missing |
+| `editor.upload.err.upload.pending_other` | Ce dessin est en cours d'envoi par un autre compte. Réessayez dans quelques instants. | Another account is sending this drawing. Try again in a moment. | Policy refusal then confirm without object | plan code upload.pending_other |
+| `editor.upload.err.object_conflict` | Un fichier différent existe déjà sous cette empreinte : l'illustration est refusée. | A different file already exists under this hash: the drawing is refused. | Downloaded object does not match its hash | plan code object_conflict |
+| `editor.upload.err.caps` | Trop d'illustrations dans cette session d'édition (16 au plus). Enregistrez, puis rechargez le brouillon. | Too many drawings in this editing session (16 at most). Save, then reload the draft. | Core drawing cap | plan code caps |
+| `editor.upload.err.core` | Le contrôle du document a refusé cette illustration. | The document check refused this drawing. | Core refusal | proposal |
+| `editor.upload.reason.malformed` | fichier mal formé | malformed file | Reader reason | proposal |
+| `editor.upload.reason.doctype` | déclaration DOCTYPE interdite | DOCTYPE declaration not allowed | Reader reason | proposal |
+| `editor.upload.reason.not_svg` | ce n'est pas un SVG | not an SVG | Reader reason | proposal |
+| `editor.upload.reason.too_many_elements` | trop d'éléments | too many elements | Reader reason | proposal |
+| `editor.upload.reason.too_deep` | imbrication trop profonde | nesting too deep | Reader reason | proposal |
+| `editor.upload.reason.too_many_uses` | trop de réutilisations (use) | too many reuses (use) | Reader reason | proposal |
+| `editor.upload.reason.too_complex` | dessin trop complexe | drawing too complex | Reader reason | proposal |
+| `editor.upload.reason.reference_cycle` | références circulaires | circular references | Reader reason | proposal |
+| `editor.upload.reason.dangling_reference` | référence vers un élément absent | reference to a missing element | Reader reason | proposal |
+| `editor.upload.reason.reserved_id` | identifiant réservé | reserved identifier | Reader reason | proposal |
+| `editor.upload.reason.root_visibility` | élément racine masqué | hidden root element | Reader reason | proposal |
+| `editor.upload.reason.other` | motif non reconnu | unrecognised reason | Reader reason, any other | proposal |
+| `editor.cleaning.title` | Nettoyer cette illustration ? | Clean this drawing? | Cleaning dialog title | proposal |
+| `editor.cleaning.body` | Ce fichier contient des éléments qui ne sont pas conservés. L'aperçu montre le dessin tel qu'il sera enregistré. | This file contains elements that are not kept. The preview shows the drawing as it will be saved. | Cleaning dialog | proposal |
+| `editor.cleaning.preview` | Aperçu du dessin nettoyé | Preview of the cleaned drawing | Cleaning dialog preview accessible name | proposal |
+| `editor.cleaning.preview_failed` | L'aperçu du dessin nettoyé ne peut pas être composé. | The preview of the cleaned drawing cannot be composed. | Cleaning dialog | proposal |
+| `editor.cleaning.removed` | Éléments retirés : | Removed elements: | Cleaning dialog list | proposal |
+| `editor.cleaning.active` | Contenu actif ou externe retiré : | Active or external content removed: | Cleaning dialog list | proposal |
+| `editor.cleaning.style` | L'élément ',
+ )
+ serverGets(dirty)
+ await pick(dirty)
+ const dialog = await screen.findByRole('dialog')
+ expect(sb.registerSheetAsset).not.toHaveBeenCalled()
+ expect(
+ within(dialog).getByText(/L'élément ',
+ )
+ serverGets(dirty)
+ const user = await pick(dirty)
+ const dialog = await screen.findByRole('dialog')
+ await user.click(within(dialog).getByRole('button', { name: 'Annuler' }))
+ expect(sb.registerSheetAsset).not.toHaveBeenCalled()
+ expect(mainAsset()).toBe(ASSET)
+ })
+
+ it('a rejected file shows its reason and nothing else happens', async () => {
+ await pick(
+ '',
+ )
+ expect(await screen.findByText(/contenu actif ou externe/)).toBeTruthy()
+ await pick('pas un svg')
+ expect(
+ await screen.findByText(/n'est pas un dessin SVG utilisable/),
+ ).toBeTruthy()
+ expect(sb.registerSheetAsset).not.toHaveBeenCalled()
+ expect(screen.queryByRole('dialog')).toBeNull()
+ })
+
+ it('a file over 2 MiB is refused before it is read', async () => {
+ const user = userEvent.setup()
+ const big = new File([new Uint8Array(MAX_DRAWING_BYTES + 1)], 'big.svg', {
+ type: 'image/svg+xml',
+ })
+ await user.upload(
+ screen.getByTestId('view-view-main-file') as HTMLInputElement,
+ big,
+ )
+ expect(await screen.findByText('Ce fichier dépasse 2 Mio.')).toBeTruthy()
+ expect(sb.registerSheetAsset).not.toHaveBeenCalled()
+ })
+
+ it('an object already present is confirmed without a second upload', async () => {
+ serverGets(svg('0 0 200 100'))
+ sb.uploadSheetDrawing.mockResolvedValue('present')
+ await pick(svg('0 0 200 100'))
+ await waitFor(() => expect(mainAsset()).toBe(NEW_ASSET))
+ expect(sb.confirmSheetAssetUpload).toHaveBeenCalledTimes(1)
+ })
+
+ it('a confirmed row is neither uploaded nor confirmed again', async () => {
+ serverGets(svg('0 0 200 100'), '2026-11-04T10:00:00Z')
+ await pick(svg('0 0 200 100'))
+ await waitFor(() => expect(mainAsset()).toBe(NEW_ASSET))
+ expect(sb.uploadSheetDrawing).not.toHaveBeenCalled()
+ expect(sb.confirmSheetAssetUpload).not.toHaveBeenCalled()
+ })
+
+ it('a policy refusal then a confirm that finds the object goes on', async () => {
+ serverGets(svg('0 0 200 100'))
+ sb.uploadSheetDrawing.mockRejectedValue(
+ new SheetFailure('upload.pending_other'),
+ )
+ await pick(svg('0 0 200 100'))
+ await waitFor(() => expect(mainAsset()).toBe(NEW_ASSET))
+ expect(sb.confirmSheetAssetUpload).toHaveBeenCalledTimes(1)
+ })
+
+ it('a policy refusal then upload_missing is upload.pending_other, view unchanged', async () => {
+ serverGets(svg('0 0 200 100'))
+ sb.uploadSheetDrawing.mockRejectedValue(
+ new SheetFailure('upload.pending_other'),
+ )
+ sb.confirmSheetAssetUpload.mockRejectedValue(
+ new SheetFailure('upload_missing'),
+ )
+ await pick(svg('0 0 200 100'))
+ expect(
+ await screen.findByText(/en cours d'envoi par un autre compte/),
+ ).toBeTruthy()
+ expect(mainAsset()).toBe(ASSET)
+ expect(store.getState().drawings.map((d) => d.asset_id)).not.toContain(
+ NEW_ASSET,
+ )
+ })
+
+ it('server kinds are phrased, size_mismatch with its own wording', async () => {
+ serverGets(svg('0 0 200 100'))
+ sb.confirmSheetAssetUpload.mockRejectedValue(
+ new SheetFailure('size_mismatch'),
+ )
+ await pick(svg('0 0 200 100'))
+ expect(
+ await screen.findByText(/ne correspond pas à celle annoncée/),
+ ).toBeTruthy()
+ expect(mainAsset()).toBe(ASSET)
+ })
+
+ it('a downloaded object that does not match its hash is an object conflict', async () => {
+ serverGets(svg('0 0 200 100'))
+ sb.downloadSheetDrawing.mockResolvedValue(new TextEncoder().encode('autre'))
+ await pick(svg('0 0 200 100'))
+ expect(
+ await screen.findByText(/Un fichier différent existe déjà/),
+ ).toBeTruthy()
+ expect(mainAsset()).toBe(ASSET)
+ })
+
+ it('a refused frame change leaves the drawing uploaded and held, the view unchanged', async () => {
+ serverGets(svg('0 0 20 20'))
+ await pick(svg('0 0 20 20'))
+ expect(await screen.findByText(/géométrie de : N\./)).toBeTruthy()
+ expect(screen.getByText(/L'illustration reste téléversée/)).toBeTruthy()
+ expect(mainAsset()).toBe(ASSET)
+ expect(store.getState().drawings.map((d) => d.asset_id)).toContain(
+ NEW_ASSET,
+ )
+ })
+})
diff --git a/apps/app/tests/unit/editor-tabs-views.test.tsx b/apps/app/tests/unit/editor-tabs-views.test.tsx
new file mode 100644
index 00000000..005f730e
--- /dev/null
+++ b/apps/app/tests/unit/editor-tabs-views.test.tsx
@@ -0,0 +1,332 @@
+/** Lot G: Vues et illustrations (states, detail views, crop group under the frame check). */
+import { createHash } from 'node:crypto'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, render, screen, within } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import type {
+ AnatomicalSheetDocument,
+ NewElement,
+} from '@faunosteo/core-wasm/types'
+import ViewsTab from '@/components/editor/tabs/ViewsTab'
+import { useLocaleStore } from '@/state/localeStore'
+import { ASSET, emptyText, insert, point } from '../helpers/editorFixtures'
+import {
+ baseText,
+ openReady,
+ resetStore,
+ sb,
+ store,
+ versionAnswer,
+} from '../helpers/editorHarness'
+
+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(),
+}))
+
+const props = { readOnly: false, onSelectTab: vi.fn(), reloadSheet: vi.fn() }
+const doc = (): AnatomicalSheetDocument =>
+ JSON.parse(store.getState().documentText)
+const detail = (
+ viewBox: object | null = { min_x: 0, min_y: 0, width: 100, height: 100 },
+) =>
+ ({
+ kind: 'view',
+ value: {
+ kind: 'detail',
+ id: 'view-d',
+ name: { fr: 'Détail', en: 'Detail' },
+ svg_asset_id: null,
+ view_box: viewBox,
+ parent_view_id: 'view-main',
+ },
+ }) as NewElement
+
+beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
+afterEach(() => {
+ cleanup()
+ resetStore()
+})
+
+async function openCrop(text: string) {
+ await openReady({ text })
+ const user = userEvent.setup()
+ render()
+ await user.click(
+ screen.getByRole('button', { name: 'Modifier le recadrage' }),
+ )
+ return user
+}
+
+const CROP_IDS: Record = {
+ 'x minimum': 'min_x',
+ 'y minimum': 'min_y',
+ largeur: 'width',
+ hauteur: 'height',
+}
+const cropField = (name: string) =>
+ document.getElementById(
+ `view-view-d-crop-${CROP_IDS[name]}`,
+ ) as HTMLInputElement
+
+describe('Vues et illustrations: drawing states', () => {
+ it('a valid main drawing shows its state and no hint', async () => {
+ await openReady()
+ render()
+ expect(screen.getByText('Illustration valide')).toBeTruthy()
+ expect(
+ screen.queryByText(/Utilisez « Choisir une illustration »/),
+ ).toBeNull()
+ })
+
+ it('a main view without drawing shows the hint pointing at the button', async () => {
+ await openReady({ text: emptyText() })
+ render()
+ expect(screen.getByText('Aucune illustration')).toBeTruthy()
+ expect(
+ screen.getByText(/Utilisez « Choisir une illustration »/),
+ ).toBeTruthy()
+ expect(screen.getByText(/n'est pas mesurable/)).toBeTruthy()
+ expect(
+ screen.getByRole('button', { name: 'Choisir une illustration' }),
+ ).toBeTruthy()
+ })
+
+ it('a drawing the handle lacks reads as not found', async () => {
+ store.getState().close()
+ sb.getSheetVersion.mockResolvedValue(
+ versionAnswer(baseText(), 3, false) as never,
+ )
+ store.getState().open('ver-1', 'user-1', { canEdit: true })
+ await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
+ render()
+ expect(screen.getByText(/Illustration introuvable/)).toBeTruthy()
+ expect(
+ screen.getByText(/Utilisez « Choisir une illustration »/),
+ ).toBeTruthy()
+ })
+
+ it('a rejected drawing shows the core detail', async () => {
+ const bytes = new TextEncoder().encode(
+ '',
+ )
+ const sha256 = createHash('sha256').update(bytes).digest('hex')
+ store.getState().close()
+ sb.getSheetVersion.mockResolvedValue({
+ ...versionAnswer(baseText(), 3, false),
+ drawings: [{ asset_id: ASSET, sha256 }],
+ } as never)
+ sb.downloadSheetDrawing.mockResolvedValue(bytes)
+ store.getState().open('ver-1', 'user-1', { canEdit: true })
+ await vi.waitFor(() => expect(store.getState().status).toBe('ready'))
+ render()
+ expect(screen.getByText(/Illustration refusée/)).toBeTruthy()
+ expect(screen.getByText(/Détail : not_canonical/)).toBeTruthy()
+ })
+
+ it('read-only shows states as text and no action', async () => {
+ await openReady({ text: insert(baseText(), detail()) })
+ render()
+ expect(screen.getByText('Illustration valide')).toBeTruthy()
+ expect(screen.queryByRole('button')).toBeNull()
+ expect(screen.queryByRole('textbox')).toBeNull()
+ })
+})
+
+describe('Vues et illustrations: detail views', () => {
+ it('adds a detail view with names and a crop, in one insert', async () => {
+ await openReady()
+ const user = userEvent.setup()
+ render()
+ await user.click(screen.getByRole('button', { name: 'Ajouter la vue' }))
+ expect(screen.getByRole('alert')).toHaveTextContent('Renseignez les noms')
+ await user.type(document.getElementById('view-new-fr')!, 'Tête')
+ await user.type(document.getElementById('view-new-en')!, 'Head')
+ await user.type(document.getElementById('view-new-crop-min_x')!, '10')
+ await user.click(screen.getByRole('button', { name: 'Ajouter la vue' }))
+ expect(screen.getByRole('alert')).toHaveTextContent('quatre valeurs')
+ expect(doc().views).toHaveLength(1)
+ for (const [key, value] of [
+ ['min_y', '20'],
+ ['width', '30'],
+ ['height', '40'],
+ ]) {
+ await user.type(document.getElementById(`view-new-crop-${key}`)!, value)
+ }
+ await user.click(screen.getByRole('button', { name: 'Ajouter la vue' }))
+ expect(doc().views).toHaveLength(2)
+ expect(doc().views[1]).toMatchObject({
+ kind: 'detail',
+ name: { fr: 'Tête', en: 'Head' },
+ parent_view_id: 'view-main',
+ svg_asset_id: null,
+ view_box: { min_x: 10, min_y: 20, width: 30, height: 40 },
+ })
+ expect(doc().views[1].id).toMatch(/^view-[a-z2-7]{10}$/)
+ })
+
+ it('renames on blur and refuses a blank name locally', async () => {
+ await openReady({ text: insert(baseText(), detail()) })
+ const user = userEvent.setup()
+ render()
+ const name = document.getElementById('view-view-d-name-en')!
+ await user.clear(name)
+ await user.type(name, 'Lower leg')
+ await user.tab()
+ expect(doc().views[1].name).toEqual({ fr: 'Détail', en: 'Lower leg' })
+ await user.clear(document.getElementById('view-view-d-name-fr')!)
+ await user.tab()
+ expect(screen.getByText('Ce champ est obligatoire.')).toBeTruthy()
+ expect(doc().views[1].name.fr).toBe('Détail')
+ })
+
+ it('deleting a view that holds an annotation lists the dependents', async () => {
+ const text = insert(
+ insert(baseText(), detail()),
+ point('anno-d', 50, 50, 5, 'view-d'),
+ )
+ await openReady({ text })
+ const user = userEvent.setup()
+ render()
+ await user.click(screen.getByRole('button', { name: 'Supprimer' }))
+ const dialog = await screen.findByRole('dialog')
+ expect(within(dialog).getByText(/ne peut pas être supprimé/)).toBeTruthy()
+ expect(doc().views).toHaveLength(2)
+ })
+})
+
+describe('Vues et illustrations: crop group under the frame check', () => {
+ it('refuses a crop that pushes a point out and keeps the typed values', async () => {
+ const text = insert(
+ insert(baseText(), detail()),
+ point('anno-d', 50, 50, 5, 'view-d'),
+ )
+ const user = await openCrop(text)
+ const before = store.getState().documentText
+ await user.clear(cropField('x minimum'))
+ await user.type(cropField('x minimum'), '60{Enter}')
+ const alert = screen.getByRole('alert')
+ expect(alert).toHaveTextContent('Non appliqué')
+ expect(alert).toHaveTextContent(/géométrie de : N/)
+ expect(store.getState().documentText).toBe(before)
+ expect(store.getState().undo).toHaveLength(0)
+ expect(cropField('x minimum')).toHaveValue('60')
+ await user.click(
+ screen.getByRole('button', { name: 'Revenir aux valeurs enregistrées' }),
+ )
+ expect(cropField('x minimum')).toHaveValue('0')
+ expect(screen.queryByText('Non appliqué')).toBeNull()
+ })
+
+ it('applies the four fields as one group when they fit', async () => {
+ const text = insert(
+ insert(baseText(), detail()),
+ point('anno-d', 50, 50, 5, 'view-d'),
+ )
+ const user = await openCrop(text)
+ await user.clear(cropField('x minimum'))
+ await user.type(cropField('x minimum'), '20')
+ await user.clear(cropField('largeur'))
+ await user.type(cropField('largeur'), '60{Enter}')
+ expect(doc().views[1]).toMatchObject({
+ view_box: { min_x: 20, width: 60, height: 100 },
+ })
+ expect(screen.queryByText('Non appliqué')).toBeNull()
+ })
+
+ it('accepts a crop change when only an already invalid point is affected', async () => {
+ const text = insert(
+ insert(baseText(), detail()),
+ point('anno-bad', 150, 50, 5, 'view-d'),
+ )
+ const user = await openCrop(text)
+ expect(
+ store
+ .getState()
+ .previewState?.report.issues.some((i) => i.path.endsWith('.geometry')),
+ ).toBe(true)
+ await user.clear(cropField('largeur'))
+ await user.type(cropField('largeur'), '90{Enter}')
+ expect(doc().views[1]).toMatchObject({ view_box: { width: 90 } })
+ expect(screen.queryByText('Non appliqué')).toBeNull()
+ })
+
+ it('refuses a crop span the core cannot measure while the view holds annotations', async () => {
+ const text = insert(
+ insert(baseText(), detail()),
+ point('anno-d', 50, 50, 5, 'view-d'),
+ )
+ const user = await openCrop(text)
+ await user.clear(cropField('largeur'))
+ await user.type(cropField('largeur'), '0.5')
+ await user.clear(cropField('hauteur'))
+ await user.type(cropField('hauteur'), '0.5{Enter}')
+ expect(screen.getByRole('alert')).toHaveTextContent('Non appliqué')
+ expect(screen.getByRole('alert')).toHaveTextContent(
+ /non mesurable|géométrie de/,
+ )
+ expect(doc().views[1]).toMatchObject({ view_box: { width: 100 } })
+ })
+
+ it('a partial group is not applied and says so; an unchanged number commits nothing', async () => {
+ const user = await openCrop(insert(baseText(), detail()))
+ await user.clear(cropField('hauteur'))
+ await user.type(cropField('hauteur'), '{Enter}')
+ expect(screen.getByRole('alert')).toHaveTextContent(
+ 'Indiquez les quatre valeurs',
+ )
+ await user.click(
+ screen.getByRole('button', { name: 'Revenir aux valeurs enregistrées' }),
+ )
+ await user.clear(cropField('largeur'))
+ await user.type(cropField('largeur'), '100.0{Enter}')
+ expect(store.getState().undo).toHaveLength(0)
+ expect(screen.queryByText('Non appliqué')).toBeNull()
+ })
+
+ it('draws the crop rectangle over the parent canvas, numbers only', async () => {
+ await openCrop(
+ insert(
+ baseText(),
+ detail({ min_x: 10, min_y: 20, width: 30, height: 40 }),
+ ),
+ )
+ const rect = screen.getByTestId('crop-overlay').querySelector('rect')!
+ expect(rect.getAttribute('x')).toBe('10')
+ expect(rect.getAttribute('height')).toBe('40')
+ expect(
+ screen.getByTestId('crop-canvas-drawing').querySelector('svg'),
+ ).not.toBeNull()
+ })
+
+ it('a parent change commits through the frame check', async () => {
+ const text = insert(insert(baseText(), detail()), detail2())
+ await openReady({ text })
+ const user = userEvent.setup()
+ render()
+ await user.selectOptions(
+ document.getElementById('view-view-d-parent')!,
+ 'view-e',
+ )
+ expect(doc().views[1]).toMatchObject({ parent_view_id: 'view-e' })
+ })
+})
+
+function detail2(): NewElement {
+ return {
+ kind: 'view',
+ value: {
+ kind: 'detail',
+ id: 'view-e',
+ name: { fr: 'Autre', en: 'Other' },
+ svg_asset_id: null,
+ view_box: { min_x: 0, min_y: 0, width: 50, height: 50 },
+ parent_view_id: 'view-main',
+ },
+ }
+}