# OrangeCat Comprehensive Testing Guide ## Overview This guide provides detailed instructions for using OrangeCat's comprehensive testing infrastructure, covering unit tests, integration tests, end-to-end tests, performance tests, and security tests. ## Quick Start ### Run All Tests ```bash npm run test:comprehensive ``` ### Run Specific Test Types ```bash # Unit tests only npm run test:comprehensive:unit # Integration tests only npm run test:comprehensive:integration # End-to-end tests only npm run test:comprehensive:e2e # Performance tests only npm run test:comprehensive:performance # Security tests only npm run test:comprehensive:security ``` ### Run with Coverage ```bash npm run test:comprehensive:coverage ``` ### Watch Mode ```bash npm run test:comprehensive:watch ``` ## Test Types ### 1. Unit Tests **Purpose**: Test individual functions, components, and services in isolation. **Location**: `src/__tests__/` and `src/*/tests/` **Framework**: Jest with Testing Library **Coverage Target**: 85%+ #### Writing Unit Tests ```typescript // src/components/__tests__/Button.test.tsx import { render, screen } from '@testing-library/react'; import { Button } from '../Button'; describe('Button Component', () => { test('should render button with text', () => { render(); expect(screen.getByRole('button', { name: /click me/i })).toBeInTheDocument(); }); test('should handle click events', () => { const handleClick = jest.fn(); render(); screen.getByRole('button').click(); expect(handleClick).toHaveBeenCalledTimes(1); }); }); ``` ### 2. Integration Tests **Purpose**: Test interactions between components and services. **Location**: `tests/integration/` **Framework**: Jest #### Writing Integration Tests ```typescript // tests/integration/auth-integration.test.ts import { ProfileService } from '@/services/profileService'; import { createTestUser } from '@/tests/utils'; describe('ProfileService Integration', () => { test('should integrate with Supabase', async () => { const user = createTestUser(); const profile = await ProfileService.getProfile(user.id); expect(profile).toBeDefined(); expect(profile.id).toBe(user.id); }); }); ``` ### 3. End-to-End Tests **Purpose**: Test complete user journeys from browser perspective. **Location**: `tests/e2e/` **Framework**: Playwright #### Writing E2E Tests ```typescript // tests/e2e/user-journey.spec.ts import { test, expect } from '@playwright/test'; test.describe('User Journey', () => { test('should complete user registration', async ({ page }) => { await page.goto('/auth'); await page.getByRole('textbox', { name: /email/i }).fill('test@example.com'); await page.getByRole('textbox', { name: /password/i }).fill('password123'); await page.getByRole('button', { name: /sign up/i }).click(); await expect(page).toHaveURL('/dashboard'); await expect(page.getByText('Welcome to OrangeCat')).toBeVisible(); }); }); ``` ### 4. Performance Tests **Purpose**: Test application performance under load. **Location**: `tests/performance/` **Framework**: Playwright with Lighthouse #### Writing Performance Tests ```typescript // tests/performance/critical-path.spec.ts import { test, expect } from '@playwright/test'; test.describe('Performance', () => { test('should meet Core Web Vitals', async ({ page }) => { await page.goto('/'); const metrics = await page.evaluate(() => { return performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming; }); expect(metrics.loadEventEnd - metrics.loadEventStart).toBeLessThan(3000); // LCP < 3s }); }); ``` ### 5. Security Tests **Purpose**: Test for security vulnerabilities. **Location**: `tests/security/` **Framework**: Custom security testing framework #### Writing Security Tests ```typescript // tests/security/xss-prevention.test.ts import { securityUtils } from '@/tests/utils'; describe('XSS Prevention', () => { test('should sanitize malicious input', () => { const maliciousInput = ''; const sanitized = sanitizeInput(maliciousInput); securityUtils.testSanitization(maliciousInput, sanitized); expect(sanitized).not.toContain('