> ## Documentation Index
> Fetch the complete documentation index at: https://docs.olis-ai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing

> Testing strategies and best practices

## Overview

Comprehensive testing ensures code quality and reliability across the Olis monorepo.

## Running Tests

```bash theme={null}
# Run all tests
pnpm test

# Run tests for specific app
pnpm nx test electron-client
pnpm nx test api-server

# Watch mode
pnpm nx test electron-client --watch

# With coverage
pnpm nx test --coverage
```

## Test Types

<CardGroup cols={2}>
  <Card title="Unit Tests" icon="flask">
    Test individual functions and components in isolation
  </Card>

  <Card title="Integration Tests" icon="link">
    Test interactions between components and services
  </Card>

  <Card title="E2E Tests" icon="robot">
    Test complete user workflows from start to finish
  </Card>

  <Card title="API Tests" icon="plug">
    Test API endpoints and responses
  </Card>
</CardGroup>

## Electron Client Testing

### Unit Tests with Jest

```typescript theme={null}
// src/components/ChatMessage.test.tsx
import { render, screen } from '@testing-library/react'
import ChatMessage from './ChatMessage'

describe('ChatMessage', () => {
  it('renders message text', () => {
    render(<ChatMessage text="Hello" sender="user" />)
    expect(screen.getByText('Hello')).toBeInTheDocument()
  })

  it('applies correct styling for user messages', () => {
    const { container } = render(
      <ChatMessage text="Hello" sender="user" />
    )
    expect(container.firstChild).toHaveClass('user-message')
  })
})
```

### E2E Tests with Playwright

```typescript theme={null}
// e2e/chat.spec.ts
import { test, expect } from '@playwright/test'

test('can send a chat message', async ({ page }) => {
  await page.goto('http://localhost:3000')

  await page.fill('[data-testid="chat-input"]', 'What is Olis?')
  await page.click('[data-testid="send-button"]')

  await expect(page.locator('[data-testid="chat-message"]')).toContainText('What is Olis?')
})
```

## API Server Testing

### pytest Integration Tests

```python theme={null}
# tests/integration_tests/test_fastapi.py
import pytest
from fastapi.testclient import TestClient
from main import app

client = TestClient(app)

def test_health_endpoint():
    response = client.get("/health")
    assert response.status_code == 200
    assert response.json()["status"] == "healthy"

def test_chat_endpoint():
    response = client.post(
        "/api/chat",
        json={
            "message": "Hello",
            "sessionId": "test-session"
        }
    )
    assert response.status_code == 200
    assert "response" in response.json()

@pytest.mark.asyncio
async def test_rag_pipeline():
    # Test document ingestion
    # Test retrieval
    # Test generation
    pass
```

## Best Practices

<AccordionGroup>
  <Accordion title="Write Testable Code">
    * Small, focused functions
    * Avoid side effects
    * Use dependency injection
    * Mock external dependencies
  </Accordion>

  <Accordion title="Test Coverage">
    * Aim for 80%+ coverage
    * Focus on critical paths
    * Don't test implementation details
    * Test behavior, not code
  </Accordion>

  <Accordion title="Test Organization">
    * Mirror source structure
    * Group related tests
    * Clear test names
    * Arrange-Act-Assert pattern
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Contributing" icon="hand-holding-heart" href="/development/contributing">
    Learn how to contribute
  </Card>

  <Card title="Building" icon="hammer" href="/development/building">
    Build for production
  </Card>
</CardGroup>
