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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
4da3254d0a
commit
c1440f83c0
@@ -35,7 +35,9 @@ const setWindowPosition = vi.fn()
|
||||
const openLoginWindow = vi.fn()
|
||||
const logout = vi.fn()
|
||||
const quitApp = vi.fn()
|
||||
const setPipelinePanelVisible = vi.fn()
|
||||
const toggleChatWindow = vi.fn()
|
||||
const notifySessionEnded = vi.fn()
|
||||
let onChatWindowClosedCb: (() => void) | undefined
|
||||
const sessionsCreate = vi.fn()
|
||||
const sessionsSendObjectiveMessage = vi.fn()
|
||||
const getAuthStatus = vi.fn(async (): Promise<{ loggedIn: boolean; email: string | null }> => ({
|
||||
@@ -55,13 +57,19 @@ function setupWindowApi(): void {
|
||||
}),
|
||||
onToggleListening: vi.fn(() => () => {}),
|
||||
onProactiveSpeech: vi.fn(() => () => {}),
|
||||
onChatWindowClosed: vi.fn((cb: () => void) => {
|
||||
onChatWindowClosedCb = cb
|
||||
return () => {}
|
||||
}),
|
||||
onSessionStatusChanged: vi.fn(() => () => {}),
|
||||
getWindowBounds,
|
||||
setWindowPosition,
|
||||
getAuthStatus,
|
||||
openLoginWindow,
|
||||
logout,
|
||||
quitApp,
|
||||
setPipelinePanelVisible,
|
||||
toggleChatWindow,
|
||||
notifySessionEnded,
|
||||
sessions: {
|
||||
create: sessionsCreate,
|
||||
get: vi.fn(),
|
||||
@@ -175,20 +183,16 @@ describe('<App />', () => {
|
||||
expect(getWindowBounds).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should not show the chat panel when logged out', async () => {
|
||||
it('should disable the "Ecrire un message" menu item when logged out', async () => {
|
||||
getAuthStatus.mockResolvedValue({ loggedIn: false, email: null })
|
||||
render(<App />)
|
||||
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
|
||||
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
|
||||
const container = screen.getByTestId('avatar-viewer').parentElement!
|
||||
fireEvent.contextMenu(container)
|
||||
expect(screen.getByRole('menuitem', { name: 'Ecrire un message' })).toBeDisabled()
|
||||
})
|
||||
|
||||
it('should not show the chat panel right after login, until "Ecrire un message" is used', async () => {
|
||||
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
|
||||
render(<App />)
|
||||
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
|
||||
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should open the chat panel via the context menu and shrink the pipeline panel back on toggle off', async () => {
|
||||
it('should toggle the separate chat window via the context menu (chat is its own Electron window, not rendered here)', async () => {
|
||||
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
|
||||
render(<App />)
|
||||
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
|
||||
@@ -196,43 +200,47 @@ describe('<App />', () => {
|
||||
const container = screen.getByTestId('avatar-viewer').parentElement!
|
||||
fireEvent.contextMenu(container)
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' }))
|
||||
|
||||
expect(await screen.findByLabelText('Message')).toBeInTheDocument()
|
||||
expect(toggleChatWindow).toHaveBeenCalledOnce()
|
||||
|
||||
fireEvent.contextMenu(container)
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' }))
|
||||
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
|
||||
const menuItem = screen.getByRole('menuitem', { name: 'Ecrire un message' })
|
||||
expect(menuItem.querySelector('.context-menu__check')).not.toBeNull()
|
||||
fireEvent.click(menuItem)
|
||||
expect(toggleChatWindow).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('should not show the pipeline stepper before a session exists', async () => {
|
||||
it('should resync the menu when the chat window is closed externally (e.g. Alt+F4)', async () => {
|
||||
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
|
||||
render(<App />)
|
||||
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
|
||||
expect(onChatWindowClosedCb).toBeTypeOf('function')
|
||||
|
||||
const container = screen.getByTestId('avatar-viewer').parentElement!
|
||||
fireEvent.contextMenu(container)
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' }))
|
||||
|
||||
act(() => onChatWindowClosedCb?.())
|
||||
|
||||
fireEvent.contextMenu(container)
|
||||
const menuItem = screen.getByRole('menuitem', { name: 'Ecrire un message' })
|
||||
expect(menuItem.querySelector('.context-menu__check')).toBeNull()
|
||||
})
|
||||
|
||||
it('should not render the pipeline stepper or chat panel in this window (they live in their own windows)', async () => {
|
||||
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
|
||||
render(<App />)
|
||||
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
|
||||
expect(screen.queryByText('Objectif')).not.toBeInTheDocument()
|
||||
expect(setPipelinePanelVisible).toHaveBeenCalledWith(false)
|
||||
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the pipeline stepper and widen the window once a session is created', async () => {
|
||||
it('should open the chat window automatically if a session starts without it (safety net)', async () => {
|
||||
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
|
||||
sessionsCreate.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
sessionsSendObjectiveMessage.mockResolvedValueOnce({
|
||||
reply: 'Quel est ton sujet ?',
|
||||
ready: false
|
||||
})
|
||||
|
||||
render(<App />)
|
||||
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
|
||||
|
||||
const container = screen.getByTestId('avatar-viewer').parentElement!
|
||||
fireEvent.contextMenu(container)
|
||||
fireEvent.click(screen.getByRole('menuitem', { name: 'Ecrire un message' }))
|
||||
act(() => useSessionStore.setState({ sessionId: 1, status: 'objective_discovery' }))
|
||||
|
||||
fireEvent.change(await screen.findByLabelText('Message'), {
|
||||
target: { value: 'Je veux apprendre' }
|
||||
})
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
|
||||
|
||||
await waitFor(() => expect(screen.getByText('Objectif')).toBeInTheDocument())
|
||||
expect(setPipelinePanelVisible).toHaveBeenCalledWith(true)
|
||||
expect(toggleChatWindow).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,11 +7,13 @@ 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 }
|
||||
sessions: { create, get, sendObjectiveMessage, confirmObjective },
|
||||
notifySessionEnded
|
||||
}
|
||||
useSessionStore.getState().restart()
|
||||
})
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, act } from '@testing-library/react'
|
||||
import StepperView from '../../../src/renderer/src/components/StepperView'
|
||||
import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore'
|
||||
|
||||
let onSessionStatusChangedCb: ((status: string) => void) | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
onSessionStatusChangedCb = undefined
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
notifySessionEnded: vi.fn(),
|
||||
onSessionStatusChanged: vi.fn((cb: (status: string) => void) => {
|
||||
onSessionStatusChangedCb = cb
|
||||
return () => {}
|
||||
})
|
||||
}
|
||||
useSessionStore.getState().restart()
|
||||
})
|
||||
|
||||
describe('<StepperView />', () => {
|
||||
it('should render all 7 steps as pending when no status has been received yet', () => {
|
||||
render(<StepperView />)
|
||||
expect(screen.getByText('Objectif')).toBeInTheDocument()
|
||||
expect(screen.getByText('Evaluation finale')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should update the active step when the main process relays a new session status', () => {
|
||||
render(<StepperView />)
|
||||
|
||||
act(() => onSessionStatusChangedCb?.('objective_validated'))
|
||||
|
||||
const objectifStep = screen.getByText('Objectif').closest('li')
|
||||
expect(objectifStep).toHaveClass('step--done')
|
||||
const cartographieStep = screen.getByText('Cartographie').closest('li')
|
||||
expect(cartographieStep).toHaveClass('step--active')
|
||||
})
|
||||
})
|
||||
@@ -5,11 +5,13 @@ 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 }
|
||||
sessions: { create, get, sendObjectiveMessage, confirmObjective },
|
||||
notifySessionEnded
|
||||
}
|
||||
useSessionStore.getState().restart()
|
||||
})
|
||||
@@ -101,15 +103,22 @@ describe('useSessionStore', () => {
|
||||
expect(useSessionStore.getState().error).toBe('Aucune session en cours')
|
||||
})
|
||||
|
||||
it('should reset all state on restart', async () => {
|
||||
it('should reset all state on restart and notify the main process', async () => {
|
||||
create.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
sendObjectiveMessage.mockResolvedValueOnce({ reply: 'ok', ready: false })
|
||||
await useSessionStore.getState().sendMessage('message')
|
||||
|
||||
notifySessionEnded.mockClear()
|
||||
useSessionStore.getState().restart()
|
||||
|
||||
expect(notifySessionEnded).toHaveBeenCalledOnce()
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.sessionId).toBeNull()
|
||||
expect(state.messages).toEqual([])
|
||||
})
|
||||
|
||||
it('should set the status directly (used by the stepper window to sync with the main process)', () => {
|
||||
useSessionStore.getState().setStatus('objective_validated')
|
||||
expect(useSessionStore.getState().status).toBe('objective_validated')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user