fix(host): cancelling a superseded path edit falls back to the single-pane level

A draft edit can invalidate the selection's preview request; Escape then
left selected set with no child and nothing loading — a half-empty
two-pane view. Cancel now clears the selection when no preview exists
(ds-review-bot round 7).
This commit is contained in:
creatixchu
2026-07-29 00:38:37 +08:00
parent 36be9f26db
commit b0d120efa8
2 changed files with 22 additions and 0 deletions
@@ -355,6 +355,23 @@ describe('DirectoryBrowser', () => {
expect(screen.queryByText('harness')).toBeNull()
})
it('falls back to the single-pane level when a path edit superseded the preview and was cancelled', async () => {
const pending: ((listing: DirectoryListing) => void)[] = []
const b = mount()
await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() })
// Selection starts a preview that never lands (superseded below).
b.listDirectory.mockImplementation(() =>
new Promise<DirectoryListing>((settle) => { pending.push(settle) }))
fireEvent.click(rowButton(screen.getByRole('listitem')))
fireEvent.click(screen.getByRole('button', { name: 'browser.editPath' }))
const input = screen.getByLabelText('browser.editPath')
fireEvent.change(input, { target: { value: `${DOCS}/x` } })
fireEvent.keyDown(input, { key: 'Escape' })
// No half-empty two-pane residue: back to the single wide level.
expect(columns()).toHaveLength(1)
expect(screen.getByRole('button', { name: 'browser.editPath' })).toBeTruthy()
})
it('ignores dismissal while adoption is busy', async () => {
const b = mount({ busy: true })
await waitFor(() => { expect(screen.getByRole('dialog')).toBeTruthy() })