mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
One composer row with the Send, Stop and microphone slot
This commit is contained in:
1 parent
13eca93b92
commit
64749a760d
4 files changed
+117
-79
No files matched your search
@@ -1,12 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { act, fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import { useSessionStatus } from '@/stores/sessionStatusStore'
|
||||
import { connectTestEventStream } from '@/test/render'
|
||||
import { promptTextarea, renderPromptInput } from '@/test/promptInput'
|
||||
import type { SessionMessageAssistant } from '@opencode-manager/shared/opencode'
|
||||
|
||||
const submitButton = () => document.querySelector('[data-submit-prompt]')
|
||||
const controlsRow = () => screen.getByTestId('composer-controls-row')
|
||||
const inputRow = () => screen.getByTestId('composer-input-row')
|
||||
const keysRow = () => screen.queryByTestId('composer-keys-row')
|
||||
const voiceMicButton = () => screen.queryByRole('button', { name: 'Start voice conversation' })
|
||||
const keyButtons = () => screen.queryAllByRole('toolbar', { name: 'Insert' })
|
||||
|
||||
@@ -23,15 +24,30 @@ function assistantUsageMessage(tokens: SessionMessageAssistant['tokens']): Sessi
|
||||
}
|
||||
|
||||
describe('PromptInput composer layout', () => {
|
||||
it('anchors the activity bar in the gap above the controls row', async () => {
|
||||
it('anchors the activity bar in the gap above the input row', async () => {
|
||||
useSessionStatus.getState().setStatus('test-session', { type: 'busy' })
|
||||
await renderPromptInput()
|
||||
|
||||
const bar = await screen.findByRole('progressbar', { name: 'Session working' })
|
||||
expect(controlsRow()).toContainElement(bar)
|
||||
expect(controlsRow().firstElementChild).toBe(bar)
|
||||
expect(inputRow()).toContainElement(bar)
|
||||
expect(inputRow().firstElementChild).toBe(bar)
|
||||
expect(bar).toHaveClass('absolute', 'bottom-full')
|
||||
expect(promptTextarea().compareDocumentPosition(bar) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
expect(bar.compareDocumentPosition(promptTextarea()) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
})
|
||||
|
||||
it('holds only the config trigger, the input and the action buttons in the input row', async () => {
|
||||
await renderPromptInput()
|
||||
|
||||
fireEvent.change(await screen.findByPlaceholderText('Send a message...'), { target: { value: 'hello' } })
|
||||
|
||||
const config = screen.getByRole('button', { name: /^Session config:/ })
|
||||
expect(within(inputRow()).getAllByRole('button')).toEqual([config, submitButton()])
|
||||
expect(promptTextarea().previousElementSibling).toBe(config)
|
||||
expect(screen.queryByRole('button', { name: /^Agent:/ })).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: /permission/i })).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: /goal/i })).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: /sandbox/i })).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: /attach|upload/i })).toBeNull()
|
||||
})
|
||||
|
||||
describe('primary action placement', () => {
|
||||
@@ -53,7 +69,7 @@ describe('PromptInput composer layout', () => {
|
||||
|
||||
expect(button.parentElement).toBe(textarea.parentElement)
|
||||
expect(textarea.nextElementSibling).toBe(button)
|
||||
expect(button.parentElement?.contains(controlsRow())).toBe(false)
|
||||
expect(button.parentElement).toBe(inputRow())
|
||||
})
|
||||
|
||||
it('sends the typed prompt from the row button', async () => {
|
||||
@@ -185,34 +201,32 @@ describe('PromptInput composer layout', () => {
|
||||
})
|
||||
|
||||
describe('mobile key bar', () => {
|
||||
it('replaces the config trigger with keys in the controls row while focused', async () => {
|
||||
it('mounts the key bar below the input row while focused and keeps the config trigger', async () => {
|
||||
await renderPromptInput({ mobile: true })
|
||||
|
||||
expect(await screen.findByPlaceholderText('Send a message...')).toBeInTheDocument()
|
||||
expect(keyButtons()).toHaveLength(0)
|
||||
expect(screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })).toBeInTheDocument()
|
||||
expect(keysRow()).toBeNull()
|
||||
const config = screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })
|
||||
expect(inputRow()).toContainElement(config)
|
||||
|
||||
fireEvent.focus(promptTextarea())
|
||||
|
||||
expect(keyButtons()).toHaveLength(1)
|
||||
expect(controlsRow().firstElementChild).toContainElement(keyButtons()[0])
|
||||
expect(screen.getByRole('button', { name: 'cmd /' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'mention @' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'bash !' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /^Session config/ })).not.toBeInTheDocument()
|
||||
expect(keysRow()).toContainElement(keyButtons()[0])
|
||||
expect(inputRow()).not.toContainElement(keyButtons()[0])
|
||||
expect(screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })).toBe(config)
|
||||
})
|
||||
|
||||
it('restores the config trigger after the prompt blurs', async () => {
|
||||
it('removes the key bar after the prompt blurs', async () => {
|
||||
await renderPromptInput({ mobile: true })
|
||||
|
||||
fireEvent.focus(await screen.findByPlaceholderText('Send a message...'))
|
||||
expect(screen.queryByRole('button', { name: /^Session config/ })).not.toBeInTheDocument()
|
||||
expect(keyButtons()).toHaveLength(1)
|
||||
|
||||
fireEvent.blur(promptTextarea())
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByRole('toolbar', { name: 'Insert' })).not.toBeInTheDocument()
|
||||
})
|
||||
await waitFor(() => expect(keysRow()).toBeNull())
|
||||
expect(screen.getByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -224,31 +238,28 @@ describe('PromptInput composer layout', () => {
|
||||
expect(screen.queryByRole('button', { name: 'Jump to latest' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps the voice button on the right and the session config in the controls row', async () => {
|
||||
it('keeps the voice button and the session config in the input row', async () => {
|
||||
await renderPromptInput({ mobile: true })
|
||||
|
||||
await screen.findByPlaceholderText('Send a message...')
|
||||
const actions = controlsRow().lastElementChild
|
||||
if (!(actions instanceof HTMLElement)) throw new Error('actions row is missing')
|
||||
expect(actions).toContainElement(voiceMicButton())
|
||||
|
||||
const config = screen.getByRole('button', { name: /^Session config/ })
|
||||
expect(controlsRow()).toContainElement(config)
|
||||
expect(actions).not.toContainElement(config)
|
||||
|
||||
expect(within(inputRow()).getAllByRole('button')).toEqual([config, voiceMicButton()])
|
||||
})
|
||||
})
|
||||
|
||||
describe('mobile voice button', () => {
|
||||
it('renders the mobile mic alongside Send when the prompt has content', async () => {
|
||||
it('replaces the mic with Send once the prompt has content', async () => {
|
||||
await renderPromptInput({ mobile: true })
|
||||
|
||||
fireEvent.change(await screen.findByPlaceholderText('Send a message...'), { target: { value: 'hello' } })
|
||||
await screen.findByPlaceholderText('Send a message...')
|
||||
expect(voiceMicButton()).not.toBeNull()
|
||||
|
||||
fireEvent.change(promptTextarea(), { target: { value: 'hello' } })
|
||||
|
||||
expect(submitButton()).not.toBeNull()
|
||||
expect(voiceMicButton()).not.toBeNull()
|
||||
const actions = controlsRow().lastElementChild
|
||||
if (!(actions instanceof HTMLElement)) throw new Error('actions row is missing')
|
||||
expect(actions).toContainElement(voiceMicButton())
|
||||
expect(voiceMicButton()).toBeNull()
|
||||
expect(inputRow()).toContainElement(submitButton())
|
||||
})
|
||||
|
||||
it('hides the mic while a permission is pending', async () => {
|
||||
@@ -270,6 +281,34 @@ describe('PromptInput composer layout', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('stop action', () => {
|
||||
it.each([true, false])('shows Stop in the input row while a turn runs and hides the mic (mobile: %s)', async (mobile) => {
|
||||
const { rerenderWith } = await renderPromptInput({ mobile, isSessionActive: true })
|
||||
|
||||
await screen.findByPlaceholderText('Send a message...')
|
||||
const stop = screen.getByTitle('Stop')
|
||||
expect(inputRow()).toContainElement(stop)
|
||||
expect(voiceMicButton()).toBeNull()
|
||||
if (mobile) {
|
||||
expect(stop).toHaveClass('min-h-11', 'min-w-11')
|
||||
}
|
||||
|
||||
await rerenderWith({ isSessionActive: false })
|
||||
|
||||
expect(screen.queryByTitle('Stop')).toBeNull()
|
||||
expect(voiceMicButton()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('keeps Stop next to Queue while the prompt has text during a turn', async () => {
|
||||
await renderPromptInput({ isSessionActive: true, isStreamingResponse: true })
|
||||
|
||||
fireEvent.change(await screen.findByPlaceholderText('Send a message...'), { target: { value: 'follow-up' } })
|
||||
|
||||
const queue = screen.getByTitle('Queue message')
|
||||
expect(queue.nextElementSibling).toBe(screen.getByTitle('Stop'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('control sizing', () => {
|
||||
it('keeps the mic at 44px before and after the prompt gains focus on mobile', async () => {
|
||||
await renderPromptInput({ mobile: true })
|
||||
|
||||
@@ -333,7 +333,7 @@ describe('PromptInput submission', () => {
|
||||
|
||||
fireEvent.change(promptTextarea(), { target: { value: 'draft while active' } })
|
||||
|
||||
expect(screen.getAllByTitle('Stop').length).toBeGreaterThan(0)
|
||||
expect(screen.getAllByTitle('Stop')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('clears the draft store for the session after a successful send', async () => {
|
||||
|
||||
@@ -1267,7 +1267,26 @@ return (
|
||||
|
||||
{!isVoiceActive && (
|
||||
<>
|
||||
<div className="flex items-end gap-1.5 md:gap-2 mb-1.5 md:mb-2">
|
||||
<div data-testid="composer-input-row" className="relative flex items-end gap-1.5 md:gap-2">
|
||||
<ComposerActivityBar sessionID={sessionID} />
|
||||
<SessionConfigMenu
|
||||
sessionID={sessionID}
|
||||
directory={directory}
|
||||
currentAgent={currentMode}
|
||||
isBashMode={isBashMode}
|
||||
onAgentChange={handleAgentChange}
|
||||
modelName={displayModelName}
|
||||
modelSelectionSession={modelSelectionSession}
|
||||
modelPickerOpen={isModelPickerOpen}
|
||||
onModelPickerOpenChange={setIsModelPickerOpen}
|
||||
isCompacting={isCompacting}
|
||||
onCompact={handleCompact}
|
||||
goalArmed={isGoalArmed}
|
||||
goalDisabled={isGoalModeDisabled}
|
||||
goalLabel={goalButtonLabel}
|
||||
onToggleGoal={toggleGoalArmed}
|
||||
onAttachFile={openFilePicker}
|
||||
/>
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
data-prompt-input
|
||||
@@ -1311,10 +1330,27 @@ return (
|
||||
<span className="whitespace-nowrap">{hasPendingPermissionForSession ? 'View' : (isStreamingResponse ? 'Queue' : 'Send')}</span>
|
||||
</button>
|
||||
)}
|
||||
{showStopButton && (
|
||||
<button
|
||||
onClick={handleStop}
|
||||
className="min-h-11 min-w-11 md:min-h-0 md:min-w-0 flex flex-shrink-0 items-center justify-center p-1.5 px-5 md:p-2 md:px-6 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 bg-destructive hover:bg-destructive/90 text-destructive-foreground border border-destructive/60 hover:border-destructive shadow-md shadow-destructive/30 hover:shadow-destructive/40 ring-1 ring-destructive/20 hover:ring-destructive/30"
|
||||
title="Stop"
|
||||
>
|
||||
<SquareFill className="w-4 h-4 md:w-5 md:h-5" />
|
||||
</button>
|
||||
)}
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept={ACCEPTED_FILE_TYPES.join(',')}
|
||||
className="hidden"
|
||||
onChange={handleFileInputChange}
|
||||
/>
|
||||
{showVoiceMic && !hasPromptContent && !showStopButton && renderVoiceMic()}
|
||||
</div>
|
||||
|
||||
{imageAttachments.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 px-2 py-2 mb-2">
|
||||
<div className="mt-2 flex flex-wrap gap-2 px-2 py-2">
|
||||
{imageAttachments.map((attachment) => (
|
||||
<div
|
||||
key={attachment.id}
|
||||
@@ -1334,50 +1370,11 @@ return (
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div data-testid="composer-controls-row" className="relative flex gap-1.5 md:gap-2 items-center justify-between">
|
||||
<ComposerActivityBar sessionID={sessionID} />
|
||||
<div className="flex flex-1 md:flex-initial gap-1.5 md:gap-2 items-center min-w-0">
|
||||
{showMobileKeys ? renderMobileKeys() : (
|
||||
<SessionConfigMenu
|
||||
sessionID={sessionID}
|
||||
directory={directory}
|
||||
currentAgent={currentMode}
|
||||
isBashMode={isBashMode}
|
||||
onAgentChange={handleAgentChange}
|
||||
modelName={displayModelName}
|
||||
modelSelectionSession={modelSelectionSession}
|
||||
modelPickerOpen={isModelPickerOpen}
|
||||
onModelPickerOpenChange={setIsModelPickerOpen}
|
||||
isCompacting={isCompacting}
|
||||
onCompact={handleCompact}
|
||||
goalArmed={isGoalArmed}
|
||||
goalDisabled={isGoalModeDisabled}
|
||||
goalLabel={goalButtonLabel}
|
||||
onToggleGoal={toggleGoalArmed}
|
||||
onAttachFile={openFilePicker}
|
||||
/>
|
||||
)}
|
||||
{showMobileKeys && (
|
||||
<div data-testid="composer-keys-row" className="mt-1.5 flex">
|
||||
{renderMobileKeys()}
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5 md:gap-2 flex-shrink-0">
|
||||
{showStopButton && (
|
||||
<button
|
||||
onClick={handleStop}
|
||||
className="hidden md:block p-1.5 px-5 md:p-2 md:px-6 rounded-lg transition-all duration-200 active:scale-95 hover:scale-105 bg-destructive hover:bg-destructive/90 text-destructive-foreground border border-destructive/60 hover:border-destructive shadow-md shadow-destructive/30 hover:shadow-destructive/40 ring-1 ring-destructive/20 hover:ring-destructive/30"
|
||||
title="Stop"
|
||||
>
|
||||
<SquareFill className="w-4 h-4 md:w-5 md:h-5" />
|
||||
</button>
|
||||
)}
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept={ACCEPTED_FILE_TYPES.join(',')}
|
||||
className="hidden"
|
||||
onChange={handleFileInputChange}
|
||||
/>
|
||||
{showVoiceMic && renderVoiceMic()}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user