Per user feedback after visually testing the app: the chat and the pipeline stepper were a single combined panel, which the user wanted split. Rename SessionPanel to ChatPanel (chat history + objective validation + input bar only, no stepper), rendered only while a new chatOpen flag is true - toggled via the context menu's "Ecrire un message" item, not shown automatically on login. The PipelineStepper now lives directly in App.tsx and only mounts once useSessionStore.sessionId is set (i.e. the user has actually started a training session, not just logged in). It's anchored to the right edge of the window, vertically centered, instead of stacked above the avatar: the window itself grows from 420 to 620px wide via the new set-pipeline-panel-visible IPC call whenever a session becomes active, and shrinks back when it doesn't. A new .avatar-stage wrapper keeps the avatar/chat panel's own layout anchored to a fixed 420px column so it doesn't re-center across the wider window. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
64 lines
2.7 KiB
TypeScript
64 lines
2.7 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
|
import ChatPanel from '../../../src/renderer/src/components/ChatPanel'
|
|
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('<ChatPanel />', () => {
|
|
it('should show an input bar and no pipeline steps before any session exists', () => {
|
|
render(<ChatPanel />)
|
|
expect(screen.getByLabelText('Message')).toBeInTheDocument()
|
|
expect(screen.queryByText('Objectif')).not.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(<ChatPanel />)
|
|
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(<ChatPanel />)
|
|
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(<ChatPanel />)
|
|
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()
|
|
})
|
|
})
|