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
@@ -253,6 +253,9 @@ describe('Constats tab', () => {
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
expect(screen.getByRole('alert')).toBeInTheDocument()
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-a')
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
expect(screen.getByRole('alert')).toBeInTheDocument()
|
||||
await user.selectOptions(
|
||||
screen.getByLabelText('Type de catégorie'),
|
||||
'anamnesis',
|
||||
@@ -277,19 +280,7 @@ describe('Constats tab', () => {
|
||||
expect(doc().finding_zones[0].categories[1].children).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('names the zone a category lands in and appends it at zone level, a node selected', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
items()[0].focus()
|
||||
await user.keyboard('{ArrowDown}{ArrowRight}{ArrowRight}')
|
||||
expect(items()[2]).toHaveAttribute('aria-selected', 'true')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
expect(
|
||||
screen.getByText('Nouvelle catégorie dans la zone « Zone A »'),
|
||||
).toBeInTheDocument()
|
||||
async function fillCategory(user: ReturnType<typeof userEvent.setup>) {
|
||||
await user.type(
|
||||
screen.getByLabelText('Nom (FR)', { selector: '#finding-new-name-fr' }),
|
||||
'Nouv',
|
||||
@@ -302,10 +293,86 @@ describe('Constats tab', () => {
|
||||
screen.getByLabelText('Type de catégorie'),
|
||||
'anamnesis',
|
||||
)
|
||||
}
|
||||
|
||||
it('lands in the zone chosen in the form, not the zone of the selected node (C46)', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
items()[0].focus()
|
||||
await user.keyboard('{ArrowDown}{ArrowRight}{ArrowRight}')
|
||||
expect(items()[2]).toHaveAttribute('aria-selected', 'true')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
expect(screen.getByLabelText('Zone')).toHaveValue('')
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-b')
|
||||
expect(
|
||||
screen.getByText('Nouvelle catégorie dans la zone « Zone B »'),
|
||||
).toBeInTheDocument()
|
||||
await fillCategory(user)
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
const categories = doc().finding_zones[0].categories
|
||||
expect(categories.map((c) => c.id)).toEqual(['fcat-a', expect.any(String)])
|
||||
expect(categories[0].children[0].children).toHaveLength(1)
|
||||
expect(doc().finding_zones[1].categories).toHaveLength(1)
|
||||
expect(doc().finding_zones[1].categories[0].kind).toBe('anamnesis')
|
||||
expect(doc().finding_zones[0].categories.map((c) => c.id)).toEqual([
|
||||
'fcat-a',
|
||||
])
|
||||
})
|
||||
|
||||
it('appends the category after the existing ones of the chosen zone', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-a')
|
||||
await fillCategory(user)
|
||||
await user.click(screen.getByRole('button', { name: 'Créer' }))
|
||||
const ids = doc().finding_zones[0].categories.map((c) => c.id)
|
||||
expect(ids).toEqual(['fcat-a', expect.any(String)])
|
||||
})
|
||||
|
||||
it('is enabled with nothing selected and preselects nothing among several zones', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
const add = screen.getByRole('button', { name: 'Ajouter une catégorie' })
|
||||
expect(add).toBeEnabled()
|
||||
await user.click(items()[2])
|
||||
await user.click(add)
|
||||
expect(screen.getByLabelText('Zone')).toHaveValue('')
|
||||
})
|
||||
|
||||
it('preselects the zone when exactly one exists', async () => {
|
||||
const text = edit(baseText(), {
|
||||
op: 'insert',
|
||||
element: {
|
||||
kind: 'zone',
|
||||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||||
},
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<FindingsTab {...props} />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
)
|
||||
expect(screen.getByLabelText('Zone')).toHaveValue('zone-a')
|
||||
expect(
|
||||
screen.getByText('Nouvelle catégorie dans la zone « Zone A »'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('is disabled with its hint while no zone exists', async () => {
|
||||
await openReady()
|
||||
render(<FindingsTab {...props} />)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter une catégorie' }),
|
||||
).toBeDisabled()
|
||||
expect(
|
||||
screen.getByText("Créez d'abord une zone pour ajouter une catégorie."),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('disables « Ajouter un constat » on a zone and at depth 8', async () => {
|
||||
@@ -529,35 +596,20 @@ describe('Constats tab', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the category form title (N1 review)', () => {
|
||||
const parentOf = (id: string) => {
|
||||
const found = buildItems(doc()).find((item) => item.id.includes(`"${id}"`) && item.path.at(-1) === id || item.zoneId === id && item.kind === 'zone')
|
||||
if (!found) throw new Error(`no ${id}`)
|
||||
return found
|
||||
}
|
||||
const title = (parent: ReturnType<typeof parentOf> | null) => {
|
||||
describe('the category form title (N1 review, C46)', () => {
|
||||
it('names the chosen zone, and falls back to an existing label before the choice', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<FindingCreateForm
|
||||
pending={{ kind: 'category', parent }}
|
||||
pending={{ kind: 'category', parent: null }}
|
||||
onCreated={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
/>,
|
||||
)
|
||||
return document.querySelector('p.font-medium')?.textContent
|
||||
}
|
||||
|
||||
it.each(['zone-a', 'fcat-a', 'node-a'])(
|
||||
'names the zone when the parent is %s',
|
||||
async (id) => {
|
||||
await openReady({ text: treeText() })
|
||||
expect(title(parentOf(id))).toBe(
|
||||
'Nouvelle catégorie dans la zone « Zone A »',
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
it('falls back to an existing label, never a missing key, without a parent', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
expect(title(null)).toBe('Ajouter une catégorie')
|
||||
const title = () => document.querySelector('p.font-medium')?.textContent
|
||||
expect(title()).toBe('Ajouter une catégorie')
|
||||
await user.selectOptions(screen.getByLabelText('Zone'), 'zone-a')
|
||||
expect(title()).toBe('Nouvelle catégorie dans la zone « Zone A »')
|
||||
})
|
||||
})
|
||||
@@ -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