More E2E tests.

This commit is contained in:
2026-01-13 17:29:41 +00:00
parent 27f084f950
commit 2ade07e12a

View File

@@ -1131,6 +1131,357 @@ These items were identified during gap analysis and have been completed.
---
---
## E2E Test Coverage Plan
This section outlines comprehensive e2e tests to cover the functionality described in the 10 specification files. Tests are organized by feature area with clear acceptance criteria mapping.
### 1. Authentication Tests (`e2e/auth.spec.ts`)
#### Existing Coverage
- Login page loads
- Form validation
- Protected routes redirect
- Basic error handling
#### Additional Tests Needed
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `OIDC flow completes successfully` | Click OIDC login, complete flow, verify dashboard redirect | auth.md - Login Flow |
| `Session persists across browser refresh` | Login, refresh page, verify still authenticated | auth.md - Session Management |
| `Session expires after inactivity` | Verify 14-day expiration (simulated) | auth.md - Session Management |
| `Logout clears session and cookie` | Click logout, verify redirect to login, verify cookie cleared | auth.md - Protected Routes |
| `Invalid token redirects to login` | Manually corrupt token, verify redirect | auth.md - Protected Routes |
| `Multiple tabs share session state` | Open two tabs, logout in one, verify other redirects | auth.md - Session Management |
---
### 2. Dashboard Tests (`e2e/dashboard.spec.ts`)
#### Existing Coverage
- Dashboard renders
- Decision display
- Override toggles
#### Additional Tests Needed
##### Decision Card
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Decision card shows REST status with red color` | Verify REST displays correctly | dashboard.md - Decision Card |
| `Decision card shows GENTLE status with yellow color` | Verify GENTLE displays correctly | dashboard.md - Decision Card |
| `Decision card shows TRAIN status with green color` | Verify TRAIN displays correctly | dashboard.md - Decision Card |
| `Decision card displays reason text` | Verify reason explains limiting factor | dashboard.md - Decision Card |
| `Decision card shows appropriate icon per status` | Verify icon matches status | dashboard.md - Decision Card |
##### Data Panel (8 Metrics)
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `HRV status displays with correct color coding` | Balanced=green, Unbalanced=red, Unknown=grey | dashboard.md - Data Panel |
| `Body Battery current displays 0-100 range` | Verify value display and bounds | dashboard.md - Data Panel |
| `Body Battery yesterday low displays correctly` | Verify yesterday's low value | dashboard.md - Data Panel |
| `Cycle day displays correctly (Day X format)` | Verify "Day 12" format | dashboard.md - Data Panel |
| `Current phase displays correctly` | Verify phase name matches cycle day | dashboard.md - Data Panel |
| `Week intensity minutes displays correctly` | Verify cumulative weekly minutes | dashboard.md - Data Panel |
| `Phase limit displays correctly` | Verify limit matches phase config | dashboard.md - Data Panel |
| `Remaining minutes calculates correctly` | Verify phase limit minus week intensity | dashboard.md - Data Panel |
##### Nutrition Panel
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Seeds display Flax+Pumpkin for days 1-14` | Verify follicular phase seeds | nutrition.md - Seed Cycling |
| `Seeds display Sesame+Sunflower for days 15+` | Verify luteal phase seeds | nutrition.md - Seed Cycling |
| `Carb range displays for current cycle day` | Verify range matches day | nutrition.md - Macro Guidance |
| `Keto guidance shows OPTIONAL during optimal window` | Days 7-14 should show optional | nutrition.md - Macro Guidance |
| `Keto guidance shows NEVER during late luteal` | Days 25-31 should show never (red) | nutrition.md - Macro Guidance |
| `Seed switch alert appears only on day 15` | Verify alert visibility | nutrition.md - Seed Switch Alert |
| `Seed switch alert is dismissible` | Click dismiss, verify gone | dashboard.md - Nutrition Panel |
##### Override Toggles
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Flare toggle forces REST decision` | Enable flare, verify REST | decision-engine.md - Override Integration |
| `Stress toggle forces REST decision` | Enable stress, verify REST | decision-engine.md - Override Integration |
| `Sleep toggle forces GENTLE decision` | Enable poor sleep, verify GENTLE | decision-engine.md - Override Integration |
| `PMS toggle forces GENTLE decision` | Enable PMS, verify GENTLE | decision-engine.md - Override Integration |
| `Override persists after page refresh` | Toggle, refresh, verify still active | dashboard.md - Override Toggles |
| `Override can be cleared` | Toggle on, toggle off, verify cleared | dashboard.md - Override Toggles |
| `Multiple overrides respect priority (flare > stress)` | Enable both, verify flare message | decision-engine.md - Override Priority |
##### Mini Calendar
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Mini calendar shows current month` | Verify correct month/year | dashboard.md - Mini Calendar |
| `Today is highlighted in calendar` | Verify today has distinct styling | dashboard.md - Mini Calendar |
| `Phase colors display correctly` | Verify color coding per phase | dashboard.md - Mini Calendar |
| `Period days marked distinctly` | Verify period days have special marker | dashboard.md - Mini Calendar |
##### Onboarding & Error States
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Onboarding banner shows when Garmin not connected` | New user sees Garmin setup prompt | dashboard.md - User Flows |
| `Onboarding banner shows when last period not set` | Shows date picker for period | dashboard.md - User Flows |
| `Onboarding banner shows when notification time not set` | Prompts for notification preference | dashboard.md - User Flows |
| `Network error shows retry option` | Simulate failure, verify retry UI | dashboard.md - Edge Cases |
| `Skeleton loaders display during data fetch` | Verify loading states | dashboard.md - Features |
| `Error toast auto-dismisses after 5 seconds` | Verify toast timing | dashboard.md - Features |
##### Accessibility
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Dashboard navigable with keyboard only` | Tab through all interactive elements | dashboard.md - Accessibility |
| `Override toggles not accidentally activated` | Verify deliberate activation required | dashboard.md - Success Criteria |
| `All critical metrics visible without scrolling on mobile` | Viewport check | dashboard.md - Responsive Design |
---
### 3. Decision Engine Tests (`e2e/decision-engine.spec.ts`)
**New file needed** - Tests the full decision priority chain through the UI
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `HRV Unbalanced forces REST` | User with unbalanced HRV sees REST | decision-engine.md - Priority 1 |
| `Body Battery yesterday low <30 forces REST` | Low recovery triggers REST | decision-engine.md - Priority 2 |
| `Late Luteal phase forces GENTLE` | Days 25-31 show GENTLE | decision-engine.md - Priority 3 |
| `Menstrual phase forces GENTLE` | Days 1-3 show GENTLE | decision-engine.md - Priority 4 |
| `Weekly intensity at phase limit forces REST` | At limit shows REST | decision-engine.md - Priority 5 |
| `Body Battery current <75 shows LIGHT` | Low current BB shows LIGHT | decision-engine.md - Priority 6 |
| `Body Battery current 75-84 shows REDUCED` | Medium BB shows REDUCED | decision-engine.md - Priority 7 |
| `All systems normal shows TRAIN` | Default state is TRAIN | decision-engine.md - Priority 8 |
| `Decision reason clearly explains limiting factor` | Verify reason text matches rule | decision-engine.md - Success Criteria |
---
### 4. Cycle Tracking Tests (`e2e/cycle.spec.ts`)
**New file needed** - Tests cycle calculation and phase transitions
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Cycle day resets to 1 on period start` | Log period, verify day 1 | cycle.md - Acceptance Criteria |
| `Phase transitions at correct day boundaries` | Verify each phase boundary | cycle.md - Phase System |
| `Menstrual phase shows days 1-3` | Verify phase assignment | cycle.md - Phase System |
| `Follicular phase shows days 4 to cycleLength-16` | Verify follicular range | cycle.md - Phase System |
| `Ovulation phase shows correct 2-day window` | Verify ovulation timing | cycle.md - Phase System |
| `Early luteal phase shows correct range` | Verify early luteal | cycle.md - Phase System |
| `Late luteal phase shows last 6 days` | Verify late luteal | cycle.md - Phase System |
| `Weekly limits adjust per phase` | Verify limit changes with phase | cycle.md - Acceptance Criteria |
| `Cycle exceeding configured length defaults to late luteal` | Day 35 of 31-day cycle | cycle.md - Edge Cases |
| `Custom cycle length (21 days) scales phases correctly` | Short cycle test | cycle.md - Features |
| `Custom cycle length (45 days) scales phases correctly` | Long cycle test | cycle.md - Features |
---
### 5. Period Logging Tests (`e2e/period-logging.spec.ts`)
#### Existing Coverage
- Basic period date logging
#### Additional Tests Needed
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Period date updates cycle day immediately` | Log period, verify day reset | cycle.md - User Flows |
| `Period date cannot be in future` | Attempt future date, verify error | cycle.md - User Flows |
| `Period history shows all logged periods` | View history, verify all entries | cycle.md - Acceptance Criteria |
| `Prediction accuracy calculated on new period` | Log period, see days early/late | calendar.md - ICS Feed Details |
| `Dashboard updates after period logged` | Log period, dashboard reflects change | cycle.md - User Flows |
---
### 6. Calendar Tests (`e2e/calendar.spec.ts`)
#### Existing Coverage
- Calendar page loads
- ICS export basic
#### Additional Tests Needed
##### In-App Calendar
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Month navigation works (next/previous)` | Click arrows, verify month changes | calendar.md - User Flows |
| `Phase colors render correctly per day` | Verify color coding | calendar.md - Features |
| `Calendar responsive on mobile` | Viewport test | calendar.md - Acceptance Criteria |
| `Today highlighted in calendar view` | Verify today styling | calendar.md - Features |
##### ICS Feed
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `ICS feed URL generates correctly` | Click generate, verify URL format | calendar.md - User Flows |
| `ICS feed contains next 90 days of events` | Download ICS, count events | calendar.md - ICS Feed Details |
| `ICS events are all-day events` | Parse ICS, verify all-day | calendar.md - ICS Feed Details |
| `Phase colors in ICS match spec` | Verify color hex values | calendar.md - ICS Feed Details |
| `Phase emojis included in event titles` | Verify emoji presence | calendar.md - ICS Feed Details |
| `Invalid token returns 401` | Use wrong token, verify 401 | calendar.md - Edge Cases |
| `Token regeneration invalidates old URL` | Regenerate, old URL fails | calendar.md - Acceptance Criteria |
| `Predicted vs actual events distinguished` | After period log, verify labels | calendar.md - ICS Feed Details |
| `Future cycles regenerated on new period` | Log period, future events update | calendar.md - Edge Cases |
---
### 7. Settings Tests (`e2e/settings.spec.ts`)
#### Existing Coverage
- Basic settings configuration
#### Additional Tests Needed
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Cycle length editable (21-45 range)` | Change cycle length, verify saved | auth.md - Settings Page |
| `Cycle length rejects values outside range` | Try 20 or 46, verify error | auth.md - User Schema |
| `Notification time editable (HH:MM format)` | Change time, verify saved | auth.md - Settings Page |
| `Timezone editable (IANA format)` | Change timezone, verify saved | auth.md - Settings Page |
| `Changes persist after logout/login` | Edit, logout, login, verify | auth.md - Settings Page |
| `Garmin settings link navigates correctly` | Click manage, verify route | auth.md - Settings Page |
---
### 8. Garmin Integration Tests (`e2e/garmin.spec.ts`)
#### Existing Coverage
- Basic Garmin connection flows
#### Additional Tests Needed
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Connection status shows green when connected` | Verify indicator color | garmin.md - Token Storage |
| `Connection status shows red when disconnected` | Verify indicator color | garmin.md - Features |
| `Days until expiry displays correctly` | Verify countdown | garmin.md - Token Expiration |
| `14-day warning shows yellow indicator` | Approaching expiry warning | garmin.md - Token Expiration |
| `7-day warning shows critical alert` | Critical expiry warning | garmin.md - Token Expiration |
| `Token paste and save works` | Paste tokens, verify saved | garmin.md - OAuth Flow |
| `Disconnect clears connection` | Click disconnect, verify cleared | garmin.md - API Endpoints |
| `Instructions display correctly` | Verify setup instructions visible | garmin.md - OAuth Flow |
| `Expired tokens show red alert` | Expired state displays correctly | garmin.md - Token Expiration |
---
### 9. History Tests (`e2e/history.spec.ts`)
**New file needed** - Tests historical data viewing
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `History page loads with paginated data` | Verify table and pagination | dashboard.md - implied |
| `Date range filter works correctly` | Apply filter, verify results | dashboard.md - implied |
| `Decision status shows correct colors` | REST=red, TRAIN=green, GENTLE=yellow | dashboard.md - Decision Card |
| `All required columns display` | Date, Day, Phase, Decision, BB, HRV, Intensity | dashboard.md - implied |
| `Pagination controls work` | Next/previous page navigation | dashboard.md - implied |
| `Empty state displays when no data` | New user with no history | dashboard.md - implied |
---
### 10. Notifications Tests (`e2e/notifications.spec.ts`)
**New file needed** - Tests notification preferences (not actual email delivery)
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Notification time preference saves` | Set time, verify persisted | notifications.md - Features |
| `Timezone affects notification scheduling` | Set timezone, verify display | notifications.md - Timezone Query |
| `Dashboard shows next notification time` | Display when email expected | notifications.md - Features |
---
### 11. Health & Observability Tests (`e2e/health.spec.ts`)
**New file needed** - Tests monitoring endpoints
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Health endpoint returns 200 when healthy` | GET /api/health succeeds | observability.md - Health Check |
| `Health endpoint responds in under 100ms` | Performance check | observability.md - Success Criteria |
| `Metrics endpoint is accessible` | GET /metrics returns data | observability.md - Prometheus Metrics |
---
### 12. Exercise Plan Tests (`e2e/plan.spec.ts`)
**New file needed** - Tests the plan/reference page
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Plan page shows current cycle status` | Day, phase, days until next | exercise-plan implied |
| `All 5 phase cards display` | Verify all phases shown | cycle.md - Phase System |
| `Phase limits display per phase` | Verify weekly limits | cycle.md - Phase System |
| `Training type displays per phase` | Strength vs rebounding | cycle.md - Phase System |
---
### 13. Dark Mode Tests (`e2e/dark-mode.spec.ts`)
**New file needed** - Tests system preference detection
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Auto-detect dark mode from system preference` | System dark → app dark | dashboard.md - Features |
| `Colors maintain contrast in dark mode` | Minimum 4.5:1 contrast | dashboard.md - Accessibility |
---
### 14. Mobile Responsiveness Tests (`e2e/mobile.spec.ts`)
**New file needed** - Tests mobile viewport behavior
| Test Name | Description | Spec Reference |
|-----------|-------------|----------------|
| `Dashboard single column on mobile (<768px)` | Verify layout change | dashboard.md - Responsive Design |
| `Touch targets minimum 44x44px` | Verify tap target sizes | dashboard.md - Responsive Design |
| `All critical metrics visible without scrolling` | Viewport check | dashboard.md - Success Criteria |
| `Calendar responsive on mobile` | Verify calendar adapts | calendar.md - Acceptance Criteria |
---
### E2E Test Summary
#### New Test Files Needed
1. `e2e/decision-engine.spec.ts` - 9 tests
2. `e2e/cycle.spec.ts` - 11 tests
3. `e2e/history.spec.ts` - 6 tests
4. `e2e/notifications.spec.ts` - 3 tests
5. `e2e/health.spec.ts` - 3 tests
6. `e2e/plan.spec.ts` - 4 tests
7. `e2e/dark-mode.spec.ts` - 2 tests
8. `e2e/mobile.spec.ts` - 4 tests
#### Existing Files to Extend
1. `e2e/auth.spec.ts` - +6 tests
2. `e2e/dashboard.spec.ts` - +35 tests (largest expansion)
3. `e2e/period-logging.spec.ts` - +5 tests
4. `e2e/calendar.spec.ts` - +13 tests
5. `e2e/settings.spec.ts` - +6 tests
6. `e2e/garmin.spec.ts` - +9 tests
#### Total Test Count
- **Current E2E tests**: 64 tests
- **New tests needed**: ~116 tests
- **Across 15 test files** (7 existing + 8 new)
#### Priority Order for Implementation
1. **High Priority** (Core functionality)
- Decision Engine tests
- Cycle Tracking tests
- Dashboard Data Panel tests
2. **Medium Priority** (User workflows)
- Period Logging tests
- Calendar ICS tests
- Settings tests
3. **Lower Priority** (Edge cases & polish)
- Mobile Responsiveness tests
- Dark Mode tests
- History tests
- Health/Observability tests
---
## Notes
1. **TDD Approach:** Each implementation task should follow TDD - write failing tests first, then implement