feat(editor): repair out-of-frame annotations when attaching a drawing

This commit is contained in:
bchanot committed 2026-11-04 20:10:07 +01:00
1 parent 4ab85adeb0
commit 3776a33b79
22 files changed
+1277 -19

No files matched your search

@@ -9,7 +9,9 @@ import {
geometryField,
openEditor,
pointOf,
saveDraft,
seedDraft,
serverDocument,
selectTab,
shapeWith,
standardShape,
@@ -221,6 +223,97 @@ test.describe('editor geometry (adversarial)', () => {
await expect(width).toHaveValue('300')
})
test('attaching a drawing to an unmeasured view repairs the annotations outside its frame', async ({
page,
requests,
}) => {
const zone = {
...pointOf('out-zone', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone hors cadre'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[10, 10],
[400, 10],
[400, 400],
],
},
}
const point = pointOf(
'out-point',
'main',
{ cx: 500, cy: 400, r: 20 },
'Point hors cadre',
)
const actor = await editorActor('fr')
requests.forbid(actor.account.email, actor.account.password)
const seed = await seedDraft(actor, {
drawing: null,
shape: (document) => {
standardShape(document)
const views = document.views as { id: string }[]
document.views = views.filter((view) => view.id === 'main')
document.annotations = [point, zone]
},
})
await openEditor(page, dict, actor, seed.sheetId)
await selectTab(page, dict, 'views')
await page.getByTestId('view-main-file').setInputFiles({
name: 'petit.svg',
mimeType: 'image/svg+xml',
buffer: Buffer.from(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">' +
'<rect x="2" y="2" width="96" height="96" fill="#eee"/></svg>',
),
})
const dialog = page.getByRole('dialog', {
name: dict['editor.views.repair.title'],
})
await expect(dialog).toBeVisible()
const row = dialog.getByTestId('repair-out-point')
await expect(
row.getByLabel(dict['editor.annotations.geometry.cx']),
).toHaveValue('85')
await expectAccessible(page, 'the repair dialog')
// A value the core refuses: nothing applied, the typed value kept.
const cx = row.getByLabel(dict['editor.annotations.geometry.cx'])
await cx.fill('900')
await cx.press('Enter')
await dialog
.getByRole('button', { name: dict['editor.views.repair.apply'] })
.click()
await expect(
dialog.getByText(dict['editor.views.repair.refused']),
).toBeVisible()
await expect(cx).toHaveValue('900')
await cx.fill('60')
await cx.press('Enter')
await dialog
.getByRole('button', { name: dict['editor.views.repair.apply'] })
.click()
await expect(dialog).toBeHidden()
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
await saveDraft(page, dict, seed.revision + 1)
const saved = await serverDocument<{
views: { id: string; svg_asset_id: string | null }[]
annotations: { id: string; geometry: Record<string, unknown> }[]
}>(seed.draftId)
expect(saved.views[0].svg_asset_id).not.toBeNull()
const byId = Object.fromEntries(saved.annotations.map((a) => [a.id, a]))
expect(byId['out-point'].geometry).toMatchObject({ type: 'circle', cx: 60 })
expect(byId['out-zone'].geometry).toEqual({
type: 'polygon',
points: [
[10, 10],
[100, 10],
[100, 100],
],
})
})
test('an unmeasured view: drawing tools and add buttons disabled, the hint shown', async ({
page,
requests,