Files
ForgeBase/Max Avatar/tests/unit/components/ChatPanel.test.tsx
T
williamandClaude Sonnet 5 c1440f83c0 feat(windows): route chat/stepper content to their own windows, fix status badge position
- ChatPanel now fills its own window instead of being absolutely
  positioned over the avatar; its interactive regions (messages,
  input bar, objective card) opt out of the window's drag region so
  they stay clickable/selectable while the rest of the panel can be
  used to move the window.
- New StepperView: the #stepper window's root component, relays
  "session-status-changed" from the main process into its own
  Zustand store instance (new setStatus action) since this window has
  no direct access to the chat window's state.
- App.tsx no longer renders ChatPanel/PipelineStepper at all (they
  live in separate windows now) or resizes itself - it only toggles
  the chat window via IPC and keeps a local optimistic flag for the
  context menu's checkmark, resynced if the window is closed
  externally.
- Fixed AvatarStatusIndicator's position: .avatar-status-anchor used
  to be computed from the in-window chat panel's height
  (bottom: calc(2% + 64vh + ...)), which misplaced it once that panel
  stopped living in this window. It now mirrors .thinking's simple
  fixed anchor above the avatar's head.

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

66 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()
const notifySessionEnded = vi.fn()
beforeEach(() => {
vi.clearAllMocks()
;(window as unknown as { api: Record<string, unknown> }).api = {
sessions: { create, get, sendObjectiveMessage, 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 () => {
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()
})
})