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,40 @@
|
|||||||
|
export type AvatarStatus = 'idle' | 'thinking' | 'speaking' | 'waiting'
|
||||||
|
|
||||||
|
export interface AvatarStatusIndicatorProps {
|
||||||
|
status: AvatarStatus
|
||||||
|
label?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_LABELS = new Map<AvatarStatus, string>([
|
||||||
|
['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 (
|
||||||
|
<div className="avatar-status" role="status">
|
||||||
|
{status === 'waiting' ? (
|
||||||
|
<span className="avatar-status__dot avatar-status__dot--waiting" />
|
||||||
|
) : (
|
||||||
|
<span className="avatar-status__dots">
|
||||||
|
<span className="avatar-status__dot" style={{ animationDelay: '0s' }} />
|
||||||
|
<span className="avatar-status__dot" style={{ animationDelay: '0.2s' }} />
|
||||||
|
<span className="avatar-status__dot" style={{ animationDelay: '0.4s' }} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<span className="avatar-status__label">{text}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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 (
|
||||||
|
<div className={`chat-bubble chat-bubble--${role}`}>
|
||||||
|
<ReactMarkdown remarkPlugins={[remarkGfm]}>{content}</ReactMarkdown>
|
||||||
|
{timestamp && (
|
||||||
|
<time className="chat-bubble__time" dateTime={timestamp.toISOString()}>
|
||||||
|
{timestamp.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' })}
|
||||||
|
</time>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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<HTMLInputElement>): void => {
|
||||||
|
if (event.key === 'Enter' && !event.shiftKey) {
|
||||||
|
event.preventDefault()
|
||||||
|
send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleVoice = (): void => {
|
||||||
|
if (recording) {
|
||||||
|
onVoiceStop?.()
|
||||||
|
} else {
|
||||||
|
onVoiceStart?.()
|
||||||
|
}
|
||||||
|
setRecording((prev) => !prev)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="input-bar">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={text}
|
||||||
|
onChange={(e) => setText(e.target.value)}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
|
placeholder={placeholder}
|
||||||
|
disabled={disabled}
|
||||||
|
aria-label="Message"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`input-bar__btn${recording ? ' input-bar__btn--recording' : ''}`}
|
||||||
|
aria-label={recording ? "Arreter l'enregistrement vocal" : 'Activer le microphone'}
|
||||||
|
onClick={toggleVoice}
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
<Mic size={14} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="input-bar__send"
|
||||||
|
aria-label="Envoyer le message"
|
||||||
|
onClick={send}
|
||||||
|
disabled={disabled || text.trim().length === 0}
|
||||||
|
>
|
||||||
|
<Send size={14} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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<void>
|
||||||
|
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<ObjectiveData>(objective)
|
||||||
|
const [editingField, setEditingField] = useState<FieldKey | null>(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 (
|
||||||
|
<div className="module-panel objective-card">
|
||||||
|
<div className="module-panel__header objective-card__header">
|
||||||
|
<Target size={16} aria-hidden="true" />
|
||||||
|
<span className="module-panel__title">Ton objectif de formation</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="module-panel__body">
|
||||||
|
{FIELD_LABELS.map(({ key, label }) => {
|
||||||
|
const value: string = Reflect.get(draft, key)
|
||||||
|
return (
|
||||||
|
<div key={key} className="objective-card__row">
|
||||||
|
<span className="objective-card__row-label">{label}</span>
|
||||||
|
{editingField === key ? (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="auth-field__input"
|
||||||
|
value={value}
|
||||||
|
aria-label={label}
|
||||||
|
autoFocus
|
||||||
|
onChange={(e) => updateField(key, e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === 'Enter') closeEditing()
|
||||||
|
}}
|
||||||
|
onBlur={closeEditing}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="objective-card__row-value">{value}</span>
|
||||||
|
)}
|
||||||
|
{!confirmed && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="objective-card__edit-btn"
|
||||||
|
aria-label={editingField === key ? `Valider ${label}` : `Modifier ${label}`}
|
||||||
|
onClick={() => (editingField === key ? closeEditing() : startEditing(key))}
|
||||||
|
disabled={editingField === key && value.trim().length === 0}
|
||||||
|
>
|
||||||
|
{editingField === key ? <Check size={14} /> : <Pencil size={14} />}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
|
||||||
|
{confirmed ? (
|
||||||
|
<p className="objective-card__confirmed">
|
||||||
|
<Check size={14} aria-hidden="true" /> Objectif enregistre — Max passe a la cartographie
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="objective-card__actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="auth-panel__submit"
|
||||||
|
aria-label="C'est exactement ca, confirmer l'objectif"
|
||||||
|
onClick={confirm}
|
||||||
|
disabled={editingField !== null || confirming}
|
||||||
|
>
|
||||||
|
{confirming ? 'Confirmation...' : "C'est exactement ca ✓"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="objective-card__restart"
|
||||||
|
aria-label="Recommencer depuis le debut"
|
||||||
|
onClick={onRestart}
|
||||||
|
disabled={confirming}
|
||||||
|
>
|
||||||
|
Recommencer depuis le debut
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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 (
|
||||||
|
<ol className="pipeline-stepper">
|
||||||
|
{steps.map((step) => (
|
||||||
|
<li key={step.id} className={`step step--${step.status}`}>
|
||||||
|
<span className="step__num">{step.status === 'done' ? '✓' : step.id}</span>
|
||||||
|
<span className="step__texts">
|
||||||
|
<span className="step__label">{step.label}</span>
|
||||||
|
{step.status === 'active' && step.subLabel && (
|
||||||
|
<span className="step__sublabel">{step.subLabel}</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ol>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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) ── */
|
/* ── Bannieres flottantes (erreur, mise a jour) ── */
|
||||||
|
|
||||||
.banner {
|
.banner {
|
||||||
@@ -208,3 +255,94 @@
|
|||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
opacity: 1;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,6 +29,29 @@
|
|||||||
align-self: flex-end;
|
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 — panneau de cours ── */
|
||||||
|
|
||||||
.module-panel {
|
.module-panel {
|
||||||
@@ -115,6 +138,25 @@
|
|||||||
|
|
||||||
/* ── Pipeline stepper — progression session ── */
|
/* ── 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 {
|
.step {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -228,6 +270,12 @@
|
|||||||
color: var(--text-1);
|
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 {
|
.input-bar__send {
|
||||||
width: 28px;
|
width: 28px;
|
||||||
height: 28px;
|
height: 28px;
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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