hermes-agent/ui-tui/src/lib/text.test.ts
Brooklyn Nicholson 62fe9fd101 style(desktop,tui): fix all lint/type/formatting issues
Bring apps/desktop and ui-tui to a clean state for typecheck, eslint,
and prettier:

- Run prettier across both trees (printWidth/wrap drift; prettier is not
  CI-enforced for these JS projects, so main had accumulated drift).
- Apply eslint --fix for padding-line-between-statements and perfectionist
  import/export sorting.
- Manual fixes for non-auto-fixable rules:
  - remove unused node:net import in electron/main.cjs (uses Electron net)
  - replace inline `typeof import(...)` annotations with top-level
    `import type * as EnvModule` in two ui-tui test files
  - scoped eslint-disable no-control-regex on intentional sentinel/ANSI
    regexes (mathUnicode.ts, text.ts)
  - resolve react-hooks/exhaustive-deps per-case: correct swapped/missing
    deps, collapse redundant session.* members, and justified disables on
    settings mount-only data-load effects to preserve run-once behavior

No behavior changes; test pass/fail counts are unchanged from the main
baseline.
2026-06-26 01:04:33 -05:00

53 lines
1.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { formatAbandonedClarify, stripTrailingPasteNewlines } from './text.js'
describe('stripTrailingPasteNewlines', () => {
it('removes trailing newline runs from pasted text', () => {
expect(stripTrailingPasteNewlines('alpha\n')).toBe('alpha')
expect(stripTrailingPasteNewlines('alpha\nbeta\n\n')).toBe('alpha\nbeta')
})
it('preserves interior newlines', () => {
expect(stripTrailingPasteNewlines('alpha\nbeta\ngamma')).toBe('alpha\nbeta\ngamma')
})
it('preserves newline-only pastes', () => {
expect(stripTrailingPasteNewlines('\n\n')).toBe('\n\n')
})
})
describe('formatAbandonedClarify', () => {
it('renders the question, numbered options, and reason', () => {
const out = formatAbandonedClarify('How do you want to scope?', ['Option A', 'Option B', 'Option C'], 'timed out')
expect(out).toBe(
[
'ask How do you want to scope?',
' 1. Option A',
' 2. Option B',
' 3. Option C',
' (timed out — no selection)'
].join('\n')
)
})
it('handles a prompt with no choices (free-text clarify)', () => {
const out = formatAbandonedClarify('What is the target branch?', null, 'cancelled')
expect(out).toBe(['ask What is the target branch?', ' (cancelled — no selection)'].join('\n'))
})
it('trims surrounding whitespace on the question', () => {
const out = formatAbandonedClarify(' trailing space ', [], 'timed out')
expect(out.split('\n')[0]).toBe('ask trailing space')
})
it('numbers options 1-based to match the live ClarifyPrompt', () => {
const out = formatAbandonedClarify('q', ['first'], 'timed out')
expect(out).toContain(' 1. first')
expect(out).not.toContain(' 0.')
})
})