Add AuthProvider to test components

This commit is contained in:
2025-07-31 20:34:33 +02:00
parent 169432260a
commit ad117ef6c6
6 changed files with 294 additions and 266 deletions

View File

@@ -1,10 +1,11 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import App from '@/App'
import { InstancesProvider } from '@/contexts/InstancesContext'
import { instancesApi } from '@/lib/api'
import type { Instance } from '@/types/instance'
import { AuthProvider } from '@/contexts/AuthContext'
// Mock the API
vi.mock('@/lib/api', () => ({
@@ -35,9 +36,11 @@ vi.mock('@/lib/healthService', () => ({
function renderApp() {
return render(
<InstancesProvider>
<App />
</InstancesProvider>
<AuthProvider>
<InstancesProvider>
<App />
</InstancesProvider>
</AuthProvider>
)
}
@@ -50,6 +53,12 @@ describe('App Component - Critical Business Logic Only', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(instancesApi.list).mockResolvedValue(mockInstances)
window.sessionStorage.setItem('llamactl_management_key', 'test-api-key-123')
global.fetch = vi.fn(() => Promise.resolve(new Response(null, { status: 200 })))
})
afterEach(() => {
vi.restoreAllMocks()
})
describe('End-to-End Instance Management', () => {
@@ -167,7 +176,6 @@ describe('App Component - Critical Business Logic Only', () => {
renderApp()
// App should still render and show error
expect(screen.getByText('Llamactl Dashboard')).toBeInTheDocument()
await waitFor(() => {
expect(screen.getByText('Error loading instances')).toBeInTheDocument()
})