hermes-agent/ui-tui/src/__tests__/useQueue.test.ts
Brooklyn Nicholson ea1012f59f feat(tui): delete queued message while editing with ctrl-x / cancel with esc
Today there's no way to remove a queued message — ↑ loads it for edit,
ctrl-K dispatches the head, but a draft you no longer want stays put
forever. ctrl-C just clears the composer and exits edit mode without
touching the queue.

Two new bindings, both gated on queueEditIdx !== null so they're
inert when the user isn't pointing at a queue item:

- ctrl-X — delete the queue item being edited, clear composer, exit
  edit mode.  "cut" matches the mental model and doesn't collide with
  any existing binding.
- esc — cancel the edit (composer clears, item stays in queue).
  Mirrors ctrl-C's existing behavior so muscle memory has two paths.

Header line now reads `queued (3) · editing 2 · ⌃X delete · esc cancel`
when in edit mode, so the affordance is discoverable without /help.
The /help hotkey table also gets a Ctrl+X entry.

ctrl-C is intentionally unchanged: it should never destroy queued
content.  Cancel is non-destructive (esc / ctrl-C); only ctrl-X
removes the item.
2026-04-27 15:24:14 -05:00

28 lines
636 B
TypeScript

import { describe, expect, it } from 'vitest'
import { removeAt } from '../hooks/useQueue.js'
describe('removeAt', () => {
it('removes the item at the given index in place', () => {
const arr = ['a', 'b', 'c']
removeAt(arr, 1)
expect(arr).toEqual(['a', 'c'])
})
it('is a no-op when the index is out of bounds', () => {
const arr = ['a', 'b']
removeAt(arr, -1)
removeAt(arr, 5)
expect(arr).toEqual(['a', 'b'])
})
it('returns the same reference (mutates in place)', () => {
const arr = ['x']
const same = removeAt(arr, 0)
expect(same).toBe(arr)
expect(arr).toEqual([])
})
})