feat(pipeline): add InputBar, ChatBubble, AvatarStatusIndicator, PipelineStepper and ObjectiveValidationCard
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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
ed32c21f24
commit
309db80add
@@ -0,0 +1,31 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import AvatarStatusIndicator from '../../../src/renderer/src/components/AvatarStatusIndicator'
|
||||
|
||||
describe('<AvatarStatusIndicator />', () => {
|
||||
it('should render nothing when idle', () => {
|
||||
const { container } = render(<AvatarStatusIndicator status="idle" />)
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('should show the default label for thinking', () => {
|
||||
render(<AvatarStatusIndicator status="thinking" />)
|
||||
expect(screen.getByText('Max reflechit...')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the default label for speaking', () => {
|
||||
render(<AvatarStatusIndicator status="speaking" />)
|
||||
expect(screen.getByText('Max parle...')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show a fixed green dot and "En attente" for waiting', () => {
|
||||
const { container } = render(<AvatarStatusIndicator status="waiting" />)
|
||||
expect(screen.getByText('En attente')).toBeInTheDocument()
|
||||
expect(container.querySelector('.avatar-status__dot--waiting')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should prefer an explicit label over the default one', () => {
|
||||
render(<AvatarStatusIndicator status="thinking" label="Max recherche des sources..." />)
|
||||
expect(screen.getByText('Max recherche des sources...')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import ChatBubble from '../../../src/renderer/src/components/ChatBubble'
|
||||
|
||||
describe('<ChatBubble />', () => {
|
||||
it('should render a Max message with the max variant class', () => {
|
||||
const { container } = render(<ChatBubble role="max" content="Bonjour !" />)
|
||||
expect(screen.getByText('Bonjour !')).toBeInTheDocument()
|
||||
expect(container.querySelector('.chat-bubble--max')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should render a user message with the user variant class', () => {
|
||||
const { container } = render(<ChatBubble role="user" content="Salut" />)
|
||||
expect(container.querySelector('.chat-bubble--user')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should render simple markdown (bold, code)', () => {
|
||||
const { container } = render(<ChatBubble role="max" content="**gras** et `code`" />)
|
||||
expect(container.querySelector('strong')?.textContent).toBe('gras')
|
||||
expect(container.querySelector('code')?.textContent).toBe('code')
|
||||
})
|
||||
|
||||
it('should display the timestamp when provided', () => {
|
||||
render(<ChatBubble role="max" content="x" timestamp={new Date('2026-01-01T10:30:00')} />)
|
||||
expect(screen.getByText('10:30')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should not render a time element when no timestamp is given', () => {
|
||||
const { container } = render(<ChatBubble role="max" content="x" />)
|
||||
expect(container.querySelector('time')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,85 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
||||
import ObjectiveValidationCard from '../../../src/renderer/src/components/ObjectiveValidationCard'
|
||||
|
||||
const objective = {
|
||||
subject: 'Facturation freelance',
|
||||
professionalGoal: 'Facturer mes clients sans erreur',
|
||||
duration: '2 semaines'
|
||||
}
|
||||
|
||||
describe('<ObjectiveValidationCard />', () => {
|
||||
it('should display the 3 pillars', () => {
|
||||
render(
|
||||
<ObjectiveValidationCard objective={objective} onConfirm={vi.fn()} onRestart={vi.fn()} />
|
||||
)
|
||||
expect(screen.getByText('Facturation freelance')).toBeInTheDocument()
|
||||
expect(screen.getByText('Facturer mes clients sans erreur')).toBeInTheDocument()
|
||||
expect(screen.getByText('2 semaines')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should switch a row to edit mode and back without affecting other rows', () => {
|
||||
render(
|
||||
<ObjectiveValidationCard objective={objective} onConfirm={vi.fn()} onRestart={vi.fn()} />
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Modifier Sujet' }))
|
||||
const input = screen.getByLabelText<HTMLInputElement>('Sujet')
|
||||
expect(input.value).toBe('Facturation freelance')
|
||||
|
||||
fireEvent.change(input, { target: { value: 'Facturation freelance avancee' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Valider Sujet' }))
|
||||
|
||||
expect(screen.getByText('Facturation freelance avancee')).toBeInTheDocument()
|
||||
expect(screen.queryByLabelText('Sujet')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should close the previous field when opening another one', () => {
|
||||
render(
|
||||
<ObjectiveValidationCard objective={objective} onConfirm={vi.fn()} onRestart={vi.fn()} />
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Modifier Sujet' }))
|
||||
expect(screen.getByLabelText('Sujet')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Modifier Duree' }))
|
||||
expect(screen.queryByLabelText('Sujet')).not.toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Duree')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should not allow validating an empty field', () => {
|
||||
render(
|
||||
<ObjectiveValidationCard objective={objective} onConfirm={vi.fn()} onRestart={vi.fn()} />
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Modifier Sujet' }))
|
||||
fireEvent.change(screen.getByLabelText('Sujet'), { target: { value: '' } })
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Valider Sujet' })).toBeDisabled()
|
||||
})
|
||||
|
||||
it('should call onConfirm with the current draft and show the locked confirmed state', async () => {
|
||||
const onConfirm = vi.fn().mockResolvedValue(undefined)
|
||||
render(
|
||||
<ObjectiveValidationCard objective={objective} onConfirm={onConfirm} onRestart={vi.fn()} />
|
||||
)
|
||||
|
||||
fireEvent.click(
|
||||
screen.getByRole('button', { name: "C'est exactement ca, confirmer l'objectif" })
|
||||
)
|
||||
|
||||
expect(onConfirm).toHaveBeenCalledWith(objective)
|
||||
await waitFor(() => expect(screen.getByText(/Objectif enregistre/)).toBeInTheDocument())
|
||||
expect(screen.queryByRole('button', { name: 'Modifier Sujet' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should call onRestart when the secondary button is clicked', () => {
|
||||
const onRestart = vi.fn()
|
||||
render(
|
||||
<ObjectiveValidationCard objective={objective} onConfirm={vi.fn()} onRestart={onRestart} />
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Recommencer depuis le debut' }))
|
||||
expect(onRestart).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import PipelineStepper from '../../../src/renderer/src/components/PipelineStepper'
|
||||
|
||||
describe('<PipelineStepper />', () => {
|
||||
it('should render each step with its own status class, unchanged from props', () => {
|
||||
const { container } = render(
|
||||
<PipelineStepper
|
||||
steps={[
|
||||
{ id: 1, label: 'Objectif', status: 'done' },
|
||||
{ id: 2, label: 'Cartographie', status: 'active', subLabel: 'En cours' },
|
||||
{ id: 3, label: 'Niveau', status: 'pending' }
|
||||
]}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(container.querySelectorAll('.step--done')).toHaveLength(1)
|
||||
expect(container.querySelectorAll('.step--active')).toHaveLength(1)
|
||||
expect(container.querySelectorAll('.step--pending')).toHaveLength(1)
|
||||
expect(screen.getByText('Objectif')).toBeInTheDocument()
|
||||
expect(screen.getByText('Cartographie')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should only show the sub-label for the active step', () => {
|
||||
render(
|
||||
<PipelineStepper
|
||||
steps={[
|
||||
{ id: 1, label: 'Objectif', status: 'done', subLabel: 'ignore' },
|
||||
{ id: 2, label: 'Cartographie', status: 'active', subLabel: 'En cours' }
|
||||
]}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.queryByText('ignore')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('En cours')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show a checkmark instead of the number for a done step', () => {
|
||||
render(<PipelineStepper steps={[{ id: 1, label: 'Objectif', status: 'done' }]} />)
|
||||
expect(screen.getByText('✓')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { deriveStepsFromStatus } from '../../../src/renderer/src/utils/pipelineSteps'
|
||||
|
||||
describe('deriveStepsFromStatus()', () => {
|
||||
it('should mark every step pending when there is no session yet', () => {
|
||||
const steps = deriveStepsFromStatus(null)
|
||||
expect(steps).toHaveLength(7)
|
||||
expect(steps.every((s) => s.status === 'pending')).toBe(true)
|
||||
})
|
||||
|
||||
it('should mark the objective step active during objective_discovery', () => {
|
||||
const steps = deriveStepsFromStatus('objective_discovery')
|
||||
expect(steps.at(0)?.status).toBe('active')
|
||||
expect(steps.slice(1).every((s) => s.status === 'pending')).toBe(true)
|
||||
})
|
||||
|
||||
it('should mark the objective step done and mapping active once objective_validated', () => {
|
||||
const steps = deriveStepsFromStatus('objective_validated')
|
||||
expect(steps.at(0)?.status).toBe('done')
|
||||
expect(steps.at(1)?.status).toBe('active')
|
||||
})
|
||||
|
||||
it('should mark every step done once completed', () => {
|
||||
const steps = deriveStepsFromStatus('completed')
|
||||
expect(steps.every((s) => s.status === 'done')).toBe(true)
|
||||
})
|
||||
|
||||
it('should mark steps before the current one as done and steps after as pending', () => {
|
||||
const steps = deriveStepsFromStatus('researching')
|
||||
expect(steps.at(0)?.status).toBe('done')
|
||||
expect(steps.at(1)?.status).toBe('done')
|
||||
expect(steps.at(2)?.status).toBe('done')
|
||||
expect(steps.at(3)?.status).toBe('active')
|
||||
expect(steps.at(4)?.status).toBe('pending')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user