import { describe, it, expect, vi, beforeEach } from 'vitest' import { render, screen, fireEvent } from '@testing-library/react' import ChatPanel from '../../../src/renderer/src/components/ChatPanel' import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore' const sendTextTurn = vi.fn() const notifySessionEnded = vi.fn() beforeEach(() => { vi.clearAllMocks() ;(window as unknown as { api: Record }).api = { sendTextTurn, notifySessionEnded } useSessionStore.getState().restart() }) /** * Ce n'est PAS un chat (retour utilisateur direct) : juste une barre de saisie alternative au * micro. Le texte tape suit le meme pipeline qu'une phrase prononcee et Max repond toujours a * voix haute - aucune bulle, aucun historique de conversation affiche ici. */ describe('', () => { it('should show only the message input, no conversation history', () => { render() expect(screen.getByLabelText('Message')).toBeInTheDocument() expect(screen.queryByText('Ton objectif de formation')).not.toBeInTheDocument() }) it('should submit the typed text via text-turn and clear the field', async () => { sendTextTurn.mockResolvedValueOnce({ ok: true }) render() fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'Je veux apprendre la facturation' } }) fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' })) expect(sendTextTurn).toHaveBeenCalledWith('Je veux apprendre la facturation') expect(await screen.findByDisplayValue('')).toBeInTheDocument() }) it('should show the store error message when the backend reports a failure', async () => { sendTextTurn.mockResolvedValueOnce({ ok: false, error: 'Max API injoignable' }) render() 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() }) })