fix(editor): free paths never reshaped on attach, category zone chosen explicitly

This commit is contained in:
bchanot committed 2026-11-04 22:14:59 +01:00
1 parent f1175bb3a1
commit a69eba569b
13 files changed
+333 -117

No files matched your search

+92 -40
View File
@@ -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 »')
})
})