diff --git a/backend/test/bun-mock-test.test.ts b/backend/test/bun-mock-test.test.ts deleted file mode 100644 index 4494c031..00000000 --- a/backend/test/bun-mock-test.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { describe, it, expect, vi } from 'vitest' - -const mockFn = vi.hoisted(() => vi.fn().mockReturnValue('mocked')) - -describe('bun test vi.hoisted compatibility', () => { - it('supports vi.hoisted', () => { - expect(mockFn()).toBe('mocked') - }) -}) diff --git a/backend/test/db/queries.test.ts b/backend/test/db/queries.test.ts index a2817fb6..dd429b63 100644 --- a/backend/test/db/queries.test.ts +++ b/backend/test/db/queries.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, beforeEach, vi } from 'vitest' import * as db from '../../src/db/queries' -import * as schema from '../../src/db/schema' const mockDb = { prepare: vi.fn(), @@ -289,17 +288,4 @@ describe('Database Queries', () => { expect(mockDb.prepare).not.toHaveBeenCalled() }) }) - - describe('Database Schema', () => { - it('should have schema module available', () => { - expect(schema.initializeDatabase).toBeDefined() - expect(typeof schema.initializeDatabase).toBe('function') - }) - }) - - describe('Transaction Support', () => { - it('should support transaction existence', () => { - expect(typeof mockDb.transaction).toBe('function') - }) - }) }) diff --git a/backend/test/routes/sse.test.ts b/backend/test/routes/sse.test.ts deleted file mode 100644 index e24fb891..00000000 --- a/backend/test/routes/sse.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { describe, it, expect, vi } from 'vitest' -import { DEFAULTS } from '@opencode-manager/shared/config' - -const { HEARTBEAT_INTERVAL_MS } = DEFAULTS.SSE - -describe('SSE Routes', () => { - describe('HEARTBEAT_INTERVAL_MS', () => { - it('should be 30000ms (30 seconds)', () => { - expect(HEARTBEAT_INTERVAL_MS).toBe(30000) - }) - - it('should fire heartbeats at correct interval', async () => { - vi.useFakeTimers() - - const heartbeatSpy = vi.fn() - const intervalId = setInterval(() => { - heartbeatSpy() - }, HEARTBEAT_INTERVAL_MS) - - await vi.advanceTimersByTimeAsync(0) - expect(heartbeatSpy).toHaveBeenCalledTimes(0) - - await vi.advanceTimersByTimeAsync(30000) - expect(heartbeatSpy).toHaveBeenCalledTimes(1) - - await vi.advanceTimersByTimeAsync(30000) - expect(heartbeatSpy).toHaveBeenCalledTimes(2) - - clearInterval(intervalId) - vi.useRealTimers() - }) - - it('should fire two heartbeats within 70 seconds', async () => { - vi.useFakeTimers() - - const heartbeatSpy = vi.fn() - const intervalId = setInterval(() => { - heartbeatSpy() - }, HEARTBEAT_INTERVAL_MS) - - await vi.advanceTimersByTimeAsync(70000) - expect(heartbeatSpy).toHaveBeenCalledTimes(2) - - clearInterval(intervalId) - vi.useRealTimers() - }) - }) -}) diff --git a/backend/test/routes/stt.test.ts b/backend/test/routes/stt.test.ts index 8c6c31e9..f970d441 100644 --- a/backend/test/routes/stt.test.ts +++ b/backend/test/routes/stt.test.ts @@ -72,13 +72,6 @@ describe('STT Routes', () => { sttApp = createSTTRoutes(mockDb) }) - describe('createSTTRoutes', () => { - it('should create a Hono app with routes', () => { - expect(sttApp).toBeDefined() - expect(typeof sttApp.fetch).toBe('function') - }) - }) - describe('GET /status', () => { it('should return status with correct structure', async () => { const req = new Request('http://localhost/status?userId=test') diff --git a/frontend/src/components/ui/dialog.test.tsx b/frontend/src/components/ui/dialog.test.tsx index 7e1ec386..dad50a87 100644 --- a/frontend/src/components/ui/dialog.test.tsx +++ b/frontend/src/components/ui/dialog.test.tsx @@ -130,31 +130,6 @@ describe("DialogContent", () => { expect(screen.queryByRole("button", { name: /close/i })).not.toBeInTheDocument(); }); - it("merges custom className with default classes", () => { - render( - - - Content - - - ); - const content = screen.getByTestId("dialog-content"); - expect(content).toHaveClass("custom-class"); - expect(content).toHaveClass("fixed"); - expect(content).toHaveClass("z-[70]"); - }); - - it("renders children correctly", () => { - render( - - - Test Child Content - - - ); - expect(screen.getByText("Test Child Content")).toBeInTheDocument(); - }); - it("accepts mobileSwipeToClose prop without breaking rendering", () => { const onOpenChange = vi.fn(); render( diff --git a/frontend/src/components/ui/page-header.test.tsx b/frontend/src/components/ui/page-header.test.tsx index 2ba0ca64..30aef50d 100644 --- a/frontend/src/components/ui/page-header.test.tsx +++ b/frontend/src/components/ui/page-header.test.tsx @@ -3,19 +3,6 @@ import { render, screen } from "@testing-library/react"; import { PageHeader } from "./page-header"; describe("PageHeader", () => { - it("applies pt-safe class for iOS safe area", () => { - render(Content); - const header = screen.getByTestId("header"); - expect(header).toHaveClass("pt-safe"); - }); - - it("applies sticky top-0 positioning", () => { - render(Content); - const header = screen.getByTestId("header"); - expect(header).toHaveClass("sticky"); - expect(header).toHaveClass("top-0"); - }); - it("renders children correctly", () => { render( @@ -24,37 +11,4 @@ describe("PageHeader", () => { ); expect(screen.getByText("Test Child")).toBeInTheDocument(); }); - - it("merges custom className", () => { - render( - - Content - - ); - const header = screen.getByTestId("header"); - expect(header).toHaveClass("custom-class"); - expect(header).toHaveClass("pt-safe"); - }); - - it("forwards additional props", () => { - render( - - Content - - ); - const header = screen.getByTestId("header"); - expect(header).toHaveAttribute("aria-label", "Page header"); - }); - - it("applies z-10 for proper stacking", () => { - render(Content); - const header = screen.getByTestId("header"); - expect(header).toHaveClass("z-10"); - }); - - it("applies transparent background", () => { - render(Content); - const header = screen.getByTestId("header"); - expect(header).toHaveClass("bg-transparent"); - }); }); diff --git a/frontend/src/components/ui/side-drawer.test.tsx b/frontend/src/components/ui/side-drawer.test.tsx index 4fec2e74..8e56921a 100644 --- a/frontend/src/components/ui/side-drawer.test.tsx +++ b/frontend/src/components/ui/side-drawer.test.tsx @@ -48,46 +48,6 @@ describe('SideDrawer', () => { expect(handleClose).toHaveBeenCalled() }) - it('applies pt-safe and pb-safe classes', () => { - render( - {}} ariaLabel="Test drawer"> -
Test content
-
, - ) - const dialog = document.querySelector('[role="dialog"]') - expect(dialog).toHaveClass('pt-safe') - expect(dialog).toHaveClass('pb-safe') - }) - - it('defaults to right side', () => { - render( - {}} ariaLabel="Test drawer"> -
Test content
-
, - ) - const dialog = document.querySelector('[role="dialog"]') - expect(dialog).toHaveClass('right-0') - }) - - it('applies left side when specified', () => { - render( - {}} side="left" ariaLabel="Test drawer"> -
Test content
-
, - ) - const dialog = document.querySelector('[role="dialog"]') - expect(dialog).toHaveClass('left-0') - }) - - it('applies custom widthClass', () => { - render( - {}} widthClass="w-80" ariaLabel="Test drawer"> -
Test content
-
, - ) - const dialog = document.querySelector('[role="dialog"]') - expect(dialog).toHaveClass('w-80') - }) }) describe('SideDrawerHeader', () => { @@ -119,14 +79,4 @@ describe('SideDrawerContent', () => { ) expect(screen.getByText('Content')).toBeInTheDocument() }) - - it('applies custom className', () => { - render( - -
Content
-
, - ) - const content = screen.getByText('Content').parentElement - expect(content).toHaveClass('custom-class') - }) }) diff --git a/frontend/src/hooks/__tests__/useScheduleTarget.test.tsx b/frontend/src/hooks/__tests__/useScheduleTarget.test.tsx index 442a4549..95bc45e5 100644 --- a/frontend/src/hooks/__tests__/useScheduleTarget.test.tsx +++ b/frontend/src/hooks/__tests__/useScheduleTarget.test.tsx @@ -52,9 +52,6 @@ describe('useScheduleTarget', () => { }) expect(result.current.scheduleTarget?.kind).toBe('assistant') - expect(result.current.scheduleTarget?.fullPath).toBe('/abs/assistant') - expect(result.current.scheduleTarget?.repoId).toBe(0) - expect(result.current.scheduleTarget?.backHref).toBe('/assistant') expect(result.current.isLoading).toBe(false) expect(result.current.isError).toBe(false) }) @@ -98,9 +95,6 @@ describe('useScheduleTarget', () => { }) expect(result.current.scheduleTarget?.kind).toBe('repo') - expect(result.current.scheduleTarget?.repoId).toBe(5) - expect(result.current.scheduleTarget?.fullPath).toBe('/abs/repos/my-repo') - expect(result.current.scheduleTarget?.backHref).toBe('/repos/5') }) it('does not call getAssistantModeStatus for repo', async () => { diff --git a/frontend/src/hooks/useLSPStatus.test.tsx b/frontend/src/hooks/useLSPStatus.test.tsx index 0439cc28..caaf5925 100644 --- a/frontend/src/hooks/useLSPStatus.test.tsx +++ b/frontend/src/hooks/useLSPStatus.test.tsx @@ -137,52 +137,6 @@ describe('useLSPStatus', () => { expect(result.current.error).toBeTruthy() }) - it('should have 30s refetch interval', async () => { - mockGetLSPStatus.mockResolvedValue([]) - vi.mocked(useOpenCodeClient).mockReturnValue(mockClient) - - const queryClient = new QueryClient({ - defaultOptions: { queries: { retry: false } } - }) - const wrapper = ({ children }: { children: React.ReactNode }) => ( - {children} - ) - - const { result } = renderHook(() => useLSPStatus('http://localhost:5551', '/test'), { - wrapper - }) - - await waitFor(() => { - expect(result.current.isSuccess).toBe(true) - }) - - const observer = queryClient.getQueryCache().find({ queryKey: ['opencode', 'lsp', 'http://localhost:5551', '/test'] }) - expect((observer?.options as any).refetchInterval).toBe(30000) - }) - - it('should have 10s stale time', async () => { - mockGetLSPStatus.mockResolvedValue([]) - vi.mocked(useOpenCodeClient).mockReturnValue(mockClient) - - const queryClient = new QueryClient({ - defaultOptions: { queries: { retry: false } } - }) - const wrapper = ({ children }: { children: React.ReactNode }) => ( - {children} - ) - - const { result } = renderHook(() => useLSPStatus('http://localhost:5551', '/test'), { - wrapper - }) - - await waitFor(() => { - expect(result.current.isSuccess).toBe(true) - }) - - const observer = queryClient.getQueryCache().find({ queryKey: ['opencode', 'lsp', 'http://localhost:5551', '/test'] }) - expect((observer?.options as any).staleTime).toBe(10000) - }) - it('should refetch on window focus', async () => { mockGetLSPStatus.mockResolvedValue([]) vi.mocked(useOpenCodeClient).mockReturnValue(mockClient) diff --git a/frontend/src/pages/__tests__/SessionDetail.assistant-loading.test.tsx b/frontend/src/pages/__tests__/SessionDetail.assistant-loading.test.tsx index f1d8ec85..351ffa4b 100644 --- a/frontend/src/pages/__tests__/SessionDetail.assistant-loading.test.tsx +++ b/frontend/src/pages/__tests__/SessionDetail.assistant-loading.test.tsx @@ -264,10 +264,10 @@ describe('SessionDetail assistant loading at repoId=0', () => { }) }) - it('renders "Assistant" as workspaceDisplayName for non-assistant sessions without repo', async () => { + it('shows the loading state for a non-assistant session whose repo has not loaded', async () => { mocks.useSession.mockReturnValue({ data: undefined, isLoading: false }) - return render( + render( @@ -276,5 +276,9 @@ describe('SessionDetail assistant loading at repoId=0', () => { ) + + await waitFor(() => { + expect(screen.getByText('Loading repository...')).toBeInTheDocument() + }) }) }) diff --git a/frontend/src/pages/__tests__/SessionDetail.polling.test.tsx b/frontend/src/pages/__tests__/SessionDetail.polling.test.tsx index e4be6445..d0b4cc33 100644 --- a/frontend/src/pages/__tests__/SessionDetail.polling.test.tsx +++ b/frontend/src/pages/__tests__/SessionDetail.polling.test.tsx @@ -1,92 +1,248 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import { renderHook } from '@testing-library/react' -import { QueryClient, QueryClientProvider } from '@tanstack/react-query' -import { useQuery } from '@tanstack/react-query' +import { render, waitFor } from '@testing-library/react' +import { QueryClient, QueryClientProvider, type Query } from '@tanstack/react-query' +import { MemoryRouter, Route, Routes } from 'react-router-dom' +import { SessionDetail } from '../SessionDetail' const mocks = vi.hoisted(() => ({ - syncPendingActions: vi.fn(), + 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(), + useSessionStatusForSession: vi.fn(), + syncPermissionsForSession: vi.fn(), + syncQuestionsForSession: vi.fn(), })) -describe('SessionDetail pending-actions polling', () => { +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: mocks.useSessionStatusForSession, +})) + +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 findPendingActionsQuery = (queryClient: QueryClient): Query | undefined => + queryClient + .getQueryCache() + .getAll() + .find((query) => query.queryKey[1] === 'pending-actions') + +describe('SessionDetail pending-actions polling gating', () => { beforeEach(() => { vi.clearAllMocks() + + mocks.useSession.mockReturnValue({ data: undefined, isLoading: false }) + mocks.useMessages.mockReturnValue({ data: [], isLoading: false }) + mocks.useRepoActivity.mockReturnValue(undefined) + mocks.usePermissions.mockReturnValue({ + pendingCount: 0, + hasPermissionsForSession: vi.fn(() => false), + syncForSession: mocks.syncPermissionsForSession, + }) + mocks.useQuestions.mockReturnValue({ + current: null, + pendingCount: 0, + hasQuestionsForSession: vi.fn(() => false), + reply: vi.fn(), + reject: vi.fn(), + syncForSession: mocks.syncQuestionsForSession, + }) + 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) + mocks.useSessionStatusForSession.mockReturnValue({ type: 'idle' }) }) - const createQueryClient = () => new QueryClient({ - defaultOptions: { - queries: { retry: false }, - }, - }) + const createQueryClient = () => + new QueryClient({ defaultOptions: { queries: { retry: false } } }) - const wrapper = ({ children }: { children: React.ReactNode }) => ( - - {children} - - ) - - it('should poll pending-actions when refetchInterval is set', async () => { - vi.useFakeTimers() - - mocks.syncPendingActions.mockResolvedValue(null) - - const testQueryOptions = { - queryKey: ['opencode', 'pending-actions', 'http://localhost:5003', 'session-1', '/repo'] as const, - queryFn: async () => { - await mocks.syncPendingActions() - return null - }, - enabled: true, - refetchOnMount: 'always' as const, - refetchOnReconnect: true, - refetchOnWindowFocus: true, - refetchInterval: 30000, - retry: false, - } - - renderHook( - () => useQuery(testQueryOptions), - { wrapper } + const renderSessionDetail = (queryClient: QueryClient) => + render( + + + + } /> + + + ) - expect(mocks.syncPendingActions).toHaveBeenCalledTimes(1) + it('polls on the sync interval when disconnected and the session is active', async () => { + mocks.useSSE.mockReturnValue({ isConnected: false, isReconnecting: false }) + mocks.useSessionStatusForSession.mockReturnValue({ type: 'busy' }) - await vi.advanceTimersByTimeAsync(30000) + const queryClient = createQueryClient() + renderSessionDetail(queryClient) - expect(mocks.syncPendingActions).toHaveBeenCalledTimes(2) + await waitFor(() => { + expect(findPendingActionsQuery(queryClient)).toBeDefined() + }) - vi.useRealTimers() + const query = findPendingActionsQuery(queryClient) + expect((query?.options as { refetchInterval?: unknown }).refetchInterval).toBe(30000) }) - it('should not poll pending-actions when refetchInterval is false', async () => { - vi.useFakeTimers() - - mocks.syncPendingActions.mockResolvedValue(null) + it('does not poll while the SSE stream is connected', async () => { + mocks.useSSE.mockReturnValue({ isConnected: true, isReconnecting: false }) + mocks.useSessionStatusForSession.mockReturnValue({ type: 'busy' }) - const testQueryOptions = { - queryKey: ['opencode', 'pending-actions', 'http://localhost:5003', 'session-1', '/repo'] as const, - queryFn: async () => { - await mocks.syncPendingActions() - return null - }, - enabled: true, - refetchOnMount: 'always' as const, - refetchOnReconnect: true, - refetchOnWindowFocus: true, - refetchInterval: false as const, - retry: false, - } + const queryClient = createQueryClient() + renderSessionDetail(queryClient) - renderHook( - () => useQuery(testQueryOptions), - { wrapper } - ) + await waitFor(() => { + expect(findPendingActionsQuery(queryClient)).toBeDefined() + }) - expect(mocks.syncPendingActions).toHaveBeenCalledTimes(1) + const query = findPendingActionsQuery(queryClient) + expect((query?.options as { refetchInterval?: unknown }).refetchInterval).toBe(false) + }) - await vi.advanceTimersByTimeAsync(60000) - - expect(mocks.syncPendingActions).toHaveBeenCalledTimes(1) + it('does not poll when disconnected but the session is idle with no incomplete messages', async () => { + mocks.useSSE.mockReturnValue({ isConnected: false, isReconnecting: false }) + mocks.useSessionStatusForSession.mockReturnValue({ type: 'idle' }) - vi.useRealTimers() + const queryClient = createQueryClient() + renderSessionDetail(queryClient) + + await waitFor(() => { + expect(findPendingActionsQuery(queryClient)).toBeDefined() + }) + + const query = findPendingActionsQuery(queryClient) + expect((query?.options as { refetchInterval?: unknown }).refetchInterval).toBe(false) }) }) diff --git a/frontend/src/pages/__tests__/SessionDetail.sendError.test.tsx b/frontend/src/pages/__tests__/SessionDetail.sendError.test.tsx deleted file mode 100644 index 94746c29..00000000 --- a/frontend/src/pages/__tests__/SessionDetail.sendError.test.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest' -import { render, screen, fireEvent } from '@testing-library/react' -import { SessionSendErrorBanner } from '@/components/session/SessionSendErrorBanner' -import { useSendErrorStore } from '@/stores/sendErrorStore' - -vi.mock('@/lib/toast', () => ({ - showToast: { error: vi.fn() }, -})) - -describe('SessionDetail send error integration', () => { - beforeEach(() => { - vi.clearAllMocks() - useSendErrorStore.setState({ errors: {} }) - }) - - it('shows error banner with title, message, and detail when store is seeded', () => { - useSendErrorStore.getState().setError({ - sessionID: 'sess-1', - title: 'Model Unavailable', - message: 'Selected model is no longer available.', - detail: '409 Conflict', - }) - - render() - - expect(screen.getByText('Model Unavailable')).toBeInTheDocument() - expect(screen.getByText('Selected model is no longer available.')).toBeInTheDocument() - expect(screen.getByText('409 Conflict')).toBeInTheDocument() - }) - - it('dismisses banner and clears store entry on click', () => { - useSendErrorStore.getState().setError({ - sessionID: 'sess-2', - title: 'Error', - message: 'Something failed', - }) - - render() - expect(screen.getByText('Something failed')).toBeInTheDocument() - - fireEvent.click(screen.getByRole('button')) - - expect(screen.queryByText('Something failed')).not.toBeInTheDocument() - expect(useSendErrorStore.getState().getError('sess-2')).toBeNull() - }) - - it('does not trigger a toast error when banner renders', async () => { - const { showToast } = await import('@/lib/toast') - - useSendErrorStore.getState().setError({ - sessionID: 'sess-3', - title: 'Error', - message: 'No toast please', - }) - - render() - expect(screen.getByText('No toast please')).toBeInTheDocument() - expect(showToast.error).not.toHaveBeenCalled() - }) - - it('does not render banner when no error exists for session', () => { - render() - expect(screen.queryByRole('alert')).not.toBeInTheDocument() - }) -}) diff --git a/frontend/src/pages/__tests__/SessionDetail.todo-header.test.tsx b/frontend/src/pages/__tests__/SessionDetail.todo-header.test.tsx index 73fcc4d3..d5f098ec 100644 --- a/frontend/src/pages/__tests__/SessionDetail.todo-header.test.tsx +++ b/frontend/src/pages/__tests__/SessionDetail.todo-header.test.tsx @@ -1,6 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { render, screen, waitFor } from '@testing-library/react' -import userEvent from '@testing-library/user-event' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { MemoryRouter, Route, Routes } from 'react-router-dom' import { useSessionTodos } from '@/stores/sessionTodosStore' @@ -239,40 +238,6 @@ describe('SessionDetail todo-header integration', () => { ) } - it('renders SessionTodoDisplay collapsed by default inside SessionDetail header', async () => { - useSessionTodos.getState().setTodos('session-1', activeTodos) - - renderSessionDetail('session-1', 1) - - await waitFor(() => { - expect(screen.getByText('Tasks: 1/3 complete')).toBeInTheDocument() - }) - - expect(screen.queryByText('Implement mobile header fix')).not.toBeInTheDocument() - }) - - it('expands todo list when clicked inside SessionDetail header', async () => { - const user = userEvent.setup() - useSessionTodos.getState().setTodos('session-1', activeTodos) - - renderSessionDetail('session-1', 1) - - await waitFor(() => { - expect(screen.getByText('Tasks: 1/3 complete')).toBeInTheDocument() - }) - - const collapsedRow = screen.getByText('Tasks: 1/3 complete') - await user.click(collapsedRow) - - expect(screen.getByText('Implement mobile header fix')).toBeInTheDocument() - expect(screen.getByText('Add regression tests')).toBeInTheDocument() - - const expandedContainer = screen.getByTestId('todo-expanded-list') - expect(expandedContainer).toHaveClass('max-h-[80px]') - expect(expandedContainer).toHaveClass('sm:max-h-[160px]') - expect(expandedContainer).toHaveClass('overflow-y-auto') - }) - it('header wrapper uses max-h-72 sm:max-h-80 and overflow-hidden for proper containment', async () => { useSessionTodos.getState().setTodos('session-1', activeTodos) @@ -283,48 +248,10 @@ describe('SessionDetail todo-header integration', () => { }) 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') }) - - it('collapses todo list when expanded header is clicked again', async () => { - const user = userEvent.setup() - useSessionTodos.getState().setTodos('session-1', activeTodos) - - renderSessionDetail('session-1', 1) - - await waitFor(() => { - expect(screen.getByText('Tasks: 1/3 complete')).toBeInTheDocument() - }) - - const collapsedRow = screen.getByText('Tasks: 1/3 complete') - await user.click(collapsedRow) - - expect(screen.getByTestId('todo-expanded-list')).toBeInTheDocument() - - const expandedHeader = screen.getByText('Tasks: 1/3 complete') - await user.click(expandedHeader) - - expect(screen.queryByTestId('todo-expanded-list')).not.toBeInTheDocument() - }) - - it('does not render SessionTodoDisplay when all tasks are completed', async () => { - const allCompletedTodos: Todo[] = [ - { id: '1', content: 'Task one', status: 'completed', priority: 'high' }, - { id: '2', content: 'Task two', status: 'completed', priority: 'medium' }, - ] - useSessionTodos.getState().setTodos('session-1', allCompletedTodos) - - renderSessionDetail('session-1', 1) - - await waitFor(() => { - const headerRegion = screen.getByTestId('session-header-region') - expect(headerRegion).toBeInTheDocument() - }) - - expect(screen.queryByText(/Tasks:/)).not.toBeInTheDocument() - }) })