Testing Strategy
What is this?
The blueprint for ChatKcal's "Testing Trophy," detailing the four layers of defense: Static Analysis, Unit Tests, Component Integration, and Network Integration.
Status: Implemented (Layers 1, 2, 3, 4) Reference: ADR 005: Testing Strategy
ChatKcal adopts a Layered Testing Strategy (The Testing Trophy) to ensure reliability without slowing down development.
1. Static Analysis (Layer 1)
- Tools: ESLint, Prettier.
- Scope: All files.
- CI Gate: Must pass before merge.
2. Unit Testing (Layer 2)
- Tools: Vitest.
- Scope:
- Backend: 100% coverage for AppSync Resolvers (
appsync/*.js). These are pure JS functions and must be tested logic-heavy. - Frontend: Utility functions (
dateUtils.js,calculators.js). React Hooks with complex logic.
- Backend: 100% coverage for AppSync Resolvers (
3. Integration Testing (Layer 3)
- Tools: Vitest + React Testing Library (RTL).
- Scope:
- Components: Verify user interactions (clicks, forms) and rendering.
- Philosophy: Test behavior, not implementation details.
- Must Test:
- Concurrency & Immutability: Verify that the "God Row" (Settings) rejects updates with stale versions, and that Unit definitions are locked once created.
4. Network Integration (Layer 4)
- Tools: Playwright (Mocked).
- Scope: Critical User Journeys (e.g., Logging a Meal, Saving Settings, Guest Mode).
- Method: Network Interception.
- API Tests: Mock API responses to verify frontend handles Loading, Success, Error, and Race Conditions.
- Guest Mode: Assert zero network calls to
appsync-apiwhen operating in Guest Mode (Isolation Verification). - Persistence: Verify data survives page reloads (
IndexedDBpersistence).
5. End-to-End (Smoke Tests)
- Tools: Playwright (Live).
- Scope: Critical "Can I Log In?" path only.
- Method: Hits the real Test Backend. Run sparingly.
Observability & Debugging
To bridge the gap between tests and production, we implement structured logging:
- Library:
loglevel. - Strategy:
- Development:
debuglevel enabled by default (controlled viaVITE_LOG_LEVEL). - Production:
warnlevel to minimize noise while capturing critical errors. - Prefixing: All logs are prefixed with
[ChatKcal]for easy filtering in the browser console.
- Development:
- Traceability: Significant state transitions (e.g., Guest Mode -> Authenticated Sync) are logged with metadata to facilitate troubleshooting in remote environments.