Shell and Agent 1 UI components per docs/Max_Composants_Frontend.md: - InputBar: send on Enter, newline on Shift+Enter, mic toggle (STT itself stays in the main process). - ChatBubble: max/user variants reusing the existing chat-bubble design-system classes, simple Markdown via react-markdown+remark-gfm. - AvatarStatusIndicator: purely visual, no status computed here. - PipelineStepper + utils/pipelineSteps.ts: the stepper itself only renders the `steps` prop as given (never computes status); the session.status -> step list derivation lives in a separate pure function the store/App call, per the doc's explicit rule that the component must never calculate status itself. - ObjectiveValidationCard: single-field-at-a-time editing, locked and irreversible once onConfirm resolves. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { render, screen, fireEvent } from '@testing-library/react'
|
|
import InputBar from '../../../src/renderer/src/components/InputBar'
|
|
|
|
describe('<InputBar />', () => {
|
|
it('should send the trimmed text and clear the field on Enter', () => {
|
|
const onSend = vi.fn()
|
|
render(<InputBar onSend={onSend} />)
|
|
|
|
const input = screen.getByLabelText<HTMLInputElement>('Message')
|
|
fireEvent.change(input, { target: { value: ' bonjour ' } })
|
|
fireEvent.keyDown(input, { key: 'Enter' })
|
|
|
|
expect(onSend).toHaveBeenCalledWith('bonjour')
|
|
expect(input.value).toBe('')
|
|
})
|
|
|
|
it('should not send on Shift+Enter (newline)', () => {
|
|
const onSend = vi.fn()
|
|
render(<InputBar onSend={onSend} />)
|
|
|
|
const input = screen.getByLabelText('Message')
|
|
fireEvent.change(input, { target: { value: 'ligne 1' } })
|
|
fireEvent.keyDown(input, { key: 'Enter', shiftKey: true })
|
|
|
|
expect(onSend).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should send via the send button and disable it when the field is empty', () => {
|
|
const onSend = vi.fn()
|
|
render(<InputBar onSend={onSend} />)
|
|
|
|
const sendButton = screen.getByRole('button', { name: 'Envoyer le message' })
|
|
expect(sendButton).toBeDisabled()
|
|
|
|
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'salut' } })
|
|
expect(sendButton).toBeEnabled()
|
|
fireEvent.click(sendButton)
|
|
expect(onSend).toHaveBeenCalledWith('salut')
|
|
})
|
|
|
|
it('should not send when disabled', () => {
|
|
const onSend = vi.fn()
|
|
render(<InputBar onSend={onSend} disabled />)
|
|
|
|
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'salut' } })
|
|
fireEvent.keyDown(screen.getByLabelText('Message'), { key: 'Enter' })
|
|
|
|
expect(onSend).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('should call onVoiceStart then onVoiceStop when the microphone button is toggled', () => {
|
|
const onVoiceStart = vi.fn()
|
|
const onVoiceStop = vi.fn()
|
|
render(<InputBar onSend={vi.fn()} onVoiceStart={onVoiceStart} onVoiceStop={onVoiceStop} />)
|
|
|
|
const micButton = screen.getByRole('button', { name: 'Activer le microphone' })
|
|
fireEvent.click(micButton)
|
|
expect(onVoiceStart).toHaveBeenCalledOnce()
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: "Arreter l'enregistrement vocal" }))
|
|
expect(onVoiceStop).toHaveBeenCalledOnce()
|
|
})
|
|
})
|