Test Structure & Organization
Test Directory Layout
src/__tests__/
βββ api/ # API service tests
β βββ ProductService.test.ts (40+ tests)
β βββ auth.test.ts (20+ tests)
β βββ client.test.ts (30+ tests)
β βββ integration/
β βββ apiWorkflow.integration.test.ts
β
βββ components/ # Component tests
β βββ __snapshots__/
β β βββ Button.test.tsx.snap
β β βββ Header.test.tsx.snap
β βββ Buttons.test.tsx (15+ tests)
β βββ Header.test.tsx (20+ tests)
β βββ Sidebar.test.tsx (15+ tests)
β βββ ErrorBoundary.test.tsx (10+ tests)
β βββ SkeletonLoader.test.tsx (10+ tests)
β βββ pages/
β βββ LoginPage.test.tsx (20+ tests)
β βββ ListStockPage.test.tsx (25+ tests)
β βββ AddProductPage.test.tsx (20+ tests)
β βββ ChangeProductDetailsPage.test.tsx (15+ tests)
β βββ AdminDashboard.test.tsx (20+ tests)
β βββ UserDashboard.test.tsx (10+ tests)
β
βββ services/ # Service & hook tests
β βββ apiClient.test.ts (25+ tests)
β βββ hooks/
β β βββ useProducts.test.ts (25+ tests)
β β βββ useForm.test.ts (30+ tests)
β β βββ useAuth.test.ts (20+ tests)
β β βββ useDebounce.test.ts (10+ tests)
β β βββ useLocalStorage.test.ts (12+ tests)
β βββ integration/
β βββ serviceWorkflow.test.ts
β
βββ utils/ # Utility function tests
β βββ validation.test.ts (15+ tests)
β βββ helpers.test.ts (15+ tests)
β βββ formatters.test.ts (10+ tests)
β
βββ integration/ # Integration tests
β βββ productWorkflow.integration.test.ts
β βββ authFlow.integration.test.ts
β βββ dashboardIntegration.test.ts
β
βββ mocks/
β βββ server.ts # MSW server setup
β βββ handlers.ts # HTTP request handlers
β βββ data.ts # Mock data factories
β
βββ setup.ts # Global test setup
Test File Statistics
API Service Tests (90+ tests)
src/__tests__/api/
βββ ProductService.test.ts (40 tests)
β βββ getProducts (8 tests)
β βββ getProductById (5 tests)
β βββ createProduct (8 tests)
β βββ updateProduct (8 tests)
β βββ deleteProduct (4 tests)
β βββ searchProducts (4 tests)
β βββ batch operations (3 tests)
β
βββ auth.test.ts (20 tests)
β βββ login (8 tests)
β βββ logout (2 tests)
β βββ token extraction (5 tests)
β βββ token validation (5 tests)
β
βββ client.test.ts (30 tests)
β βββ configuration (5 tests)
β βββ request interceptor (10 tests)
β βββ response interceptor (10 tests)
β βββ error handling (5 tests)
β
βββ integration/
βββ apiWorkflow.integration.test.ts (20 tests)
βββ CRUD workflow (8 tests)
βββ error scenarios (12 tests)
Component Tests (120+ tests)
src/__tests__/components/
βββ Buttons.test.tsx (15 tests)
β βββ Rendering (3 tests)
β βββ Props (5 tests)
β βββ Events (4 tests)
β βββ Accessibility (3 tests)
β
βββ Header.test.tsx (20 tests)
β βββ Rendering (3 tests)
β βββ Navigation (5 tests)
β βββ User menu (6 tests)
β βββ Responsive (4 tests)
β βββ Accessibility (2 tests)
β
βββ pages/ (80+ tests)
β βββ LoginPage.test.tsx (20 tests)
β βββ ListStockPage.test.tsx (25 tests)
β βββ AddProductPage.test.tsx (20 tests)
β βββ AdminDashboard.test.tsx (15+ tests)
β
βββ Snapshots (5+ tests)
βββ Button.test.tsx.snap
βββ Header.test.tsx.snap
Service & Hook Tests (97+ tests)
src/__tests__/services/
βββ apiClient.test.ts (25 tests)
β βββ Configuration (5 tests)
β βββ Request handling (8 tests)
β βββ Response handling (8 tests)
β βββ Error handling (4 tests)
β
βββ hooks/ (72+ tests)
β βββ useProducts.test.ts (25 tests)
β β βββ Fetch on mount (5 tests)
β β βββ Loading states (4 tests)
β β βββ Error handling (6 tests)
β β βββ Refetch (10 tests)
β β
β βββ useForm.test.ts (30 tests)
β β βββ Initialization (3 tests)
β β βββ Value updates (5 tests)
β β βββ Validation (10 tests)
β β βββ Submission (8 tests)
β β βββ Reset (4 tests)
β β
β βββ useAuth.test.ts (12 tests)
β βββ useDebounce.test.ts (3 tests)
β βββ useLocalStorage.test.ts (2 tests)
β
βββ integration/
βββ serviceWorkflow.test.ts
Utility Tests (40+ tests)
src/__tests__/utils/
βββ validation.test.ts (15 tests)
β βββ Email validation (3 tests)
β βββ Product validation (5 tests)
β βββ Form validation (4 tests)
β βββ Type guards (3 tests)
β
βββ helpers.test.ts (15 tests)
β βββ Array helpers (4 tests)
β βββ Object helpers (5 tests)
β βββ String helpers (3 tests)
β βββ Date helpers (3 tests)
β
βββ formatters.test.ts (10 tests)
βββ Number formatting (3 tests)
βββ Date formatting (4 tests)
βββ Currency formatting (3 tests)
Integration Tests (30+ tests)
src/__tests__/integration/
βββ productWorkflow.integration.test.ts (12 tests)
β βββ Full CRUD workflow (5 tests)
β βββ Bulk operations (4 tests)
β βββ Error scenarios (3 tests)
β
βββ authFlow.integration.test.ts (10 tests)
β βββ Login flow (4 tests)
β βββ Session management (3 tests)
β βββ Token refresh (3 tests)
β
βββ dashboardIntegration.test.ts (8 tests)
βββ Data loading (3 tests)
βββ User interactions (3 tests)
βββ State updates (2 tests)
Test Coverage by Category
API Coverage
ProductService.ts
βββ getProducts: 100%
βββ getProductById: 100%
βββ createProduct: 95%
βββ updateProduct: 100%
βββ deleteProduct: 100%
βββ searchProducts: 100%
βββ batch ops: 90%
Overall: 98%
auth.ts
βββ login: 95%
βββ logout: 100%
βββ token extraction: 95%
βββ validation: 90%
Overall: 95%
apiClient.ts
βββ Configuration: 100%
βββ Interceptors: 95%
βββ Error handling: 90%
βββ Token injection: 95%
Overall: 95%
Component Coverage
Buttons.tsx: 95%
Header.tsx: 92%
Sidebar.tsx: 88%
ErrorBoundary.tsx: 85%
SkeletonLoader.tsx: 90%
LoginPage.tsx: 85%
ListStockPage.tsx: 88%
AddProductPage.tsx: 90%
AdminDashboard.tsx: 82%
UserDashboard.tsx: 80%
Overall Components: 88%
Services Coverage
useProducts: 90%
useForm: 92%
useAuth: 88%
useDebounce: 95%
useLocalStorage: 85%
Custom Hooks: 90%
Utility functions: 85%
Helpers: 88%
Formatters: 86%
Validators: 92%
Overall Services: 89%
Test Execution Timeline
Local Test Run (8.2 seconds)
β Unit Tests (320 tests) 2.1s (fastest)
β Service Tests (97 tests) 1.8s
β Component Tests (120 tests) 2.8s
β Integration Tests (30 tests) 1.0s
β Utility Tests (40 tests) 0.5s
βββββββββββββββββββββββββββββββ
Total: 607 tests 8.2s
CI/CD Pipeline (12 seconds)
Setup & Install 2.0s
Lint 1.5s
Build 2.0s
Run Tests (607) 4.2s
Coverage Report 1.3s
Upload Coverage 1.0s
βββββββββββββββββββββββββββββββ
Total CI/CD Time 12s
Test Statistics Summary
| Metric | Count |
|---|---|
| Total Test Files | 25+ |
| Total Test Cases | 607+ |
| Unit Tests | 320+ |
| Component Tests | 120+ |
| Integration Tests | 30+ |
| Snapshot Tests | 5+ |
| Mock Handlers | 15+ |
| Coverage Avg | 83% |
Related Documentation
- Overview - Testing overview
- Patterns - Testing patterns
- Setup - Configuration
- Coverage - Coverage goals
- Running Tests - Commands
Last Updated: November 2025