Files
ForgeBase/Max Avatar/tests/unit/components/SessionPanel.test.tsx
T
williamandClaude Sonnet 5 919b82ef37 feat(pipeline): wire SessionPanel into App once logged in
SessionPanel composes PipelineStepper (status derived via
deriveStepsFromStatus), the ChatBubble conversation, the
ObjectiveValidationCard (shown once Agent 1 is ready to confirm) and
InputBar, all driven by useSessionStore. It's anchored to the bottom
of the avatar window (420x720) like the existing voice/update banners,
shown only once App.tsx confirms the user is actually logged in
(re-checked via getAuthStatus on every toggle-listening event, since
listening can be turned off manually without logging out).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 22:05:41 +01:00

64 lines
2.7 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import SessionPanel from '../../../src/renderer/src/components/SessionPanel'
import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore'
const create = vi.fn()
const get = vi.fn()
const sendObjectiveMessage = vi.fn()
const confirmObjective = vi.fn()
beforeEach(() => {
vi.clearAllMocks()
;(window as unknown as { api: Record<string, unknown> }).api = {
sessions: { create, get, sendObjectiveMessage, confirmObjective }
}
useSessionStore.getState().restart()
})
describe('<SessionPanel />', () => {
it('should show the pending pipeline steps and an input bar before any session exists', () => {
render(<SessionPanel />)
expect(screen.getByLabelText('Message')).toBeInTheDocument()
expect(screen.getByText('Objectif')).toBeInTheDocument()
})
it('should send the first message, creating a session, and render the conversation', async () => {
create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
sendObjectiveMessage.mockResolvedValueOnce({ reply: 'Quel est ton sujet ?', ready: false })
render(<SessionPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'Je veux apprendre' } })
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
expect(await screen.findByText('Je veux apprendre')).toBeInTheDocument()
expect(await screen.findByText('Quel est ton sujet ?')).toBeInTheDocument()
})
it('should show the ObjectiveValidationCard instead of the input bar once the agent is ready', async () => {
create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
sendObjectiveMessage.mockResolvedValueOnce({
reply: 'Voici le recap',
ready: true,
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
})
render(<SessionPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
await waitFor(() => expect(screen.getByText('Ton objectif de formation')).toBeInTheDocument())
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
})
it('should show the store error message when a call fails', async () => {
create.mockRejectedValueOnce(new Error('Max API injoignable'))
render(<SessionPanel />)
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
expect(await screen.findByText('Max API injoignable')).toBeInTheDocument()
})
})