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

# WEEK9 TESTING PLAN

# Week 9: Testing & QA Implementation Plan

## Overview

Comprehensive testing infrastructure and test coverage for the AI-Powered Photo Journaling iOS app. This week focuses on building a robust test suite with unit tests, widget tests, integration tests, and test utilities.

**Implementation Week**: Week 9
**Linear Ticket**: OVE-55
**Branch**: `feature/OVE-55-comprehensive-testing`
**Estimated Time**: 6-8 hours
**Target Coverage**: 80%+ for critical paths

***

## Testing Strategy

### Coverage Goals

| Layer                  | Target Coverage | Priority |
| ---------------------- | --------------- | -------- |
| Business Logic (BLoCs) | 90%+            | Critical |
| Services               | 85%+            | Critical |
| Repositories           | 80%+            | High     |
| Widgets                | 75%+            | High     |
| Utils/Helpers          | 80%+            | Medium   |
| UI Integration         | Key flows       | Medium   |

### Testing Pyramid

```
                    /\
                   /  \
                  / E2E \          ← 5-10 critical flows
                 /      \
                /--------\
               /          \
              / Integration \      ← 20-30 integration tests
             /              \
            /----------------\
           /                  \
          /   Widget Tests     \   ← 50-80 widget tests
         /                      \
        /------------------------\
       /                          \
      /        Unit Tests          \  ← 150-200 unit tests
     /______________________________\
```

***

## Phase 1: Testing Infrastructure Setup (Tasks 1-3)

### Task 1: Update pubspec.yaml with Test Dependencies

**Goal**: Add mocktail and additional testing packages

**Dependencies to add**:

```yaml theme={null}
dev_dependencies:
  flutter_test:
    sdk: flutter

  # Existing
  flutter_lints: ^5.0.0
  bloc_test: ^9.1.5
  build_runner: ^2.4.7
  drift_dev: ^2.14.0

  # NEW: Better mocking (replacing mockito)
  mocktail: ^1.0.1

  # NEW: Test utilities
  fake_async: ^1.3.1
  network_image_mock: ^2.1.1

  # NEW: Golden tests
  golden_toolkit: ^0.15.0
```

**Rationale**:

* **mocktail**: Better than mockito, no code generation needed, type-safe
* **fake\_async**: Control time in tests (for animations, debouncing)
* **network\_image\_mock**: Mock network images in widget tests
* **golden\_toolkit**: Visual regression testing

**Commit**: `chore(test): add comprehensive testing dependencies`

***

### Task 2: Create Test Helpers and Mock Data Utilities

**Goal**: Reusable test utilities for consistent testing

**Files to create**:

#### `test/helpers/test_helpers.dart`

```dart theme={null}
// Pump and settle utilities
// Widget testing helpers
// Golden test helpers
// Matcher utilities
```

#### `test/helpers/mock_data.dart`

```dart theme={null}
// Mock journal entries
// Mock users
// Mock photos
// Mock emotions
// Mock AI responses
```

#### `test/helpers/test_blocs.dart`

```dart theme={null}
// BLoC test utilities
// State builders
// Event builders
```

**Commit**: `test(helpers): add test utilities and mock data generators`

***

### Task 3: Create Mock Repository Classes

**Goal**: Mock implementations for all repositories

**Files to create**:

#### `test/mocks/repository_mocks.dart`

```dart theme={null}
class MockEntryRepository extends Mock implements EntryRepository {}
class MockPhotoRepository extends Mock implements PhotoRepository {}
class MockUserRepository extends Mock implements UserRepository {}
class MockAuthRepository extends Mock implements AuthRepository {}
```

**Commit**: `test(mocks): add mock repository implementations`

***

## Phase 2: Unit Tests - Services Layer (Tasks 4-9)

### Task 4: Test SyncService

**File**: `test/core/services/sync_service_test.dart` (already exists - enhance)

**Test coverage**:

* ✅ Sync on connectivity change
* ✅ Batch sync entries
* ✅ Handle sync conflicts
* ✅ Retry failed syncs
* NEW: Sync queue priority
* NEW: Offline mode behavior
* NEW: Partial sync recovery

**Commit**: `test(sync): enhance SyncService test coverage`

***

### Task 5: Test PhotoCacheService

**File**: `test/core/services/photo_cache_service_test.dart` (already exists - enhance)

**Test coverage**:

* ✅ Cache photos locally
* ✅ Retrieve from cache
* NEW: Cache eviction policy
* NEW: Memory pressure handling
* NEW: Preloading strategies
* NEW: Cache size limits

**Commit**: `test(cache): enhance PhotoCacheService test coverage`

***

### Task 6: Test OptimizedImageCache

**File**: `test/core/services/optimized_image_cache_test.dart`

**Test coverage**:

* Separate cache managers (photos, thumbnails, avatars)
* Memory/disk limits
* Image size optimization
* Preloading behavior
* Cache eviction
* Error handling

**Commit**: `test(cache): add OptimizedImageCache comprehensive tests`

***

### Task 7: Test ErrorHandler

**File**: `test/core/error/error_handler_test.dart`

**Test coverage**:

* Global error capture
* Error dialog display
* Retry functionality
* Error logging
* Network errors
* AI errors
* Authentication errors

**Commit**: `test(error): add ErrorHandler comprehensive tests`

***

### Task 8: Test ApiClient

**File**: `test/core/network/api_client_test.dart`

**Test coverage**:

* GET/POST/PUT/DELETE requests
* Authentication headers
* Error handling
* Retry logic
* Request/response interceptors
* Timeout handling

**Commit**: `test(network): add ApiClient comprehensive tests`

***

### Task 9: Test Validators

**File**: `test/core/utils/validators_test.dart`

**Test coverage**:

* Email validation
* Password validation
* Text length validation
* Date validation
* Edge cases and boundary conditions

**Commit**: `test(utils): add comprehensive validator tests`

***

## Phase 3: Unit Tests - BLoC Layer (Tasks 10-15)

### Task 10: Test AuthBloc

**File**: `test/features/auth/presentation/bloc/auth_bloc_test.dart`

**Test coverage**:

* Login success/failure
* Logout
* Sign up flow
* Password reset
* Apple Sign-In
* Token refresh
* Session management

**Commit**: `test(auth): add AuthBloc comprehensive tests`

***

### Task 11: Test EntryBloc

**File**: `test/features/entry/presentation/bloc/entry_bloc_test.dart`

**Test coverage**:

* Create entry
* Update entry
* Delete entry
* Load entry
* Entry validation
* Photo attachment
* Emotion tagging

**Commit**: `test(entry): add EntryBloc comprehensive tests`

***

### Task 12: Test TimelineBloc

**File**: `test/features/timeline/presentation/bloc/timeline_bloc_test.dart`

**Test coverage**:

* Load entries
* Pagination
* Pull to refresh
* Date navigation
* Empty state
* Error state

**Commit**: `test(timeline): add TimelineBloc comprehensive tests`

***

### Task 13: Test SearchBloc

**File**: `test/features/search/presentation/bloc/search_bloc_test.dart`

**Test coverage**:

* Keyword search
* Emotion filter (OR logic)
* Date range filter
* Combined filters
* Debounced search
* Clear filters

**Commit**: `test(search): add SearchBloc comprehensive tests`

***

### Task 14: Test OfflineBloc

**File**: `test/features/offline/offline_bloc_test.dart` (already exists - enhance)

**Test coverage**:

* ✅ Offline mode detection
* ✅ Queue operations
* NEW: Sync when online
* NEW: Conflict resolution
* NEW: Partial sync

**Commit**: `test(offline): enhance OfflineBloc test coverage`

***

### Task 15: Test PremiumBloc

**File**: `test/features/premium/presentation/bloc/premium_bloc_test.dart`

**Test coverage**:

* Check subscription status
* Purchase flow
* Restore purchases
* Subscription validation
* Free tier limits
* Premium feature unlocks

**Commit**: `test(premium): add PremiumBloc comprehensive tests`

***

## Phase 4: Widget Tests (Tasks 16-22)

### Task 16: Test EntryCard Widget

**File**: `test/features/timeline/presentation/widgets/entry_card_test.dart`

**Test coverage**:

* Renders photo correctly
* Shows emotions
* Shows text preview
* Tap navigation
* Hero animation
* Loading state

**Commit**: `test(widget): add EntryCard comprehensive tests`

***

### Task 17: Test EmotionPicker Widget

**File**: `test/features/entry/presentation/widgets/emotion_picker_test.dart`

**Test coverage**:

* Displays all 12 emotions
* Multi-select behavior
* Deselect behavior
* Category grouping
* Done button
* Accessibility

**Commit**: `test(widget): add EmotionPicker comprehensive tests`

***

### Task 18: Test LoadingSkeletons

**File**: `test/shared/widgets/loading/loading_skeletons_test.dart`

**Test coverage**:

* TimelineGridSkeleton renders
* EntryDetailSkeleton renders
* Animation behavior
* Shimmer effect
* Accessibility labels

**Commit**: `test(widget): add loading skeleton tests`

***

### Task 19: Test AnimatedIndicators

**File**: `test/shared/widgets/loading/animated_indicators_test.dart`

**Test coverage**:

* PulsingDotsIndicator animation
* BreathingCircleIndicator animation
* AILoadingIndicator message rotation
* ProgressIndicator percentage
* Accessibility

**Commit**: `test(widget): add animated indicator tests`

***

### Task 20: Test CustomButtons (AnimatedButton, BouncyButton, RippleButton)

**File**: `test/core/interactions/button_animations_test.dart`

**Test coverage**:

* AnimatedButton scale animation
* BouncyButton spring animation
* RippleButton expanding effect
* Tap behavior
* Disabled state
* Accessibility

**Commit**: `test(widget): add custom button animation tests`

***

### Task 21: Test ErrorDisplay Widget

**File**: `test/core/error/error_display_test.dart`

**Test coverage**:

* Shows error message
* Retry button works
* Network error state
* Empty state
* Accessibility

**Commit**: `test(widget): add error display widget tests`

***

### Task 22: Test AccessibleButton/Image/TextField

**File**: `test/core/accessibility/accessible_widgets_test.dart`

**Test coverage**:

* Semantic labels present
* Minimum touch target (44x44)
* VoiceOver hints
* Dynamic Type scaling
* Focus behavior

**Commit**: `test(widget): add accessible widget tests`

***

## Phase 5: Integration Tests (Tasks 23-27)

### Task 23: Test Entry Creation Flow

**File**: `test/integration/entry_creation_flow_test.dart`

**Test coverage**:

* Camera → AI prompts → Emotion selection → Save
* Photo picker → Text entry → Save
* Error handling throughout flow
* Offline creation and sync

**Commit**: `test(integration): add entry creation flow tests`

***

### Task 24: Test Authentication Flow

**File**: `test/integration/auth_flow_test.dart`

**Test coverage**:

* Sign up → Onboarding → Timeline
* Login → Timeline
* Logout → Welcome screen
* Password reset flow

**Commit**: `test(integration): add authentication flow tests`

***

### Task 25: Test Search and Filter Flow

**File**: `test/integration/search_filter_flow_test.dart`

**Test coverage**:

* Search by keyword → Results
* Filter by emotion → Results
* Filter by date range → Results
* Combined filters → Results
* Clear filters → Full timeline

**Commit**: `test(integration): add search and filter flow tests`

***

### Task 26: Test Premium Subscription Flow

**File**: `test/integration/premium_flow_test.dart`

**Test coverage**:

* Hit free tier limit → Paywall
* Tap subscribe → Purchase flow (mocked)
* Subscription active → Premium features unlocked
* Restore purchases

**Commit**: `test(integration): add premium subscription flow tests`

***

### Task 27: Test Offline Sync Flow

**File**: `test/integration/offline_sync_flow_test.dart`

**Test coverage**:

* Create entry offline → Queue
* Go online → Auto sync
* Conflict resolution
* Partial sync recovery

**Commit**: `test(integration): add offline sync flow tests`

***

## Phase 6: Test Utilities and Golden Tests (Tasks 28-30)

### Task 28: Golden Tests for Key Widgets

**File**: `test/golden/widget_golden_test.dart`

**Test coverage**:

* EntryCard in light/dark mode
* EmotionPicker in light/dark mode
* Timeline grid layout
* Error states
* Empty states

**Commit**: `test(golden): add golden tests for key widgets`

***

### Task 29: Performance Tests

**File**: `test/performance/scroll_performance_test.dart`

**Test coverage**:

* Timeline scrolling with 100+ entries
* Memory usage during scroll
* Frame rendering performance
* Image loading performance

**Commit**: `test(performance): add scroll performance tests`

***

### Task 30: Test Coverage Report and Documentation

**File**: `app/TEST_COVERAGE_REPORT.md`

**Content**:

* Overall coverage percentage
* Coverage by layer (BLoC, Services, Widgets)
* Untested critical paths
* Recommendations for improvement
* Running tests instructions
* CI/CD integration

**Commit**: `docs(test): add comprehensive test coverage report`

***

## Summary Statistics

### Total Tasks: 30

**Phase 1: Infrastructure** (3 tasks)

* Test dependencies
* Test helpers and mock data
* Mock repositories

**Phase 2: Services Unit Tests** (6 tasks)

* SyncService, PhotoCacheService, OptimizedImageCache
* ErrorHandler, ApiClient, Validators

**Phase 3: BLoC Unit Tests** (6 tasks)

* AuthBloc, EntryBloc, TimelineBloc
* SearchBloc, OfflineBloc, PremiumBloc

**Phase 4: Widget Tests** (7 tasks)

* Entry/Timeline widgets
* Loading states
* Buttons and interactions
* Accessibility widgets

**Phase 5: Integration Tests** (5 tasks)

* Entry creation, Auth flow
* Search/filter, Premium flow
* Offline sync

**Phase 6: Advanced Testing** (3 tasks)

* Golden tests
* Performance tests
* Coverage report

### Expected Test Files: 35+

**Expected Test Count**: 200-300 individual tests

**Expected Coverage**:

* BLoCs: 90%+
* Services: 85%+
* Widgets: 75%+
* Overall: 80%+

***

## Commands Reference

### Run all tests

```bash theme={null}
cd app
flutter test
```

### Run specific test file

```bash theme={null}
flutter test test/features/auth/presentation/bloc/auth_bloc_test.dart
```

### Run tests with coverage

```bash theme={null}
flutter test --coverage
genhtml coverage/lcov.info -o coverage/html
open coverage/html/index.html
```

### Run golden tests

```bash theme={null}
flutter test --update-goldens  # Update baselines
flutter test                    # Compare against baselines
```

### Run integration tests

```bash theme={null}
flutter test integration_test/
```

***

## Success Criteria

* [ ] All 30 tasks completed
* [ ] 200+ individual tests written
* [ ] 80%+ overall test coverage
* [ ] 90%+ BLoC test coverage
* [ ] All critical paths tested
* [ ] Golden tests for key widgets
* [ ] Integration tests for major flows
* [ ] Test coverage report generated
* [ ] All tests passing in CI/CD
* [ ] Documentation complete

***

## Next Steps After Week 9

**For App Security Engineer**:

* Review test coverage for security-critical paths
* Verify authentication tests are comprehensive
* Check permission handling tests

**For Senior QA Engineer**:

* Review test coverage report
* Identify manual test scenarios not covered
* Execute manual testing checklist
* Performance testing on devices

**For DevOps Engineer**:

* Integrate tests into CI/CD pipeline
* Set up automated test runs on PR
* Configure coverage reporting
* Set up test result notifications

***

**Implementation Start**: November 15, 2025
**Estimated Completion**: November 15-16, 2025
**Developer**: @frontend-developer
