fix(editor): free paths never reshaped on attach, category zone chosen explicitly
This commit is contained in:
1 parent
f1175bb3a1
commit
a69eba569b
13 files changed
+333
-117
No files matched your search
@@ -16,11 +16,7 @@ import type {
|
||||
import ViewsTab from '@/components/editor/tabs/ViewsTab'
|
||||
import { cleanSvg } from '@/editor/core/cleaning'
|
||||
import { attachToView } from '@/editor/drawingUpload'
|
||||
import {
|
||||
applyRepair,
|
||||
polygonReplacement,
|
||||
proposeGeometry,
|
||||
} from '@/editor/repair'
|
||||
import { applyRepair, proposeGeometry } from '@/editor/repair'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { getDict } from '@/i18n'
|
||||
import { emptyText, insert, point, svgBytes } from '../helpers/editorFixtures'
|
||||
@@ -125,13 +121,9 @@ describe('proposals (UI arithmetic in the new frame)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('leaves a path to the conversion, which offers a triangle in the frame', () => {
|
||||
it('returns a path as it is: its points are never reshaped', () => {
|
||||
const path: Geometry = { type: 'path', d: 'M 1 1 L 5 5 Z' }
|
||||
expect(proposeGeometry(frame, path)).toBe(path)
|
||||
expect(polygonReplacement(frame)).toMatchObject({
|
||||
type: 'polygon',
|
||||
points: expect.arrayContaining([expect.any(Array)]),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -222,6 +214,30 @@ describe('applyRepair', () => {
|
||||
expect(store.getState().undo).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('never rewrites a free path: its d is kept and the batch is refused', async () => {
|
||||
const pathValue = {
|
||||
...(point('anno-p', 0, 0, 1).value as Annotation),
|
||||
kind: 'zone' as const,
|
||||
geometry: { type: 'path' as const, d: COMPLEX_PATH },
|
||||
} as Annotation
|
||||
await openReady({ text: unmeasuredText([pathValue]) })
|
||||
await holdNewDrawing()
|
||||
const before = store.getState().documentText
|
||||
const offer = offerOf()
|
||||
expect(offer.refusal.annotationIds).toContain('anno-p')
|
||||
const geometries = {
|
||||
...proposals(offer),
|
||||
'anno-p': proposeGeometry(
|
||||
offer.frames['view-main'],
|
||||
annotation('anno-p').geometry as Geometry,
|
||||
),
|
||||
}
|
||||
expect(geometries['anno-p']).toEqual({ type: 'path', d: COMPLEX_PATH })
|
||||
expect(applyRepair(offer, geometries, context)).toMatchObject({ ok: false })
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(store.getState().undo).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('is blocked while a recovery offer is pending', async () => {
|
||||
await openReady({ text: unmeasuredText() })
|
||||
await holdNewDrawing()
|
||||
@@ -274,6 +290,10 @@ function serverGets(text: string) {
|
||||
const SVG =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect width="4" height="4"/></svg>'
|
||||
|
||||
const COMPLEX_PATH =
|
||||
'M 300 300 l 40 0 C 350 320 380 360 400 400 q 20 -30 -40 -50 ' +
|
||||
'A 30 20 0 0 1 320 330 H 310 V 305 Z'
|
||||
|
||||
async function pickAndOpenDialog(text = unmeasuredText()) {
|
||||
await openReady({ text })
|
||||
serverGets(SVG)
|
||||
@@ -363,15 +383,17 @@ describe('the repair dialog', () => {
|
||||
expect(screen.queryByText(/Déplacez d'abord/)).toBeNull()
|
||||
})
|
||||
|
||||
it('blocks a path until it is replaced by a polygon, inside the same form', async () => {
|
||||
it('blocks a free path with its reason, no conversion, and cancel keeps everything', async () => {
|
||||
const pathValue = {
|
||||
...(point('anno-p', 0, 0, 1).value as Annotation),
|
||||
kind: 'zone' as const,
|
||||
geometry: { type: 'path' as const, d: 'M 300 300 L 400 300 L 350 400 Z' },
|
||||
geometry: { type: 'path' as const, d: COMPLEX_PATH },
|
||||
} as Annotation
|
||||
const { user, dialog } = await pickAndOpenDialog(
|
||||
unmeasuredText([pathValue]),
|
||||
)
|
||||
const before = store.getState().documentText
|
||||
const undoLength = store.getState().undo.length
|
||||
const apply = within(dialog).getByRole('button', {
|
||||
name: t('editor.views.repair.apply'),
|
||||
})
|
||||
@@ -380,15 +402,22 @@ describe('the repair dialog', () => {
|
||||
expect(
|
||||
within(row).getByText(t('editor.views.repair.path_blocked')),
|
||||
).toBeTruthy()
|
||||
expect(within(row).queryByRole('button')).toBeNull()
|
||||
expect(within(dialog).queryByText(/polygone/i)).toBeNull()
|
||||
await user.click(apply)
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
await user.click(
|
||||
within(row).getByRole('button', {
|
||||
name: t('editor.annotations.replace_polygon'),
|
||||
within(dialog).getByRole('button', {
|
||||
name: t('editor.views.repair.cancel'),
|
||||
}),
|
||||
)
|
||||
expect(apply).toBeEnabled()
|
||||
await user.click(apply)
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
expect(annotation('anno-p').geometry).toMatchObject({ type: 'polygon' })
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(store.getState().undo).toHaveLength(undoLength)
|
||||
expect(annotation('anno-p').geometry).toEqual({
|
||||
type: 'path',
|
||||
d: COMPLEX_PATH,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user