Remove the feature that let a user drop a .txt/.md/.csv/.docx/.pdf file onto the avatar to feed its text into the chat: the dropped-files IPC handler and extractText() in main, and getPathForFile/sendDroppedFiles in the preload API and renderer App.tsx. This fed documents into the general-purpose chat loop, which is being phased out in favor of the server-side coach pipeline. Uninstall mammoth and pdf-parse, now unused. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
149 lines
5.3 KiB
TypeScript
149 lines
5.3 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 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(() => () => {}),
|
|
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 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()
|
|
})
|
|
})
|