From 309db80add2a40fd94c586ec4557ca0cf6f1c4a2 Mon Sep 17 00:00:00 2001 From: william Date: Sat, 31 Oct 2026 21:58:38 +0100 Subject: [PATCH] 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 --- .../src/components/AvatarStatusIndicator.tsx | 40 +++++ .../renderer/src/components/ChatBubble.tsx | 26 ++++ .../src/renderer/src/components/InputBar.tsx | 82 +++++++++++ .../components/ObjectiveValidationCard.tsx | 136 +++++++++++++++++ .../src/components/PipelineStepper.tsx | 36 +++++ Max Avatar/src/renderer/src/styles/app.css | 138 ++++++++++++++++++ .../src/renderer/src/styles/components.css | 48 ++++++ .../src/renderer/src/utils/pipelineSteps.ts | 35 +++++ .../components/AvatarStatusIndicator.test.tsx | 31 ++++ .../tests/unit/components/ChatBubble.test.tsx | 32 ++++ .../tests/unit/components/InputBar.test.tsx | 64 ++++++++ .../ObjectiveValidationCard.test.tsx | 85 +++++++++++ .../unit/components/PipelineStepper.test.tsx | 42 ++++++ .../unit/components/pipelineSteps.test.ts | 36 +++++ 14 files changed, 831 insertions(+) create mode 100644 Max Avatar/src/renderer/src/components/AvatarStatusIndicator.tsx create mode 100644 Max Avatar/src/renderer/src/components/ChatBubble.tsx create mode 100644 Max Avatar/src/renderer/src/components/InputBar.tsx create mode 100644 Max Avatar/src/renderer/src/components/ObjectiveValidationCard.tsx create mode 100644 Max Avatar/src/renderer/src/components/PipelineStepper.tsx create mode 100644 Max Avatar/src/renderer/src/utils/pipelineSteps.ts create mode 100644 Max Avatar/tests/unit/components/AvatarStatusIndicator.test.tsx create mode 100644 Max Avatar/tests/unit/components/ChatBubble.test.tsx create mode 100644 Max Avatar/tests/unit/components/InputBar.test.tsx create mode 100644 Max Avatar/tests/unit/components/ObjectiveValidationCard.test.tsx create mode 100644 Max Avatar/tests/unit/components/PipelineStepper.test.tsx create mode 100644 Max Avatar/tests/unit/components/pipelineSteps.test.ts diff --git a/Max Avatar/src/renderer/src/components/AvatarStatusIndicator.tsx b/Max Avatar/src/renderer/src/components/AvatarStatusIndicator.tsx new file mode 100644 index 0000000..e105963 --- /dev/null +++ b/Max Avatar/src/renderer/src/components/AvatarStatusIndicator.tsx @@ -0,0 +1,40 @@ +export type AvatarStatus = 'idle' | 'thinking' | 'speaking' | 'waiting' + +export interface AvatarStatusIndicatorProps { + status: AvatarStatus + label?: string +} + +const DEFAULT_LABELS = new Map([ + ['thinking', 'Max reflechit...'], + ['speaking', 'Max parle...'], + ['waiting', 'En attente'] +]) + +/** + * Badge d'etat sous l'avatar (docs/Max_Composants_Frontend.md section 2). Purement visuel : pas + * d'appel API, aucune logique de calcul d'etat ici (le statut vient toujours du parent). + */ +export default function AvatarStatusIndicator({ + status, + label +}: AvatarStatusIndicatorProps): React.JSX.Element | null { + if (status === 'idle') return null + + const text = label ?? DEFAULT_LABELS.get(status) ?? '' + + return ( +
+ {status === 'waiting' ? ( + + ) : ( + + + + + + )} + {text} +
+ ) +} diff --git a/Max Avatar/src/renderer/src/components/ChatBubble.tsx b/Max Avatar/src/renderer/src/components/ChatBubble.tsx new file mode 100644 index 0000000..ab8b24a --- /dev/null +++ b/Max Avatar/src/renderer/src/components/ChatBubble.tsx @@ -0,0 +1,26 @@ +import ReactMarkdown from 'react-markdown' +import remarkGfm from 'remark-gfm' + +export interface ChatBubbleProps { + role: 'max' | 'user' + content: string + timestamp?: Date +} + +/** Bulle de message de la zone de conversation (docs/Max_Composants_Frontend.md section 4). */ +export default function ChatBubble({ + role, + content, + timestamp +}: ChatBubbleProps): React.JSX.Element { + return ( +
+ {content} + {timestamp && ( + + )} +
+ ) +} diff --git a/Max Avatar/src/renderer/src/components/InputBar.tsx b/Max Avatar/src/renderer/src/components/InputBar.tsx new file mode 100644 index 0000000..fc79285 --- /dev/null +++ b/Max Avatar/src/renderer/src/components/InputBar.tsx @@ -0,0 +1,82 @@ +import { useState } from 'react' +import { Mic, Send } from 'lucide-react' + +export interface InputBarProps { + placeholder?: string + disabled?: boolean + onSend: (text: string) => void + onVoiceStart?: () => void + onVoiceStop?: () => void +} + +/** + * Barre de saisie du shell permanent (docs/Max_Composants_Frontend.md section 2). La + * reconnaissance vocale elle-meme vit dans le main process : ce composant se contente d'appeler + * onVoiceStart/onVoiceStop et de refleter l'etat "recording" qu'on lui donne en retour via le + * parent (pas de logique STT ici). + */ +export default function InputBar({ + placeholder, + disabled = false, + onSend, + onVoiceStart, + onVoiceStop +}: InputBarProps): React.JSX.Element { + const [text, setText] = useState('') + const [recording, setRecording] = useState(false) + + const send = (): void => { + const trimmed = text.trim() + if (trimmed.length === 0 || disabled) return + onSend(trimmed) + setText('') + } + + const onKeyDown = (event: React.KeyboardEvent): void => { + if (event.key === 'Enter' && !event.shiftKey) { + event.preventDefault() + send() + } + } + + const toggleVoice = (): void => { + if (recording) { + onVoiceStop?.() + } else { + onVoiceStart?.() + } + setRecording((prev) => !prev) + } + + return ( +
+ setText(e.target.value)} + onKeyDown={onKeyDown} + placeholder={placeholder} + disabled={disabled} + aria-label="Message" + /> + + +
+ ) +} diff --git a/Max Avatar/src/renderer/src/components/ObjectiveValidationCard.tsx b/Max Avatar/src/renderer/src/components/ObjectiveValidationCard.tsx new file mode 100644 index 0000000..eb155ae --- /dev/null +++ b/Max Avatar/src/renderer/src/components/ObjectiveValidationCard.tsx @@ -0,0 +1,136 @@ +import { useState } from 'react' +import { Check, Pencil, Target } from 'lucide-react' + +export interface ObjectiveData { + subject: string + professionalGoal: string + duration: string +} + +export interface ObjectiveValidationCardProps { + objective: ObjectiveData + onConfirm: (objective: ObjectiveData) => Promise + onRestart: () => void +} + +type FieldKey = keyof ObjectiveData + +const FIELD_LABELS: { key: FieldKey; label: string }[] = [ + { key: 'subject', label: 'Sujet' }, + { key: 'professionalGoal', label: 'But professionnel' }, + { key: 'duration', label: 'Duree' } +] + +/** + * Carte de validation de l'objectif issu de l'Agent 1 (docs/Max_Composants_Frontend.md section + * 4). Une seule ligne editable a la fois ; une fois confirmee, l'objectif est verrouille pour le + * reste de la session (etat `confirmed` irreversible). + */ +export default function ObjectiveValidationCard({ + objective, + onConfirm, + onRestart +}: ObjectiveValidationCardProps): React.JSX.Element { + const [draft, setDraft] = useState(objective) + const [editingField, setEditingField] = useState(null) + const [confirmed, setConfirmed] = useState(false) + const [confirming, setConfirming] = useState(false) + + const updateField = (key: FieldKey, value: string): void => { + if (key === 'subject') setDraft((prev) => ({ ...prev, subject: value })) + else if (key === 'professionalGoal') setDraft((prev) => ({ ...prev, professionalGoal: value })) + else setDraft((prev) => ({ ...prev, duration: value })) + } + + const startEditing = (key: FieldKey): void => { + if (confirmed) return + setEditingField(key) + } + + const closeEditing = (): void => { + setEditingField(null) + } + + const confirm = (): void => { + if (editingField !== null) return + setConfirming(true) + void onConfirm(draft).then(() => { + setConfirming(false) + setConfirmed(true) + }) + } + + return ( +
+
+
+ +
+ {FIELD_LABELS.map(({ key, label }) => { + const value: string = Reflect.get(draft, key) + return ( +
+ {label} + {editingField === key ? ( + updateField(key, e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') closeEditing() + }} + onBlur={closeEditing} + /> + ) : ( + {value} + )} + {!confirmed && ( + + )} +
+ ) + })} + + {confirmed ? ( +

+

+ ) : ( +
+ + +
+ )} +
+
+ ) +} diff --git a/Max Avatar/src/renderer/src/components/PipelineStepper.tsx b/Max Avatar/src/renderer/src/components/PipelineStepper.tsx new file mode 100644 index 0000000..7ebdd13 --- /dev/null +++ b/Max Avatar/src/renderer/src/components/PipelineStepper.tsx @@ -0,0 +1,36 @@ +export type StepStatus = 'done' | 'active' | 'pending' + +export interface PipelineStep { + id: number + label: string + subLabel?: string + status: StepStatus +} + +export interface PipelineStepperProps { + steps: PipelineStep[] +} + +/** + * Liste verticale des 7 etapes du pipeline (docs/Max_Composants_Frontend.md section 4). Purement + * affichage : le statut de chaque etape vient du store Zustand qui lit session.status depuis + * l'API (voir src/renderer/src/stores/useSessionStore.ts et utils/pipelineSteps.ts) - ce composant + * ne calcule jamais lui-meme un statut, il se contente de rendre les props telles quelles. + */ +export default function PipelineStepper({ steps }: PipelineStepperProps): React.JSX.Element { + return ( +
    + {steps.map((step) => ( +
  1. + {step.status === 'done' ? '✓' : step.id} + + {step.label} + {step.status === 'active' && step.subLabel && ( + {step.subLabel} + )} + +
  2. + ))} +
+ ) +} diff --git a/Max Avatar/src/renderer/src/styles/app.css b/Max Avatar/src/renderer/src/styles/app.css index f64d0e1..8ba9137 100644 --- a/Max Avatar/src/renderer/src/styles/app.css +++ b/Max Avatar/src/renderer/src/styles/app.css @@ -52,6 +52,53 @@ } } +/* ── Badge d'etat sous l'avatar ── */ + +.avatar-status { + display: flex; + align-items: center; + gap: var(--space-2); + padding: 3px var(--space-3); + border-radius: var(--radius-full); + background: var(--surface); + border: 1px solid var(--border); +} + +.avatar-status__label { + font-family: var(--font-sans); + font-size: var(--text-xs); + color: var(--text-2); +} + +.avatar-status__dots { + display: flex; + gap: 3px; +} + +.avatar-status__dot { + width: 5px; + height: 5px; + border-radius: 50%; + background: var(--accent); + animation: avatar-status-pulse 1s infinite ease-in-out; +} + +.avatar-status__dot--waiting { + background: var(--green); + animation: none; +} + +@keyframes avatar-status-pulse { + 0%, + 80%, + 100% { + opacity: 0.3; + } + 40% { + opacity: 1; + } +} + /* ── Bannieres flottantes (erreur, mise a jour) ── */ .banner { @@ -208,3 +255,94 @@ cursor: not-allowed; opacity: 1; } + +/* ── Carte de validation de l'objectif (Agent 1) ── */ + +.objective-card__header { + display: flex; + align-items: center; + gap: var(--space-2); + color: var(--accent); +} + +.objective-card__row { + display: flex; + align-items: center; + gap: var(--space-2); + padding: var(--space-2) 0; + border-bottom: 1px solid var(--border); +} + +.objective-card__row-label { + width: 120px; + flex-shrink: 0; + font-size: var(--text-xs); + color: var(--text-2); +} + +.objective-card__row-value { + flex: 1; + font-size: var(--text-base); + color: var(--text-1); +} + +.objective-card__edit-btn { + flex-shrink: 0; + width: 24px; + height: 24px; + border: none; + background: none; + color: var(--text-2); + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; +} + +.objective-card__edit-btn:hover:not(:disabled) { + color: var(--accent); +} + +.objective-card__edit-btn:disabled { + color: var(--text-3); + cursor: not-allowed; +} + +.objective-card__actions { + display: flex; + flex-direction: column; + gap: var(--space-2); + margin-top: var(--space-4); +} + +.objective-card__restart { + background: none; + border: none; + color: var(--text-2); + font-family: var(--font-sans); + font-size: var(--text-sm); + cursor: pointer; + padding: var(--space-1); +} + +.objective-card__restart:hover:not(:disabled) { + color: var(--text-1); +} + +.objective-card__confirmed { + display: flex; + align-items: center; + gap: var(--space-2); + margin-top: var(--space-4); + color: var(--green); + font-size: var(--text-sm); +} + +@media (prefers-reduced-motion: reduce) { + .thinking__dot, + .avatar-status__dot, + .input-bar__btn--recording, + .live-dot { + animation: none; + } +} diff --git a/Max Avatar/src/renderer/src/styles/components.css b/Max Avatar/src/renderer/src/styles/components.css index 2e3656d..ab2dcbf 100644 --- a/Max Avatar/src/renderer/src/styles/components.css +++ b/Max Avatar/src/renderer/src/styles/components.css @@ -29,6 +29,29 @@ align-self: flex-end; } +.chat-bubble p { + margin: 0; +} + +.chat-bubble p + p { + margin-top: var(--space-2); +} + +.chat-bubble code { + font-family: var(--font-mono); + font-size: var(--text-sm); + background: var(--surface-2); + padding: 1px 4px; + border-radius: var(--radius-sm); +} + +.chat-bubble__time { + display: block; + margin-top: var(--space-1); + font-size: var(--text-xs); + color: var(--text-2); +} + /* ── Module panel — panneau de cours ── */ .module-panel { @@ -115,6 +138,25 @@ /* ── Pipeline stepper — progression session ── */ +.pipeline-stepper { + display: flex; + flex-direction: column; + gap: var(--space-1); + list-style: none; + margin: 0; + padding: 0; +} + +.step__texts { + display: flex; + flex-direction: column; +} + +.step__sublabel { + font-size: var(--text-xs); + color: var(--text-2); +} + .step { display: flex; align-items: center; @@ -228,6 +270,12 @@ color: var(--text-1); } +.input-bar__btn--recording { + color: var(--red); + border-color: var(--red); + animation: blink 1.2s ease-in-out infinite; +} + .input-bar__send { width: 28px; height: 28px; diff --git a/Max Avatar/src/renderer/src/utils/pipelineSteps.ts b/Max Avatar/src/renderer/src/utils/pipelineSteps.ts new file mode 100644 index 0000000..6b4a419 --- /dev/null +++ b/Max Avatar/src/renderer/src/utils/pipelineSteps.ts @@ -0,0 +1,35 @@ +import type { SessionStatus } from '../../../shared/session' +import type { PipelineStep } from '../components/PipelineStepper' + +const STEP_LABELS: { status: SessionStatus; label: string }[] = [ + { status: 'objective_discovery', label: 'Objectif' }, + { status: 'mapping', label: 'Cartographie' }, + { status: 'level_assessment', label: 'Niveau' }, + { status: 'researching', label: 'Recherche approfondie' }, + { status: 'planning', label: 'Plan de formation' }, + { status: 'teaching', label: 'Modules' }, + { status: 'evaluating', label: 'Evaluation finale' } +] + +/** + * Derive les 7 etapes du PipelineStepper a partir du session.status reellement renvoye par + * l'API - jamais depuis un calcul fait par le composant lui-meme (voir PipelineStepper.tsx). + * objective_validated est traite comme "Objectif termine" (l'etape 2 n'a pas encore commence). + */ +export function deriveStepsFromStatus(status: SessionStatus | null): PipelineStep[] { + const effectiveIndex = status === null ? -1 : indexForStatus(status) + + return STEP_LABELS.map((step, index) => { + if (effectiveIndex === -1) return { id: index + 1, label: step.label, status: 'pending' } + if (index < effectiveIndex) return { id: index + 1, label: step.label, status: 'done' } + if (index === effectiveIndex) return { id: index + 1, label: step.label, status: 'active' } + return { id: index + 1, label: step.label, status: 'pending' } + }) +} + +function indexForStatus(status: SessionStatus): number { + if (status === 'objective_validated') return 1 + if (status === 'completed') return STEP_LABELS.length + const index = STEP_LABELS.findIndex((step) => step.status === status) + return index === -1 ? 0 : index +} diff --git a/Max Avatar/tests/unit/components/AvatarStatusIndicator.test.tsx b/Max Avatar/tests/unit/components/AvatarStatusIndicator.test.tsx new file mode 100644 index 0000000..108b871 --- /dev/null +++ b/Max Avatar/tests/unit/components/AvatarStatusIndicator.test.tsx @@ -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('', () => { + it('should render nothing when idle', () => { + const { container } = render() + expect(container).toBeEmptyDOMElement() + }) + + it('should show the default label for thinking', () => { + render() + expect(screen.getByText('Max reflechit...')).toBeInTheDocument() + }) + + it('should show the default label for speaking', () => { + render() + expect(screen.getByText('Max parle...')).toBeInTheDocument() + }) + + it('should show a fixed green dot and "En attente" for waiting', () => { + const { container } = render() + 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() + expect(screen.getByText('Max recherche des sources...')).toBeInTheDocument() + }) +}) diff --git a/Max Avatar/tests/unit/components/ChatBubble.test.tsx b/Max Avatar/tests/unit/components/ChatBubble.test.tsx new file mode 100644 index 0000000..f30547a --- /dev/null +++ b/Max Avatar/tests/unit/components/ChatBubble.test.tsx @@ -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('', () => { + it('should render a Max message with the max variant class', () => { + const { container } = render() + 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() + expect(container.querySelector('.chat-bubble--user')).toBeInTheDocument() + }) + + it('should render simple markdown (bold, code)', () => { + const { container } = render() + expect(container.querySelector('strong')?.textContent).toBe('gras') + expect(container.querySelector('code')?.textContent).toBe('code') + }) + + it('should display the timestamp when provided', () => { + render() + expect(screen.getByText('10:30')).toBeInTheDocument() + }) + + it('should not render a time element when no timestamp is given', () => { + const { container } = render() + expect(container.querySelector('time')).not.toBeInTheDocument() + }) +}) diff --git a/Max Avatar/tests/unit/components/InputBar.test.tsx b/Max Avatar/tests/unit/components/InputBar.test.tsx new file mode 100644 index 0000000..b26cca6 --- /dev/null +++ b/Max Avatar/tests/unit/components/InputBar.test.tsx @@ -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('', () => { + it('should send the trimmed text and clear the field on Enter', () => { + const onSend = vi.fn() + render() + + const input = screen.getByLabelText('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() + + 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() + + 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() + + 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() + + 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() + }) +}) diff --git a/Max Avatar/tests/unit/components/ObjectiveValidationCard.test.tsx b/Max Avatar/tests/unit/components/ObjectiveValidationCard.test.tsx new file mode 100644 index 0000000..9519bd2 --- /dev/null +++ b/Max Avatar/tests/unit/components/ObjectiveValidationCard.test.tsx @@ -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('', () => { + it('should display the 3 pillars', () => { + render( + + ) + 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( + + ) + + fireEvent.click(screen.getByRole('button', { name: 'Modifier Sujet' })) + const input = screen.getByLabelText('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( + + ) + + 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( + + ) + + 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( + + ) + + 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( + + ) + + fireEvent.click(screen.getByRole('button', { name: 'Recommencer depuis le debut' })) + expect(onRestart).toHaveBeenCalledOnce() + }) +}) diff --git a/Max Avatar/tests/unit/components/PipelineStepper.test.tsx b/Max Avatar/tests/unit/components/PipelineStepper.test.tsx new file mode 100644 index 0000000..23a7a76 --- /dev/null +++ b/Max Avatar/tests/unit/components/PipelineStepper.test.tsx @@ -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('', () => { + it('should render each step with its own status class, unchanged from props', () => { + const { container } = render( + + ) + + 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( + + ) + + 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() + expect(screen.getByText('✓')).toBeInTheDocument() + }) +}) diff --git a/Max Avatar/tests/unit/components/pipelineSteps.test.ts b/Max Avatar/tests/unit/components/pipelineSteps.test.ts new file mode 100644 index 0000000..bf9886f --- /dev/null +++ b/Max Avatar/tests/unit/components/pipelineSteps.test.ts @@ -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') + }) +})