fix(editor): Task 8 round 2, cascade closes the sheet

This commit is contained in:
bchanot committed 2026-11-14 15:13:38 +01:00
1 parent 579d8afff4
commit 791fc03a0d
7 files changed
+205 -10

No files matched your search

@@ -42,7 +42,7 @@ function Asking(props: {
function Editor() {
const nav = useEditorNavigation('findings')
useLeaveConfirm(nav.guards)
useLeaveConfirm(nav)
return (
<>
<Layer guards={nav.guards} layer="finding" />
@@ -559,3 +559,96 @@ describe('final review: the creation dialog fades out as a creation (M-9)', () =
expect(titles).not.toContain('Modifier la référence')
})
})
/** The Navigation API as the leave guard reads it: `navigate` events and `traverseTo`. */
class NavigationStub extends EventTarget {
traverseTo = vi.fn((key: string) => {
void key
return { committed: Promise.resolve(), finished: Promise.resolve() }
})
}
describe('a jump with the reference over the sheet of a dirty finding (criterion 23)', () => {
let api: NavigationStub
beforeEach(() => {
api = new NavigationStub()
Object.defineProperty(window, 'navigation', {
value: api,
configurable: true,
})
})
afterEach(() => {
Reflect.deleteProperty(window, 'navigation')
})
const sheet = () =>
[...dialogs()].find((d) => d.querySelector('[data-place="citations"]'))
const question = 'Abandonner les modifications ?'
/** The reference dialog: the finding's edit form is a draft form too. */
const refForm = () =>
[...dialogs()].find((d) => d.querySelector('#reference-form-citation')) as
| HTMLElement
| undefined
const inForm = () => within(refForm()!)
function jump() {
const url = new URL('/app/admin/sheets', window.location.origin).href
const event = Object.assign(new Event('navigate', { cancelable: true }), {
navigationType: 'traverse',
destination: { url, key: 'list', sameDocument: true },
})
act(() => {
api.dispatchEvent(event)
})
return event
}
/** Node A in edit with a typed name, its sheet open, Barone in edit with a typed citation. */
async function stacked(user: User) {
await user.click(screen.getByRole('tab', { name: 'Constats' }))
await openFinding(user, /Node A/)
const finding = within(findingDialog()!)
await user.click(finding.getByRole('button', { name: 'Modifier' }))
await user.type(finding.getByLabelText('Nom (FR)'), ' bis')
await user.click(finding.getByRole('button', { name: '2 références' }))
await waitFor(() => expect(sheet()).toBeDefined())
const inSheet = within(sheet() as HTMLElement)
const head = inSheet.getByRole('button', { name: /^Barone/ })
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
const tile = head.closest('li')!
await user.click(within(tile).getByRole('button', { name: 'Modifier' }))
await waitFor(() => expect(refForm()).toBeDefined())
await user.type(inForm().getByLabelText('Citation'), ' x')
}
it('the finding asks next with the sheet closed, focused; the jump goes after it', async () => {
const user = await mount()
await stacked(user)
expect(jump().defaultPrevented).toBe(true)
expect(inForm().getByText(question)).toBeVisible()
await user.click(inForm().getByRole('button', { name: 'Abandonner' }))
await waitFor(() => expect(refForm()).toBeUndefined())
await waitFor(() => expect(sheet()).toBeUndefined())
const finding = within(findingDialog()!)
expect(finding.getByText(question)).toBeVisible()
const keep = finding.getByRole('button', { name: 'Continuer la saisie' })
await waitFor(() => expect(keep).toHaveFocus())
expect(api.traverseTo).not.toHaveBeenCalled()
await user.click(finding.getByRole('button', { name: 'Abandonner' }))
expect(api.traverseTo).toHaveBeenCalledWith('list')
})
it('« Continuer la saisie » there keeps the finding draft and drops the jump', async () => {
const user = await mount()
await stacked(user)
jump()
await user.click(inForm().getByRole('button', { name: 'Abandonner' }))
await waitFor(() => expect(sheet()).toBeUndefined())
const finding = within(findingDialog()!)
await user.click(
finding.getByRole('button', { name: 'Continuer la saisie' }),
)
expect(finding.getByLabelText('Nom (FR)')).toHaveValue('Node A bis')
expect(api.traverseTo).not.toHaveBeenCalled()
})
})