Files
ForgeBase/Max Avatar/tests/unit/components/App.test.tsx
T
william 83043b5819 chore(cleanup): remove assistant-exclusive skills
Removes the meeting transcription/recording feature end-to-end
(get_last_meeting_summary, meetingRecorder/meetingStore/summarize, the
useMeetingRecorder renderer hook, and the related IPC/preload wiring) and
the remember_info/forget_info long-term memory skills: all three were only
ever reachable from the now-removed Assistant mode. adjust_mood and its
mood store are unrelated (transversal) and are kept as-is.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 19:27:11 +01:00

168 lines
6.0 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen, act, fireEvent, waitFor } from '@testing-library/react'
import type { VoiceState } from '../../../src/renderer/src/voice/useVoiceAssistant'
vi.mock('../../../src/renderer/src/components/AvatarViewer', () => ({
default: ({ onReady }: { onReady: (handle: unknown) => void }) => {
onReady({ playAnimation: vi.fn(), playAnimationByName: vi.fn(), animationNames: [] })
return <div data-testid="avatar-viewer" />
}
}))
let capturedOnStateChange: ((state: VoiceState) => void) | undefined
let capturedOnError: ((message: string) => void) | undefined
const useVoiceAssistant = vi.fn(
(
_ref: unknown,
_enabled: boolean,
onStateChange?: (state: VoiceState) => void,
onError?: (message: string) => void
) => {
capturedOnStateChange = onStateChange
capturedOnError = onError
}
)
vi.mock('../../../src/renderer/src/voice/useVoiceAssistant', () => ({ useVoiceAssistant }))
vi.mock('../../../src/renderer/src/voice/useProactiveSpeech', () => ({
useProactiveSpeech: vi.fn()
}))
let onUpdateAvailableCb: (() => void) | undefined
let onUpdateReadyCb: (() => void) | undefined
const sendDroppedFiles = vi.fn()
const getPathForFile = vi.fn(() => 'C:\\fichier.txt')
const showContextMenu = vi.fn()
const getWindowBounds = vi.fn(async () => ({ x: 0, y: 0, width: 100, height: 100 }))
const setWindowPosition = vi.fn()
const getAuthStatus = vi.fn(async (): Promise<{ loggedIn: boolean; email: string | null }> => ({
loggedIn: false,
email: null
}))
function setupWindowApi(): void {
;(window as unknown as { api: Record<string, unknown> }).api = {
onUpdateAvailable: vi.fn((cb: () => void) => {
onUpdateAvailableCb = cb
return () => {}
}),
onUpdateReady: vi.fn((cb: () => void) => {
onUpdateReadyCb = cb
return () => {}
}),
onToggleListening: vi.fn(() => () => {}),
onProactiveSpeech: vi.fn(() => () => {}),
getPathForFile,
sendDroppedFiles,
showContextMenu,
getWindowBounds,
setWindowPosition,
getAuthStatus
}
}
const { default: App } = await import('../../../src/renderer/src/App')
describe('<App />', () => {
beforeEach(() => {
vi.clearAllMocks()
setupWindowApi()
})
it('should render the avatar viewer', () => {
render(<App />)
expect(screen.getByTestId('avatar-viewer')).toBeInTheDocument()
})
it('should show the thinking indicator while processing', () => {
render(<App />)
act(() => capturedOnStateChange?.('processing'))
expect(screen.getByText('Max reflechit...')).toBeInTheDocument()
})
it('should show a voice error banner and clear it when a new state arrives', () => {
vi.useFakeTimers()
render(<App />)
act(() => capturedOnError?.('Erreur reseau'))
expect(screen.getByText(/Erreur reseau/)).toBeInTheDocument()
act(() => {
vi.advanceTimersByTime(5000)
})
expect(screen.queryByText(/Erreur reseau/)).not.toBeInTheDocument()
vi.useRealTimers()
})
it('should hide the error banner once recording starts again', () => {
render(<App />)
act(() => capturedOnError?.('Erreur reseau'))
expect(screen.getByText(/Erreur reseau/)).toBeInTheDocument()
act(() => capturedOnStateChange?.('recording'))
expect(screen.queryByText(/Erreur reseau/)).not.toBeInTheDocument()
})
it('should display the update banner when an update is available, then ready', () => {
render(<App />)
act(() => onUpdateAvailableCb?.())
expect(screen.getByText(/telechargement en cours/)).toBeInTheDocument()
act(() => onUpdateReadyCb?.())
expect(screen.getByText(/prochaine fermeture/)).toBeInTheDocument()
})
it('should forward dropped files to the main process', () => {
render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.drop(container, { dataTransfer: { files: [{ name: 'a.txt' }] } })
expect(getPathForFile).toHaveBeenCalled()
expect(sendDroppedFiles).toHaveBeenCalledWith(['C:\\fichier.txt'])
})
it('should not call sendDroppedFiles when nothing is dropped', () => {
render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.drop(container, { dataTransfer: { files: [] } })
expect(sendDroppedFiles).not.toHaveBeenCalled()
})
it('should request the context menu with the current listening state', () => {
// Faux par defaut (ecoute non activee tant qu'aucun compte n'est connecte, voir
// getAuthStatus ci-dessus qui renvoie loggedIn: false).
render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.contextMenu(container)
expect(showContextMenu).toHaveBeenCalledWith(false)
})
it('should enable listening once getAuthStatus reports an existing session', async () => {
getAuthStatus.mockResolvedValueOnce({ loggedIn: true, email: 'william@example.com' })
render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement!
await waitFor(() => {
fireEvent.contextMenu(container)
expect(showContextMenu).toHaveBeenCalledWith(true)
})
})
it('should start dragging the window on mouse down and stop on mouse up', async () => {
render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.mouseDown(container, { button: 0, screenX: 10, screenY: 10 })
await waitFor(() => expect(getWindowBounds).toHaveBeenCalled())
fireEvent.mouseMove(window, { screenX: 20, screenY: 15 })
expect(setWindowPosition).toHaveBeenCalled()
fireEvent.mouseUp(window)
setWindowPosition.mockClear()
fireEvent.mouseMove(window, { screenX: 50, screenY: 50 })
expect(setWindowPosition).not.toHaveBeenCalled()
})
it('should ignore a non-primary mouse button for dragging', async () => {
render(<App />)
const container = screen.getByTestId('avatar-viewer').parentElement!
fireEvent.mouseDown(container, { button: 2 })
await new Promise((resolve) => setTimeout(resolve, 10))
expect(getWindowBounds).not.toHaveBeenCalled()
})
})