mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-24 04:47:03 +00:00
* feat(web): larger empty-composer voice/dictate hit target When the primary UnifiedButton is idle voice/dictate (empty draft), use h-12 w-12 so Quest and touch clients get a usable target. Compact h-8 w-8 remains for Send, stop, and disabled states. Closes #2006 Co-authored-by: Cursor <cursoragent@cursor.com> * feat(web): full-height composer primary (voice ↔ send) Park UnifiedButton beside the composer card so it stretches the full input+toolbar height. Empty shows giant voice/dictate; draft swaps the same giant control to Send (icon only). Refs #2006 Co-authored-by: Cursor <cursoragent@cursor.com> * test(web): fix fill-height primary goldens + UnifiedButton mocks (#2006) Fill-height tip regressed no-arg onSend assertions and empty-voice helper expect; HappyComposer omitPrimaryButton needs UnifiedButton in vi.mocks. Co-authored-by: Cursor <cursoragent@cursor.com> * test(web): assert onSend('default') + fill-height helpers (#2006) Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): flush fill-height composer primary to card edge (#2006) Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): keep draft voice companion beside fill-height Send (#2006) Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): keep draft voice companion beside fill-height Send (#2006) Revert accidental soup dump of expandEnter + fat ComposerButtons. Empty stays giant voice; draft shows companion waveform left of giant Send. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): draft voice as toolbar circle, not beside giant Send (#2006) Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): hide draft voice when scratchlist owns Send (#2006) Codex P2: toolbar DictationButton and Ctrl/Cmd+Shift+D must not start voice while routesToScratchlist — same suppress as UnifiedButton. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): compact primary when composer is expanded (#2006) Fill-height Send/voice is for the collapsed Quest card. Expanded mode stays a compact control so we do not paint a full-shell action strip. Co-authored-by: Cursor <cursoragent@cursor.com> * chore: re-trigger upstream pr-review after Sol distributor 503 Empty commit — test/integration already green on tip; pr-review failed twice with "No available channel for model gpt-6.1-sol". Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
167 lines
6.3 KiB
TypeScript
167 lines
6.3 KiB
TypeScript
import {
|
|
AssistantRuntimeProvider,
|
|
type ChatModelAdapter,
|
|
useLocalRuntime,
|
|
} from '@assistant-ui/react'
|
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
import type { Ref } from 'react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { HappyComposer } from './HappyComposer'
|
|
|
|
vi.mock('@/components/AssistantChat/ComposerButtons', () => ({
|
|
ComposerButtons: (props: {
|
|
expanded: boolean
|
|
onExpandedToggle: () => void
|
|
showSettingsButton: boolean
|
|
settingsButtonRef?: Ref<HTMLButtonElement>
|
|
onSettingsToggle: () => void
|
|
}) => (
|
|
<div>
|
|
<button
|
|
type="button"
|
|
aria-label={props.expanded ? 'Collapse message editor' : 'Expand message editor'}
|
|
onClick={props.onExpandedToggle}
|
|
/>
|
|
{props.showSettingsButton ? (
|
|
<button
|
|
ref={props.settingsButtonRef}
|
|
type="button"
|
|
aria-label="Composer settings"
|
|
onClick={props.onSettingsToggle}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
),
|
|
UnifiedButton: () => null,
|
|
DictationButton: () => null,
|
|
isComposerPrimaryFillHeight: () => true,
|
|
}))
|
|
|
|
vi.mock('@/components/AssistantChat/StatusBar', () => ({ StatusBar: () => null }))
|
|
vi.mock('@/hooks/useComposerDraft', () => ({
|
|
useComposerDraft: () => ({ sessionId: undefined, complete: true, restoredAny: false, hasStoredAttachments: false }),
|
|
}))
|
|
vi.mock('@/hooks/usePlatform', () => ({
|
|
usePlatform: () => ({
|
|
isTelegram: false,
|
|
isTouch: false,
|
|
haptic: {
|
|
impact: () => {},
|
|
notification: () => {},
|
|
selection: () => {},
|
|
},
|
|
}),
|
|
}))
|
|
vi.mock('@/hooks/usePWAInstall', () => ({
|
|
usePWAInstall: () => ({
|
|
installState: 'idle',
|
|
canInstall: false,
|
|
canInstallIOS: false,
|
|
isStandalone: false,
|
|
isIOS: false,
|
|
promptInstall: async () => false,
|
|
dismissInstall: () => {},
|
|
}),
|
|
}))
|
|
vi.mock('@/lib/use-translation', () => ({
|
|
useTranslation: () => ({
|
|
t: (key: string) => key === 'misc.typeAMessage' ? 'Type a message' : key,
|
|
}),
|
|
}))
|
|
|
|
const adapter: ChatModelAdapter = {
|
|
async *run() {},
|
|
}
|
|
|
|
function TestRuntime(props: { withSettings?: boolean }) {
|
|
const runtime = useLocalRuntime(adapter)
|
|
return (
|
|
<AssistantRuntimeProvider runtime={runtime}>
|
|
<HappyComposer
|
|
agentFlavor={props.withSettings ? 'claude' : undefined}
|
|
onPermissionModeChange={props.withSettings ? () => {} : undefined}
|
|
/>
|
|
{props.withSettings ? (
|
|
<button
|
|
type="button"
|
|
aria-label="Outside action"
|
|
onPointerDown={(event) => event.stopPropagation()}
|
|
/>
|
|
) : null}
|
|
</AssistantRuntimeProvider>
|
|
)
|
|
}
|
|
|
|
describe('HappyComposer plain-text expansion', () => {
|
|
beforeEach(() => {
|
|
localStorage.clear()
|
|
localStorage.setItem('hapi.composer.richMentions', '0')
|
|
})
|
|
|
|
it('preserves draft text and selection across expand and collapse', async () => {
|
|
render(<TestRuntime />)
|
|
|
|
const draft = 'A long draft with a selection in the middle that must survive both editor layout changes.'
|
|
const collapsedInput = screen.getByRole('textbox') as HTMLTextAreaElement
|
|
fireEvent.change(collapsedInput, { target: { value: draft } })
|
|
collapsedInput.setSelectionRange(12, 36, 'forward')
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Expand message editor' }))
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByRole('button', { name: 'Collapse message editor' })).toBeInTheDocument()
|
|
const expandedInput = screen.getByRole('textbox') as HTMLTextAreaElement
|
|
expect(expandedInput).not.toBe(collapsedInput)
|
|
expect(expandedInput.value).toBe(draft)
|
|
expect(expandedInput.selectionStart).toBe(12)
|
|
expect(expandedInput.selectionEnd).toBe(36)
|
|
expect(expandedInput.selectionDirection).toBe('forward')
|
|
expect(document.activeElement).toBe(expandedInput)
|
|
})
|
|
|
|
const expandedInput = screen.getByRole('textbox') as HTMLTextAreaElement
|
|
expandedInput.setSelectionRange(42, 67, 'backward')
|
|
fireEvent.click(screen.getByRole('button', { name: 'Collapse message editor' }))
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByRole('button', { name: 'Expand message editor' })).toBeInTheDocument()
|
|
const nextCollapsedInput = screen.getByRole('textbox') as HTMLTextAreaElement
|
|
expect(nextCollapsedInput).not.toBe(expandedInput)
|
|
expect(nextCollapsedInput.value).toBe(draft)
|
|
expect(nextCollapsedInput.selectionStart).toBe(42)
|
|
expect(nextCollapsedInput.selectionEnd).toBe(67)
|
|
expect(nextCollapsedInput.selectionDirection).toBe('backward')
|
|
expect(document.activeElement).toBe(nextCollapsedInput)
|
|
})
|
|
})
|
|
|
|
it('closes settings when clicking outside while preserving inside and trigger interactions', () => {
|
|
render(<TestRuntime withSettings />)
|
|
|
|
const settingsButton = screen.getByRole('button', { name: 'Composer settings' })
|
|
fireEvent.click(settingsButton)
|
|
|
|
const panelLabel = screen.getByText('misc.permissionMode')
|
|
fireEvent.pointerDown(panelLabel)
|
|
expect(screen.getByText('misc.permissionMode')).toBeInTheDocument()
|
|
|
|
fireEvent.pointerDown(settingsButton)
|
|
expect(screen.getByText('misc.permissionMode')).toBeInTheDocument()
|
|
|
|
fireEvent.click(settingsButton)
|
|
expect(screen.queryByText('misc.permissionMode')).not.toBeInTheDocument()
|
|
|
|
fireEvent.click(settingsButton)
|
|
expect(screen.getByText('misc.permissionMode')).toBeInTheDocument()
|
|
|
|
fireEvent.pointerDown(screen.getByRole('textbox'))
|
|
expect(screen.queryByText('misc.permissionMode')).not.toBeInTheDocument()
|
|
|
|
fireEvent.click(settingsButton)
|
|
expect(screen.getByText('misc.permissionMode')).toBeInTheDocument()
|
|
|
|
fireEvent.pointerDown(screen.getByRole('button', { name: 'Outside action' }))
|
|
expect(screen.queryByText('misc.permissionMode')).not.toBeInTheDocument()
|
|
})
|
|
})
|