fix(host): restart home on early-edit cancel; clamp the dialog to short viewports

Escape canceling a path edit opened before any level listed relaunches
the home listing instead of stranding a blank picker (the editor had
superseded the initial request while parent was still null). The card's
height clamps to the viewport (min(420px, 100dvh - 32px)); header and
footer are flex-none and the columns scroll, so Open/Cancel stay
reachable on landscape phones and short embedded windows.
This commit is contained in:
creatixchu
2026-07-29 04:46:49 +08:00
parent 48141b0007
commit 1a9b84b19e
4 changed files with 34 additions and 5 deletions
@@ -177,6 +177,27 @@ describe('DirectoryBrowser', () => {
expect(screen.queryByLabelText('browser.editPath', { selector: 'input' })).toBeNull()
})
it('restarts the home listing when Escape cancels an edit opened before any level listed', async () => {
// The initial home listing hangs; Edit Path supersedes it while parent
// is still null, and Escape must not strand a blank picker.
let settled = false
const gate = new Promise<never>(() => {})
const listDirectory = vi.fn(async (path?: string) => {
if (!settled) { settled = true; return gate }
return listingFor(path)
})
mount({ listDirectory })
fireEvent.click(screen.getByRole('button', { name: 'browser.editPath' }))
const input = screen.getByLabelText<HTMLInputElement>('browser.editPath')
expect(input.value).toBe('')
fireEvent.keyDown(input, { key: 'Escape' })
// Cancellation relaunched the home listing instead of leaving neither
// rows nor status behind.
await waitFor(() => { expect(screen.getByRole('listitem').textContent).toBe('Documents') })
expect(listDirectory).toHaveBeenCalledTimes(2)
expect(listDirectory).toHaveBeenLastCalledWith(undefined)
})
it('surfaces an unreadable target as an alert and keeps the edit open for correction', async () => {
mount()
await waitFor(() => { expect(screen.getByRole('listitem')).toBeTruthy() })