Files
ForgeBase/Max Avatar/tests/unit/components/ObjectiveValidationCard.test.tsx
T
williamandClaude Sonnet 5 309db80add 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>
2026-10-31 21:58:38 +01:00

86 lines
3.4 KiB
TypeScript

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()
})
})