Develop #2

Open
w-vandal wants to merge 48 commits from develop into main
5 changed files with 272 additions and 64 deletions
Showing only changes of commit 6e8a9d2f0d - Show all commits
+73 -10
View File
@@ -1,10 +1,14 @@
import { useCallback, useEffect, useRef, useState } from 'react' import { useCallback, useEffect, useRef, useState } from 'react'
import AvatarViewer, { type AvatarHandle } from './components/AvatarViewer' import AvatarViewer, { type AvatarHandle } from './components/AvatarViewer'
import AvatarStatusIndicator from './components/AvatarStatusIndicator' import AvatarStatusIndicator from './components/AvatarStatusIndicator'
import ChatPanel from './components/ChatPanel'
import ContextMenu from './components/ContextMenu'
import PipelineStepper from './components/PipelineStepper'
import ThinkingIndicator from './components/ThinkingIndicator' import ThinkingIndicator from './components/ThinkingIndicator'
import VoiceErrorBanner from './components/VoiceErrorBanner' import VoiceErrorBanner from './components/VoiceErrorBanner'
import UpdateBanner from './components/UpdateBanner' import UpdateBanner from './components/UpdateBanner'
import SessionPanel from './components/SessionPanel' import { useSessionStore } from './stores/useSessionStore'
import { deriveStepsFromStatus } from './utils/pipelineSteps'
import { useVoiceAssistant, type VoiceState } from './voice/useVoiceAssistant' import { useVoiceAssistant, type VoiceState } from './voice/useVoiceAssistant'
import { useProactiveSpeech } from './voice/useProactiveSpeech' import { useProactiveSpeech } from './voice/useProactiveSpeech'
@@ -15,9 +19,15 @@ function App(): React.JSX.Element {
const [listening, setListening] = useState(false) const [listening, setListening] = useState(false)
const listeningRef = useRef(listening) const listeningRef = useRef(listening)
const [loggedIn, setLoggedIn] = useState(false) const [loggedIn, setLoggedIn] = useState(false)
const [email, setEmail] = useState<string | null>(null)
const [chatOpen, setChatOpen] = useState(false)
const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null)
const [voiceState, setVoiceState] = useState<VoiceState>('idle') const [voiceState, setVoiceState] = useState<VoiceState>('idle')
const [voiceError, setVoiceError] = useState<string | null>(null) const [voiceError, setVoiceError] = useState<string | null>(null)
const [updateStatus, setUpdateStatus] = useState<'available' | 'ready' | null>(null) const [updateStatus, setUpdateStatus] = useState<'available' | 'ready' | null>(null)
const sessionId = useSessionStore((state) => state.sessionId)
const sessionStatus = useSessionStore((state) => state.status)
const restartSession = useSessionStore((state) => state.restart)
useEffect(() => window.api.onUpdateAvailable(() => setUpdateStatus('available')), []) useEffect(() => window.api.onUpdateAvailable(() => setUpdateStatus('available')), [])
useEffect(() => window.api.onUpdateReady(() => setUpdateStatus('ready')), []) useEffect(() => window.api.onUpdateReady(() => setUpdateStatus('ready')), [])
const voiceErrorTimer = useRef<ReturnType<typeof setTimeout> | null>(null) const voiceErrorTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
@@ -47,10 +57,12 @@ function App(): React.JSX.Element {
.then((status) => { .then((status) => {
setListening(status.loggedIn) setListening(status.loggedIn)
setLoggedIn(status.loggedIn) setLoggedIn(status.loggedIn)
setEmail(status.email)
}) })
.catch(() => { .catch(() => {
setListening(false) setListening(false)
setLoggedIn(false) setLoggedIn(false)
setEmail(null)
}) })
}, []) }, [])
useEffect(refreshAuthStatus, [refreshAuthStatus]) useEffect(refreshAuthStatus, [refreshAuthStatus])
@@ -60,10 +72,38 @@ function App(): React.JSX.Element {
useEffect(() => window.api.onToggleListening(refreshAuthStatus), [refreshAuthStatus]) useEffect(() => window.api.onToggleListening(refreshAuthStatus), [refreshAuthStatus])
useEffect(() => window.api.onProactiveSpeech(() => setVoiceState('speaking')), []) useEffect(() => window.api.onProactiveSpeech(() => setVoiceState('speaking')), [])
// Le stepper n'apparait que lorsqu'une session existe reellement (l'utilisateur a mentionne
// vouloir apprendre quelque chose, pas juste parce qu'il est connecte) : voir useSessionStore,
// sessionId n'est jamais non-null avant le premier POST /sessions reussi. La fenetre s'elargit a
// droite pour lui faire de la place (set-pipeline-panel-visible, voir src/main/index.ts).
useEffect(() => {
window.api.setPipelinePanelVisible(sessionId !== null)
}, [sessionId])
// Ouvre automatiquement le panneau de chat des qu'une session demarre (garde-fou : en usage
// normal, c'est l'ouverture du chat via le menu contextuel qui permet d'envoyer le premier
// message qui cree la session, donc le chat est deja ouvert a ce moment-la).
const previousSessionId = useRef<number | null>(null)
useEffect(() => {
if (previousSessionId.current === null && sessionId !== null) setChatOpen(true)
previousSessionId.current = sessionId
}, [sessionId])
const onContextMenu = useCallback((event: React.MouseEvent) => { const onContextMenu = useCallback((event: React.MouseEvent) => {
event.preventDefault() event.preventDefault()
window.api.showContextMenu(listeningRef.current) setContextMenu({ x: event.clientX, y: event.clientY })
}, []) }, [])
const closeContextMenu = useCallback(() => setContextMenu(null), [])
const handleLogin = useCallback(() => window.api.openLoginWindow(), [])
const handleLogout = useCallback(() => {
window.api.logout()
setChatOpen(false)
restartSession()
}, [restartSession])
const handleToggleListening = useCallback(() => setListening((prev) => !prev), [])
const handleToggleChat = useCallback(() => setChatOpen((prev) => !prev), [])
const handleQuit = useCallback(() => window.api.quitApp(), [])
const dragState = useRef<{ const dragState = useRef<{
startMouseX: number startMouseX: number
startMouseY: number startMouseY: number
@@ -125,12 +165,12 @@ function App(): React.JSX.Element {
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
onContextMenu={onContextMenu} onContextMenu={onContextMenu}
> >
<AvatarViewer onReady={handleReady} /> <div className="avatar-stage">
{voiceState === 'processing' && <ThinkingIndicator />} <AvatarViewer onReady={handleReady} />
{voiceError && voiceState !== 'processing' && <VoiceErrorBanner message={voiceError} />} {voiceState === 'processing' && <ThinkingIndicator />}
{updateStatus && <UpdateBanner status={updateStatus} />} {voiceError && voiceState !== 'processing' && <VoiceErrorBanner message={voiceError} />}
{loggedIn && ( {updateStatus && <UpdateBanner status={updateStatus} />}
<> {loggedIn && (
<div className="avatar-status-anchor"> <div className="avatar-status-anchor">
<AvatarStatusIndicator <AvatarStatusIndicator
status={ status={
@@ -142,8 +182,31 @@ function App(): React.JSX.Element {
} }
/> />
</div> </div>
<SessionPanel /> )}
</> {loggedIn && chatOpen && <ChatPanel />}
</div>
{sessionId !== null && (
<div className="pipeline-stepper-anchor">
<PipelineStepper steps={deriveStepsFromStatus(sessionStatus)} />
</div>
)}
{contextMenu && (
<ContextMenu
x={contextMenu.x}
y={contextMenu.y}
loggedIn={loggedIn}
email={email}
listening={listening}
chatOpen={chatOpen}
onClose={closeContextMenu}
onLogin={handleLogin}
onLogout={handleLogout}
onToggleListening={handleToggleListening}
onToggleChat={handleToggleChat}
onQuit={handleQuit}
/>
)} )}
</div> </div>
) )
@@ -1,19 +1,17 @@
import { useEffect, useRef } from 'react' import { useEffect, useRef } from 'react'
import { useSessionStore } from '../stores/useSessionStore' import { useSessionStore } from '../stores/useSessionStore'
import { deriveStepsFromStatus } from '../utils/pipelineSteps'
import ChatBubble from './ChatBubble' import ChatBubble from './ChatBubble'
import InputBar from './InputBar' import InputBar from './InputBar'
import ObjectiveValidationCard from './ObjectiveValidationCard' import ObjectiveValidationCard from './ObjectiveValidationCard'
import PipelineStepper from './PipelineStepper'
/** /**
* Panneau flottant de la session de formation (docs/Max_Composants_Frontend.md section 4) : * Panneau de conversation (docs/Max_Composants_Frontend.md section 4) : historique de messages +
* stepper + conversation + carte de validation de l'objectif + barre de saisie. N'affiche jamais * carte de validation de l'objectif + barre de saisie. Separe du PipelineStepper (rendu a cote de
* un statut calcule localement (voir utils/pipelineSteps.ts et la regle de PipelineStepper). * l'avatar par App.tsx, pas ici) - voir le retour utilisateur qui demandait cette separation.
* N'affiche jamais un statut calcule localement.
*/ */
export default function SessionPanel(): React.JSX.Element { export default function ChatPanel(): React.JSX.Element {
const { const {
status,
messages, messages,
objectiveDraft, objectiveDraft,
objectiveReady, objectiveReady,
@@ -33,16 +31,11 @@ export default function SessionPanel(): React.JSX.Element {
} }
}, [messages]) }, [messages])
const steps = deriveStepsFromStatus(status)
const showObjectiveCard = objectiveReady && objectiveDraft !== null && !objectiveConfirmed const showObjectiveCard = objectiveReady && objectiveDraft !== null && !objectiveConfirmed
return ( return (
<div className="session-panel"> <div className="chat-panel">
<div className="session-panel__stepper"> <div className="chat-panel__messages" ref={chatRef}>
<PipelineStepper steps={steps} />
</div>
<div className="session-panel__chat" ref={chatRef}>
{messages.map((message) => ( {messages.map((message) => (
<ChatBubble <ChatBubble
key={message.id} key={message.id}
@@ -53,7 +46,7 @@ export default function SessionPanel(): React.JSX.Element {
))} ))}
</div> </div>
{error && <p className="session-panel__error">{error}</p>} {error && <p className="chat-panel__error">{error}</p>}
{showObjectiveCard && objectiveDraft ? ( {showObjectiveCard && objectiveDraft ? (
<ObjectiveValidationCard <ObjectiveValidationCard
+89 -15
View File
@@ -338,11 +338,22 @@
font-size: var(--text-sm); font-size: var(--text-sm);
} }
/* ── Panneau de session (stepper + chat + saisie) ── /* ── Scene avatar (colonne fixe 420px) ──
Ancre en bas de la fenetre avatar (420x720, voir src/main/index.ts) pour laisser la partie Isole l'avatar 3D et tout ce qui lui est ancre (bannieres, badge de statut, panneau de
haute/centrale libre pour l'avatar 3D, comme les bannieres existantes. A valider visuellement conversation) dans une colonne de largeur fixe, independante de la largeur reelle de la fenetre
une fois l'app lancee : la hauteur de la conversation est bornee (max-height) pour ne jamais (voir src/main/index.ts : la fenetre s'elargit a droite pour loger le PipelineStepper quand une
recouvrir tout l'avatar sur un echange long. */ session est active). Sans cette colonne, un panneau ancre en "left: 50%" se recentrerait sur
toute la fenetre elargie et chevaucherait le stepper. */
.avatar-stage {
position: relative;
width: 420px;
height: 100%;
}
/* ── Panneau de conversation (chat + saisie) ──
Ancre en bas de la colonne avatar, comme les bannieres existantes. La hauteur est bornee
(max-height) pour ne jamais recouvrir tout l'avatar sur un echange long. */
.avatar-status-anchor { .avatar-status-anchor {
position: absolute; position: absolute;
@@ -352,7 +363,7 @@
pointer-events: none; pointer-events: none;
} }
.session-panel { .chat-panel {
position: absolute; position: absolute;
left: 50%; left: 50%;
bottom: 2%; bottom: 2%;
@@ -369,16 +380,10 @@
box-shadow: var(--shadow-panel); box-shadow: var(--shadow-panel);
} }
.session-panel__stepper { .chat-panel__messages {
flex-shrink: 0;
max-height: 140px;
overflow-y: auto;
}
.session-panel__chat {
flex: 1; flex: 1;
min-height: 60px; min-height: 60px;
max-height: 260px; max-height: 320px;
overflow-y: auto; overflow-y: auto;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -387,12 +392,81 @@
scrollbar-color: var(--surface-2) transparent; scrollbar-color: var(--surface-2) transparent;
} }
.session-panel__error { .chat-panel__error {
margin: 0; margin: 0;
font-size: var(--text-sm); font-size: var(--text-sm);
color: var(--red); color: var(--red);
} }
/* ── Stepper du pipeline — a cote de l'avatar, pas au-dessus ──
Ancre sur le bord droit de la FENETRE (pas de la colonne avatar), dans l'espace supplementaire
que main/index.ts ouvre en elargissant la fenetre (set-pipeline-panel-visible) des qu'une
session existe reellement (voir useSessionStore : jamais affiche juste parce que l'utilisateur
est connecte). A valider visuellement une fois l'app lancee. */
.pipeline-stepper-anchor {
position: absolute;
top: 50%;
right: var(--space-3);
transform: translateY(-50%);
width: 160px;
}
/* ── Menu contextuel ──
Rendu cote renderer pour pouvoir etre stylise avec le design system (un menu natif Electron ne
peut pas l'etre). Positionne en JS (ContextMenu.tsx) au clic droit. */
.context-menu {
position: absolute;
z-index: 10;
min-width: 180px;
padding: var(--space-2) 0;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-md);
box-shadow: var(--shadow-panel);
}
.context-menu__item {
display: flex;
align-items: center;
gap: var(--space-2);
width: 100%;
padding: var(--space-2) var(--space-3);
border: none;
background: none;
font-family: var(--font-sans);
font-size: var(--text-sm);
color: var(--text-1);
text-align: left;
cursor: pointer;
}
.context-menu__item:hover:not(:disabled) {
background: var(--surface-2);
}
.context-menu__item:disabled {
color: var(--text-3);
cursor: not-allowed;
}
.context-menu__item--disabled {
color: var(--text-2);
cursor: default;
}
.context-menu__check {
margin-left: auto;
color: var(--accent);
}
.context-menu__separator {
height: 1px;
margin: var(--space-1) 0;
background: var(--border);
}
@media (prefers-reduced-motion: reduce) { @media (prefers-reduced-motion: reduce) {
.thinking__dot, .thinking__dot,
.avatar-status__dot, .avatar-status__dot,
+94 -16
View File
@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, act, fireEvent, waitFor } from '@testing-library/react' import { render, screen, act, fireEvent, waitFor } from '@testing-library/react'
import type { VoiceState } from '../../../src/renderer/src/voice/useVoiceAssistant' import type { VoiceState } from '../../../src/renderer/src/voice/useVoiceAssistant'
import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore'
vi.mock('../../../src/renderer/src/components/AvatarViewer', () => ({ vi.mock('../../../src/renderer/src/components/AvatarViewer', () => ({
default: ({ onReady }: { onReady: (handle: unknown) => void }) => { default: ({ onReady }: { onReady: (handle: unknown) => void }) => {
@@ -29,9 +30,14 @@ vi.mock('../../../src/renderer/src/voice/useProactiveSpeech', () => ({
let onUpdateAvailableCb: (() => void) | undefined let onUpdateAvailableCb: (() => void) | undefined
let onUpdateReadyCb: (() => void) | undefined let onUpdateReadyCb: (() => void) | undefined
const showContextMenu = vi.fn()
const getWindowBounds = vi.fn(async () => ({ x: 0, y: 0, width: 100, height: 100 })) const getWindowBounds = vi.fn(async () => ({ x: 0, y: 0, width: 100, height: 100 }))
const setWindowPosition = vi.fn() const setWindowPosition = vi.fn()
const openLoginWindow = vi.fn()
const logout = vi.fn()
const quitApp = vi.fn()
const setPipelinePanelVisible = vi.fn()
const sessionsCreate = vi.fn()
const sessionsSendObjectiveMessage = vi.fn()
const getAuthStatus = vi.fn(async (): Promise<{ loggedIn: boolean; email: string | null }> => ({ const getAuthStatus = vi.fn(async (): Promise<{ loggedIn: boolean; email: string | null }> => ({
loggedIn: false, loggedIn: false,
email: null email: null
@@ -49,10 +55,19 @@ function setupWindowApi(): void {
}), }),
onToggleListening: vi.fn(() => () => {}), onToggleListening: vi.fn(() => () => {}),
onProactiveSpeech: vi.fn(() => () => {}), onProactiveSpeech: vi.fn(() => () => {}),
showContextMenu,
getWindowBounds, getWindowBounds,
setWindowPosition, setWindowPosition,
getAuthStatus getAuthStatus,
openLoginWindow,
logout,
quitApp,
setPipelinePanelVisible,
sessions: {
create: sessionsCreate,
get: vi.fn(),
sendObjectiveMessage: sessionsSendObjectiveMessage,
confirmObjective: vi.fn()
}
} }
} }
@@ -62,6 +77,7 @@ describe('<App />', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
setupWindowApi() setupWindowApi()
useSessionStore.getState().restart()
}) })
it('should render the avatar viewer', () => { it('should render the avatar viewer', () => {
@@ -103,24 +119,37 @@ describe('<App />', () => {
expect(screen.getByText(/prochaine fermeture/)).toBeInTheDocument() expect(screen.getByText(/prochaine fermeture/)).toBeInTheDocument()
}) })
it('should request the context menu with the current listening state', () => { it('should open the custom context menu on right-click', () => {
// Faux par defaut (ecoute non activee tant qu'aucun compte n'est connecte, voir render(<App />)
// getAuthStatus ci-dessus qui renvoie loggedIn: false). const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.contextMenu(container, { clientX: 20, clientY: 30 })
expect(screen.getByRole('menu')).toBeInTheDocument()
})
it('should call openLoginWindow when "Me connecter" is clicked from the menu', () => {
render(<App />) render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement! const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.contextMenu(container) fireEvent.contextMenu(container)
expect(showContextMenu).toHaveBeenCalledWith(false) fireEvent.click(screen.getByRole('menuitem', { name: 'Me connecter' }))
expect(openLoginWindow).toHaveBeenCalled()
}) })
it('should enable listening once getAuthStatus reports an existing session', async () => { it('should call logout and reset the session when "Se deconnecter" is clicked', async () => {
getAuthStatus.mockResolvedValueOnce({ loggedIn: true, email: 'william@example.com' }) getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
render(<App />)
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.contextMenu(container)
fireEvent.click(screen.getByRole('menuitem', { name: 'Se deconnecter' }))
expect(logout).toHaveBeenCalled()
})
it('should call quitApp when "Quitter" is clicked', () => {
render(<App />) render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement! const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.contextMenu(container)
await waitFor(() => { fireEvent.click(screen.getByRole('menuitem', { name: 'Quitter' }))
fireEvent.contextMenu(container) expect(quitApp).toHaveBeenCalled()
expect(showContextMenu).toHaveBeenCalledWith(true)
})
}) })
it('should start dragging the window on mouse down and stop on mouse up', async () => { it('should start dragging the window on mouse down and stop on mouse up', async () => {
@@ -146,15 +175,64 @@ describe('<App />', () => {
expect(getWindowBounds).not.toHaveBeenCalled() expect(getWindowBounds).not.toHaveBeenCalled()
}) })
it('should not show the session panel when logged out', async () => { it('should not show the chat panel when logged out', async () => {
render(<App />) render(<App />)
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled()) await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument() expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
}) })
it('should show the session panel input once logged in', async () => { it('should not show the chat panel right after login, until "Ecrire un message" is used', async () => {
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' }) getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
render(<App />) render(<App />)
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
})
it('should open the chat panel via the context menu and shrink the pipeline panel back on toggle off', async () => {
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
render(<App />)
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.contextMenu(container)
fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' }))
expect(await screen.findByLabelText('Message')).toBeInTheDocument() expect(await screen.findByLabelText('Message')).toBeInTheDocument()
fireEvent.contextMenu(container)
fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' }))
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
})
it('should not show the pipeline stepper before a session exists', async () => {
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
render(<App />)
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
expect(screen.queryByText('Objectif')).not.toBeInTheDocument()
expect(setPipelinePanelVisible).toHaveBeenCalledWith(false)
})
it('should show the pipeline stepper and widen the window once a session is created', async () => {
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
sessionsCreate.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
sessionsSendObjectiveMessage.mockResolvedValueOnce({
reply: 'Quel est ton sujet ?',
ready: false
})
render(<App />)
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.contextMenu(container)
fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' }))
fireEvent.change(await screen.findByLabelText('Message'), {
target: { value: 'Je veux apprendre' }
})
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
await waitFor(() => expect(screen.getByText('Objectif')).toBeInTheDocument())
expect(setPipelinePanelVisible).toHaveBeenCalledWith(true)
}) })
}) })
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react' import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import SessionPanel from '../../../src/renderer/src/components/SessionPanel' import ChatPanel from '../../../src/renderer/src/components/ChatPanel'
import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore' import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore'
const create = vi.fn() const create = vi.fn()
@@ -16,18 +16,18 @@ beforeEach(() => {
useSessionStore.getState().restart() useSessionStore.getState().restart()
}) })
describe('<SessionPanel />', () => { describe('<ChatPanel />', () => {
it('should show the pending pipeline steps and an input bar before any session exists', () => { it('should show an input bar and no pipeline steps before any session exists', () => {
render(<SessionPanel />) render(<ChatPanel />)
expect(screen.getByLabelText('Message')).toBeInTheDocument() expect(screen.getByLabelText('Message')).toBeInTheDocument()
expect(screen.getByText('Objectif')).toBeInTheDocument() expect(screen.queryByText('Objectif')).not.toBeInTheDocument()
}) })
it('should send the first message, creating a session, and render the conversation', async () => { it('should send the first message, creating a session, and render the conversation', async () => {
create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' }) create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
sendObjectiveMessage.mockResolvedValueOnce({ reply: 'Quel est ton sujet ?', ready: false }) sendObjectiveMessage.mockResolvedValueOnce({ reply: 'Quel est ton sujet ?', ready: false })
render(<SessionPanel />) render(<ChatPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'Je veux apprendre' } }) fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'Je veux apprendre' } })
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' })) fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
@@ -43,7 +43,7 @@ describe('<SessionPanel />', () => {
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' } draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
}) })
render(<SessionPanel />) render(<ChatPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } }) fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' })) fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
@@ -54,7 +54,7 @@ describe('<SessionPanel />', () => {
it('should show the store error message when a call fails', async () => { it('should show the store error message when a call fails', async () => {
create.mockRejectedValueOnce(new Error('Max API injoignable')) create.mockRejectedValueOnce(new Error('Max API injoignable'))
render(<SessionPanel />) render(<ChatPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } }) fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' })) fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))