Replace the chat window's unconditional create-session-then-send flow with a single call to the new POST /sessions/messages endpoint: a plain "salut ça va ?" no longer starts a fake training session, since the backend's intent router decides that now. Add sessions.routeMessage to the IPC/preload surface and the sessions HTTP client. useSessionStore.sendMessage only sets sessionId/status (fetched fresh via sessions:get) when the backend actually reports type: "learn". The stepper-window-open + status-broadcast trigger in main/index.ts moves from sessions:create's handler to sessions:route-message's, since session creation now happens inside the backend's routing logic rather than via an explicit prior call. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
72 lines
2.8 KiB
TypeScript
72 lines
2.8 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 get = vi.fn()
|
|
const routeMessage = vi.fn()
|
|
const confirmObjective = vi.fn()
|
|
const notifySessionEnded = vi.fn()
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
;(window as unknown as { api: Record<string, unknown> }).api = {
|
|
sessions: { get, routeMessage, confirmObjective },
|
|
notifySessionEnded
|
|
}
|
|
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 () => {
|
|
routeMessage.mockResolvedValueOnce({
|
|
type: 'learn',
|
|
sessionId: 1,
|
|
reply: 'Quel est ton sujet ?',
|
|
ready: false
|
|
})
|
|
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
|
|
|
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 () => {
|
|
routeMessage.mockResolvedValueOnce({
|
|
type: 'learn',
|
|
sessionId: 1,
|
|
reply: 'Voici le recap',
|
|
ready: true,
|
|
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
|
|
})
|
|
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
|
|
|
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 () => {
|
|
routeMessage.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()
|
|
})
|
|
})
|