mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Executes recommendations from a comprehensive test suite audit. Removes dead, redundant, and trivial tests; rewrites SessionDetail polling test to exercise real gating; trims duplicated assertions; adds missing assertion in assistant-loading tests. 13 files changed, 233 insertions(+), 462 deletions(-)
258 lines
7.7 KiB
TypeScript
258 lines
7.7 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { MemoryRouter, Route, Routes } from 'react-router-dom'
|
|
import { useSessionTodos } from '@/stores/sessionTodosStore'
|
|
import type { Todo } from '@/components/message/SessionTodoDisplay'
|
|
import { SessionDetail } from '../SessionDetail'
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
useSession: vi.fn(),
|
|
useMessages: vi.fn(),
|
|
useSSE: vi.fn(),
|
|
useRepoActivity: vi.fn(),
|
|
usePermissions: vi.fn(),
|
|
useQuestions: vi.fn(),
|
|
useSSEHealth: vi.fn(),
|
|
useConfig: vi.fn(),
|
|
useOpenCodeClient: vi.fn(),
|
|
useSettings: vi.fn(),
|
|
useSettingsDialog: vi.fn(),
|
|
useMobile: vi.fn(),
|
|
useVisualViewport: vi.fn(),
|
|
useKeyboardShortcuts: vi.fn(),
|
|
useAutoScroll: vi.fn(),
|
|
useDialogParam: vi.fn(),
|
|
useSidebarAction: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useOpenCode', () => ({
|
|
useSession: mocks.useSession,
|
|
useAbortSession: vi.fn(() => ({ mutate: vi.fn() })),
|
|
useUpdateSession: vi.fn(() => ({ mutate: vi.fn() })),
|
|
useCreateSession: vi.fn(() => ({ mutateAsync: vi.fn() })),
|
|
useMessages: mocks.useMessages,
|
|
useConfig: mocks.useConfig,
|
|
}))
|
|
|
|
vi.mock('@/hooks/useModelSelection', () => ({
|
|
useModelSelection: vi.fn(() => ({ model: null, modelString: null })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useOpenCodeClient', () => ({
|
|
useOpenCodeClient: mocks.useOpenCodeClient,
|
|
}))
|
|
|
|
vi.mock('@/hooks/useTTS', () => ({
|
|
useTTS: vi.fn(() => ({ isEnabled: false })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSettings', () => ({
|
|
useSettings: vi.fn(() => ({
|
|
preferences: { expandToolCalls: false },
|
|
updateSettings: vi.fn(),
|
|
})),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSettingsDialog', () => ({
|
|
useSettingsDialog: vi.fn(() => ({ open: vi.fn() })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useMobile', () => ({
|
|
useMobile: vi.fn(() => false),
|
|
useSwipeBack: vi.fn(() => ({ ref: vi.fn() })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useVisualViewport', () => ({
|
|
useVisualViewport: vi.fn(() => ({ keyboardHeight: 0 })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useKeyboardShortcuts', () => ({
|
|
useKeyboardShortcuts: vi.fn(() => ({ leaderActive: false })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useAutoScroll', () => ({
|
|
useAutoScroll: vi.fn(() => ({ scrollToBottom: vi.fn() })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useDialogParam', () => ({
|
|
useDialogParam: vi.fn(() => [false, vi.fn()]),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSidebarAction', () => ({
|
|
useSidebarAction: vi.fn(() => {}),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
|
|
getAssistantText: vi.fn(() => ''),
|
|
getLatestPlayableAssistantMessage: vi.fn(() => null),
|
|
useAutoPlayLastResponse: vi.fn(() => {}),
|
|
}))
|
|
|
|
vi.mock('@/stores/uiStateStore', () => ({
|
|
useUIState: vi.fn(() => vi.fn()),
|
|
}))
|
|
|
|
vi.mock('@/stores/sessionStatusStore', () => ({
|
|
useSessionStatus: vi.fn(() => ({ setStatus: vi.fn() })),
|
|
useSessionStatusForSession: vi.fn(() => ({ type: 'idle' })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSSE', () => ({
|
|
useSSE: mocks.useSSE,
|
|
}))
|
|
|
|
vi.mock('@/hooks/useRepoActivity', () => ({
|
|
useRepoActivity: mocks.useRepoActivity,
|
|
}))
|
|
|
|
vi.mock('@/contexts/EventContext', async (importOriginal) => {
|
|
const actual = await importOriginal()
|
|
return {
|
|
...(actual as object),
|
|
usePermissions: mocks.usePermissions,
|
|
useQuestions: mocks.useQuestions,
|
|
useSSEHealth: mocks.useSSEHealth,
|
|
}
|
|
})
|
|
|
|
vi.mock('@/api/repos', () => ({
|
|
getRepo: vi.fn(() => Promise.resolve({
|
|
id: 1,
|
|
repoUrl: 'https://github.com/test/repo',
|
|
localPath: '/test/repo',
|
|
sourcePath: null,
|
|
fullPath: '/test/repo',
|
|
branch: 'main',
|
|
currentBranch: 'main',
|
|
fullSlug: 'test/repo',
|
|
repoType: 'github' as const,
|
|
})),
|
|
initializeAssistantMode: vi.fn(() => Promise.resolve({ directory: '/test/repo' })),
|
|
}))
|
|
|
|
vi.mock('@/components/model/ModelSelectDialog', () => ({
|
|
ModelSelectDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/session/SessionList', () => ({
|
|
SessionList: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/file-browser/FileBrowserSheet', () => ({
|
|
FileBrowserSheet: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/RepoMcpDialog', () => ({
|
|
RepoMcpDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/ResetPermissionsDialog', () => ({
|
|
ResetPermissionsDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/RepoLspDialog', () => ({
|
|
RepoLspDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/RepoSkillsDialog', () => ({
|
|
RepoSkillsDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/source-control', () => ({
|
|
SourceControlPanel: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/session/QuestionPrompt', () => ({
|
|
QuestionPrompt: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/session/MinimizedQuestionIndicator', () => ({
|
|
MinimizedQuestionIndicator: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/notifications/PendingActionsGroup', () => ({
|
|
PendingActionsGroup: vi.fn(() => null),
|
|
}))
|
|
|
|
const activeTodos: Todo[] = [
|
|
{ id: '1', content: 'Implement mobile header fix', status: 'in_progress', priority: 'high' },
|
|
{ id: '2', content: 'Add regression tests', status: 'pending', priority: 'medium' },
|
|
{ id: '3', content: 'Verify completed item grouping', status: 'completed', priority: 'low' },
|
|
]
|
|
|
|
describe('SessionDetail todo-header integration', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
useSessionTodos.setState({ todos: new Map() })
|
|
|
|
mocks.useSession.mockReturnValue({ data: undefined, isLoading: false })
|
|
mocks.useMessages.mockReturnValue({ data: [], isLoading: false })
|
|
mocks.useSSE.mockReturnValue({ isConnected: true, isReconnecting: false })
|
|
mocks.useRepoActivity.mockReturnValue(undefined)
|
|
mocks.usePermissions.mockReturnValue({
|
|
pendingCount: 0,
|
|
hasPermissionsForSession: vi.fn(() => false),
|
|
syncForSession: vi.fn(),
|
|
})
|
|
mocks.useQuestions.mockReturnValue({
|
|
current: null,
|
|
pendingCount: 0,
|
|
hasQuestionsForSession: vi.fn(() => false),
|
|
reply: vi.fn(),
|
|
reject: vi.fn(),
|
|
syncForSession: vi.fn(),
|
|
})
|
|
mocks.useSSEHealth.mockReturnValue({ isHealthy: true })
|
|
mocks.useConfig.mockReturnValue({ data: undefined, isLoading: false })
|
|
mocks.useOpenCodeClient.mockReturnValue({})
|
|
mocks.useSettings.mockReturnValue({
|
|
preferences: { expandToolCalls: false },
|
|
updateSettings: vi.fn(),
|
|
})
|
|
mocks.useSettingsDialog.mockReturnValue({ open: vi.fn() })
|
|
mocks.useMobile.mockReturnValue(false)
|
|
mocks.useVisualViewport.mockReturnValue({ keyboardHeight: 0 })
|
|
mocks.useKeyboardShortcuts.mockReturnValue({ leaderActive: false })
|
|
mocks.useAutoScroll.mockReturnValue({ scrollToBottom: vi.fn() })
|
|
mocks.useDialogParam.mockReturnValue([false, vi.fn()])
|
|
mocks.useSidebarAction.mockReturnValue(undefined)
|
|
})
|
|
|
|
const createQueryClient = () =>
|
|
new QueryClient({
|
|
defaultOptions: {
|
|
queries: { retry: false },
|
|
},
|
|
})
|
|
|
|
const renderSessionDetail = (sessionId: string, repoId: number) => {
|
|
return render(
|
|
<MemoryRouter initialEntries={[`/repos/${repoId}/sessions/${sessionId}`]}>
|
|
<QueryClientProvider client={createQueryClient()}>
|
|
<Routes>
|
|
<Route path="/repos/:id/sessions/:sessionId" element={<SessionDetail />} />
|
|
</Routes>
|
|
</QueryClientProvider>
|
|
</MemoryRouter>
|
|
)
|
|
}
|
|
|
|
it('header wrapper uses max-h-72 sm:max-h-80 and overflow-hidden for proper containment', async () => {
|
|
useSessionTodos.getState().setTodos('session-1', activeTodos)
|
|
|
|
renderSessionDetail('session-1', 1)
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('session-header-region')).toBeInTheDocument()
|
|
})
|
|
|
|
const headerRegion = screen.getByTestId('session-header-region')
|
|
|
|
expect(headerRegion.className).toContain('max-h-72')
|
|
expect(headerRegion.className).toContain('sm:max-h-80')
|
|
expect(headerRegion.className).toContain('overflow-hidden')
|
|
expect(headerRegion.className).not.toContain('max-h-40')
|
|
})
|
|
})
|