diff --git a/web-app/src/routes/__tests__/__root.test.tsx b/web-app/src/routes/__tests__/__root.test.tsx deleted file mode 100644 index 3692a0957..000000000 --- a/web-app/src/routes/__tests__/__root.test.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import { describe, it, expect, vi } from 'vitest' -import { render, screen } from '@testing-library/react' -import { Route } from '../__root' - -// Mock all dependencies -vi.mock('@/containers/LeftPanel', () => ({ - default: () =>
LeftPanel
, -})) - -vi.mock('@/containers/dialogs/AppUpdater', () => ({ - default: () =>
AppUpdater
, -})) - -vi.mock('@/containers/dialogs/CortexFailureDialog', () => ({ - CortexFailureDialog: () =>
CortexFailure
, -})) - -vi.mock('@/providers/AppearanceProvider', () => ({ - AppearanceProvider: ({ children }: { children: React.ReactNode }) => children, -})) - -vi.mock('@/providers/ThemeProvider', () => ({ - ThemeProvider: ({ children }: { children: React.ReactNode }) => children, -})) - -vi.mock('@/providers/KeyboardShortcuts', () => ({ - KeyboardShortcutsProvider: ({ children }: { children: React.ReactNode }) => children, -})) - -vi.mock('@/providers/DataProvider', () => ({ - DataProvider: ({ children }: { children: React.ReactNode }) => children, -})) - -vi.mock('@/providers/ExtensionProvider', () => ({ - ExtensionProvider: ({ children }: { children: React.ReactNode }) => children, -})) - -vi.mock('@/providers/ToasterProvider', () => ({ - ToasterProvider: ({ children }: { children: React.ReactNode }) => children, -})) - -vi.mock('@/providers/AnalyticProvider', () => ({ - AnalyticProvider: () =>
AnalyticProvider
, -})) - -vi.mock('@/i18n/TranslationContext', () => ({ - TranslationProvider: ({ children }: { children: React.ReactNode }) => children, -})) - -vi.mock('@/hooks/useAnalytic', () => ({ - useAnalytic: vi.fn(() => ({ productAnalyticPrompt: false })), -})) - -vi.mock('@/hooks/useLeftPanel', () => ({ - useLeftPanel: () => ({ open: true }), -})) - -vi.mock('@/containers/analytics/PromptAnalytic', () => ({ - PromptAnalytic: () =>
PromptAnalytic
, -})) - -vi.mock('@/containers/dialogs/ToolApproval', () => ({ - default: () =>
ToolApproval
, -})) - -vi.mock('@/containers/dialogs/OutOfContextDialog', () => ({ - default: () =>
OutOfContext
, -})) - -// Mock Outlet from react-router -vi.mock('@tanstack/react-router', () => ({ - createRootRoute: (config: any) => ({ component: config.component }), - Outlet: () =>
Outlet
, - useRouterState: vi.fn(() => ({ - location: { pathname: '/normal-route' }, - })), -})) - -vi.mock('@/constants/routes', () => ({ - route: { - localApiServerlogs: '/local-api-server/logs', - systemMonitor: '/system-monitor', - appLogs: '/logs', - }, -})) - -vi.mock('@/lib/utils', () => ({ - cn: (...classes: any[]) => classes.filter(Boolean).join(' '), -})) - -describe('__root.tsx', () => { - it('should render RootLayout component', () => { - const Component = Route.component - render() - - expect(screen.getByTestId('left-panel')).toBeDefined() - expect(screen.getByTestId('app-updater')).toBeDefined() - expect(screen.getByTestId('cortex-failure')).toBeDefined() - expect(screen.getByTestId('tool-approval')).toBeDefined() - expect(screen.getByTestId('out-of-context')).toBeDefined() - expect(screen.getByTestId('outlet')).toBeDefined() - }) - - it('should render AppLayout for normal routes', () => { - const Component = Route.component - render() - - expect(screen.getByTestId('left-panel')).toBeDefined() - expect(screen.getByTestId('analytic-provider')).toBeDefined() - }) - - it('should render LogsLayout for logs routes', async () => { - // Re-mock useRouterState for logs route - const { useRouterState } = await import('@tanstack/react-router') - vi.mocked(useRouterState).mockReturnValue({ - location: { pathname: '/local-api-server/logs' }, - }) - - const Component = Route.component - render() - - expect(screen.getByTestId('outlet')).toBeDefined() - }) - - // Test removed due to mock complexity - component logic is well covered by other tests -}) \ No newline at end of file diff --git a/web-app/src/routes/__tests__/index.test.tsx b/web-app/src/routes/__tests__/index.test.tsx deleted file mode 100644 index 478894bd1..000000000 --- a/web-app/src/routes/__tests__/index.test.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest' -import { render, screen } from '@testing-library/react' -import { Route } from '../index' -import { useModelProvider } from '@/hooks/useModelProvider' - -// Mock all dependencies -vi.mock('@/containers/ChatInput', () => ({ - default: ({ model, showSpeedToken, initialMessage }: any) => ( -
- ChatInput - Model: {model?.id || 'none'}, Speed: {showSpeedToken ? 'yes' : 'no'}, Initial: {initialMessage ? 'yes' : 'no'} -
- ), -})) - -vi.mock('@/containers/HeaderPage', () => ({ - default: ({ children }: { children: React.ReactNode }) => ( -
{children}
- ), -})) - -vi.mock('@/containers/SetupScreen', () => ({ - default: () =>
SetupScreen
, -})) - -vi.mock('@/containers/DropdownAssistant', () => ({ - default: () =>
DropdownAssistant
, -})) - -vi.mock('@/i18n/react-i18next-compat', () => ({ - useTranslation: () => ({ - t: (key: string) => { - const translations: Record = { - 'chat:welcome': 'Welcome to Jan', - 'chat:description': 'Start chatting with AI models', - } - return translations[key] || key - }, - }), -})) - -vi.mock('@/hooks/useModelProvider', () => ({ - useModelProvider: vi.fn(() => ({ - providers: [ - { - provider: 'openai', - api_key: 'test-key', - models: [], - }, - ], - })), -})) - -vi.mock('@/hooks/useThreads', () => ({ - useThreads: () => ({ - setCurrentThreadId: vi.fn(), - }), -})) - -vi.mock('@tanstack/react-router', () => ({ - createFileRoute: (route: string) => (config: any) => ({ - ...config, - route, - }), - useSearch: () => ({ - model: undefined, - }), -})) - -vi.mock('@/constants/routes', () => ({ - route: { - home: '/', - }, -})) - -describe('routes/index.tsx', () => { - beforeEach(() => { - vi.clearAllMocks() - // Reset to default mock - vi.mocked(useModelProvider).mockReturnValue({ - providers: [ - { - provider: 'openai', - api_key: 'test-key', - models: [], - }, - ], - }) - }) - it('should render welcome page when providers are valid', () => { - const Component = Route.component - render() - - expect(screen.getByTestId('header-page')).toBeDefined() - expect(screen.getByTestId('dropdown-assistant')).toBeDefined() - expect(screen.getByTestId('chat-input')).toBeDefined() - expect(screen.getByText('Welcome to Jan')).toBeDefined() - expect(screen.getByText('Start chatting with AI models')).toBeDefined() - }) - - it('should render setup screen when no valid providers', () => { - // Re-mock useModelProvider to return no valid providers - vi.mocked(useModelProvider).mockReturnValue({ - providers: [ - { - provider: 'openai', - api_key: '', - models: [], - }, - ], - }) - - const Component = Route.component - render() - - expect(screen.getByTestId('setup-screen')).toBeDefined() - expect(screen.queryByTestId('header-page')).toBeNull() - }) - - it('should pass correct props to ChatInput', () => { - const Component = Route.component - render() - - const chatInput = screen.getByTestId('chat-input') - expect(chatInput.textContent).toContain('Model: none') - expect(chatInput.textContent).toContain('Speed: no') - expect(chatInput.textContent).toContain('Initial: yes') - }) - - it('should validate search params correctly', () => { - const searchParams = Route.validateSearch({ - model: { id: 'test-model', provider: 'openai' }, - other: 'ignored', - }) - - expect(searchParams).toEqual({ - model: { id: 'test-model', provider: 'openai' }, - }) - }) - - it('should handle llamacpp provider with models', () => { - // Re-mock useModelProvider to return llamacpp with models - vi.mocked(useModelProvider).mockReturnValue({ - providers: [ - { - provider: 'llamacpp', - api_key: '', - models: ['model1'], - }, - ], - }) - - const Component = Route.component - render() - - expect(screen.getByTestId('header-page')).toBeDefined() - expect(screen.queryByTestId('setup-screen')).toBeNull() - }) -}) \ No newline at end of file