test: remove route tests
This commit is contained in:
parent
864ad50880
commit
c2790d9181
@ -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: () => <div data-testid="left-panel">LeftPanel</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/containers/dialogs/AppUpdater', () => ({
|
||||
default: () => <div data-testid="app-updater">AppUpdater</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/containers/dialogs/CortexFailureDialog', () => ({
|
||||
CortexFailureDialog: () => <div data-testid="cortex-failure">CortexFailure</div>,
|
||||
}))
|
||||
|
||||
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: () => <div data-testid="analytic-provider">AnalyticProvider</div>,
|
||||
}))
|
||||
|
||||
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: () => <div data-testid="prompt-analytic">PromptAnalytic</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/containers/dialogs/ToolApproval', () => ({
|
||||
default: () => <div data-testid="tool-approval">ToolApproval</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/containers/dialogs/OutOfContextDialog', () => ({
|
||||
default: () => <div data-testid="out-of-context">OutOfContext</div>,
|
||||
}))
|
||||
|
||||
// Mock Outlet from react-router
|
||||
vi.mock('@tanstack/react-router', () => ({
|
||||
createRootRoute: (config: any) => ({ component: config.component }),
|
||||
Outlet: () => <div data-testid="outlet">Outlet</div>,
|
||||
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(<Component />)
|
||||
|
||||
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(<Component />)
|
||||
|
||||
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(<Component />)
|
||||
|
||||
expect(screen.getByTestId('outlet')).toBeDefined()
|
||||
})
|
||||
|
||||
// Test removed due to mock complexity - component logic is well covered by other tests
|
||||
})
|
||||
@ -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) => (
|
||||
<div data-testid="chat-input">
|
||||
ChatInput - Model: {model?.id || 'none'}, Speed: {showSpeedToken ? 'yes' : 'no'}, Initial: {initialMessage ? 'yes' : 'no'}
|
||||
</div>
|
||||
),
|
||||
}))
|
||||
|
||||
vi.mock('@/containers/HeaderPage', () => ({
|
||||
default: ({ children }: { children: React.ReactNode }) => (
|
||||
<div data-testid="header-page">{children}</div>
|
||||
),
|
||||
}))
|
||||
|
||||
vi.mock('@/containers/SetupScreen', () => ({
|
||||
default: () => <div data-testid="setup-screen">SetupScreen</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/containers/DropdownAssistant', () => ({
|
||||
default: () => <div data-testid="dropdown-assistant">DropdownAssistant</div>,
|
||||
}))
|
||||
|
||||
vi.mock('@/i18n/react-i18next-compat', () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string) => {
|
||||
const translations: Record<string, string> = {
|
||||
'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(<Component />)
|
||||
|
||||
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(<Component />)
|
||||
|
||||
expect(screen.getByTestId('setup-screen')).toBeDefined()
|
||||
expect(screen.queryByTestId('header-page')).toBeNull()
|
||||
})
|
||||
|
||||
it('should pass correct props to ChatInput', () => {
|
||||
const Component = Route.component
|
||||
render(<Component />)
|
||||
|
||||
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(<Component />)
|
||||
|
||||
expect(screen.getByTestId('header-page')).toBeDefined()
|
||||
expect(screen.queryByTestId('setup-screen')).toBeNull()
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user