A learn-intent conversation driven entirely by voice never reached ObjectiveValidationCard: the chat window's Zustand store lives in its own isolated renderer process and only ever updated from its own direct sessions:route-message calls, never from voice-turn results handled in the main process. A user doing everything by voice could never see or confirm their objective. The main process now opens the chat window and broadcasts the voice turn (reply/ready/draft) to it whenever intent is 'learn'; the chat window's store applies it the same way it applies its own responses. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
96 lines
3.7 KiB
TypeScript
96 lines
3.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 get = vi.fn()
|
|
const routeMessage = vi.fn()
|
|
const confirmObjective = vi.fn()
|
|
const notifySessionEnded = vi.fn()
|
|
const onVoiceTurnSynced = vi.fn(() => () => {})
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
;(window as unknown as { api: Record<string, unknown> }).api = {
|
|
sessions: { get, routeMessage, confirmObjective },
|
|
notifySessionEnded,
|
|
onVoiceTurnSynced
|
|
}
|
|
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 ObjectiveValidationCard from a voice-originated turn, not just a typed message', async () => {
|
|
let voiceTurnCallback: ((result: unknown) => void) | undefined
|
|
onVoiceTurnSynced.mockImplementationOnce((callback: (result: unknown) => void) => {
|
|
voiceTurnCallback = callback
|
|
return () => {}
|
|
})
|
|
|
|
render(<ChatPanel />)
|
|
expect(screen.queryByText('Ton objectif de formation')).not.toBeInTheDocument()
|
|
|
|
voiceTurnCallback?.({
|
|
type: 'learn',
|
|
sessionId: 1,
|
|
reply: 'Voici le recap (dit a voix haute)',
|
|
ready: true,
|
|
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
|
|
})
|
|
|
|
await waitFor(() => expect(screen.getByText('Ton objectif de formation')).toBeInTheDocument())
|
|
expect(screen.getByText('Voici le recap (dit a voix haute)')).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()
|
|
})
|
|
})
|