test(desktop): cover the busy empty-Enter double-send

This commit is contained in:
Brooklyn Nicholson 2026-07-27 22:43:42 -05:00
parent 84d77b608c
commit ac8310bcc2

View file

@ -29,7 +29,8 @@ function Harness({
onSubmit,
onQueue,
onCancel,
onDrain
onDrain,
onSendNow
}: {
busy?: boolean
disabled?: boolean
@ -38,6 +39,7 @@ function Harness({
onQueue: (text: string) => void
onCancel: () => void
onDrain: () => void
onSendNow?: (id: string) => void
}) {
const editorRef = useRef<HTMLDivElement>(null)
const draftRef = useRef('')
@ -103,6 +105,12 @@ function Harness({
}
if (busy && !hasLivePayload) {
const head = queued[0]
if (head) {
onSendNow?.(head)
}
return
}
@ -167,13 +175,21 @@ describe('composer Enter submit — live DOM vs stale composer state (#39630)',
expect(onCancel).not.toHaveBeenCalled()
})
it('treats an empty Enter while busy as a no-op (never an accidental Stop)', async () => {
it('treats an empty Enter while busy with nothing queued as a no-op (never an accidental Stop)', async () => {
const onCancel = vi.fn()
const onSubmit = vi.fn()
const onQueue = vi.fn()
const onSendNow = vi.fn()
const { getByTestId } = render(
<Harness busy onCancel={onCancel} onDrain={vi.fn()} onQueue={onQueue} onSubmit={onSubmit} />
<Harness
busy
onCancel={onCancel}
onDrain={vi.fn()}
onQueue={onQueue}
onSendNow={onSendNow}
onSubmit={onSubmit}
/>
)
const editor = getByTestId('editor')
@ -186,6 +202,35 @@ describe('composer Enter submit — live DOM vs stale composer state (#39630)',
expect(onCancel).not.toHaveBeenCalled()
expect(onSubmit).not.toHaveBeenCalled()
expect(onQueue).not.toHaveBeenCalled()
expect(onSendNow).not.toHaveBeenCalled()
})
it('double-send: an empty Enter while busy with a queued turn sends that turn now', async () => {
const onCancel = vi.fn()
const onSendNow = vi.fn()
const { getByTestId } = render(
<Harness
busy
onCancel={onCancel}
onDrain={vi.fn()}
onQueue={vi.fn()}
onSendNow={onSendNow}
onSubmit={vi.fn()}
queued={['queued-1', 'queued-2']}
/>
)
const editor = getByTestId('editor')
await act(async () => {
editor.textContent = ''
fireEvent.keyDown(editor, { key: 'Enter' })
})
// Head of the queue, and NOT a bare cancel — send-now promotes + interrupts.
expect(onSendNow).toHaveBeenCalledWith('queued-1')
expect(onCancel).not.toHaveBeenCalled()
})
it('drains the next queued prompt on Enter when idle with a truly empty editor', async () => {