-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Context
Overall Jest test coverage is 13.5% (50 test files, 793 tests). Core services like problemService (79%) and sessionService (73%) are decent, but huge gaps exist:
- 20 of 24 DB store files have zero tests
- 8 of 9 problem service files are untested (including files modified for the enrichment fix in bug: Hints used card on Overview page not reflecting accurate data #247)
- Schedule/recalibration services — the spaced repetition engine — are at 0-3%
- Retry/resilience layer is essentially untested
Target: 55-60% overall, with 75%+ on critical business logic.
Scope: Jest unit tests only. The browser integration tests (core-business-tests.js) are complementary and remain unchanged.
Phase 1 — Critical Algorithms (13% → 25-28%)
Locks down the session assembly pipeline, enrichment fix, normalizer, and schedule service.
1.1 problemNormalizerHelpers.test.js (~14 tests)
Source: src/shared/services/problem/problemNormalizerHelpers.js (93 lines, ~0%) → target 90%
- Pure functions, no mocks needed
buildSessionMetadata,buildAttemptTracking,buildSpacedRepetitionData,buildAttemptsArray, etc.
1.2 problemServiceHelpers.test.js (~28 tests)
Source: src/shared/services/problem/problemServiceHelpers.js (127 lines, 21%) → target 85%
enrichReviewProblem— validates the enrichment fix from the difficulty crashnormalizeReviewProblem— slug fallback chain, attempt_stats conversionfilterValidReviewProblems— validates required fields
1.3 problemNormalizer.test.js (~24 tests)
Source: src/shared/services/problem/problemNormalizer.js (221 lines, 61%) → target 85%
validateRawProblem— missing difficulty (the bug), missing tags, non-numeric idnormalizeProblem— id coercion, title case, metadata flagsnormalizeProblems— array validation, error wrapping with index
1.4 scheduleService.test.js (~20 tests)
Source: src/shared/services/schedule/scheduleService.js (138 lines, 3%) → target 70%
isDueForReview— date boundariesisRecentlyAttempted— box-level skip intervals, relaxationgetDailyReviewSchedule— sorting, limits, error handling
1.5 problemServiceSession.test.js (~50 tests)
Source: src/shared/services/problem/problemServiceSession.js (590 lines, 45%) → target 80%
addTriggeredReviewsToSession— validates enrichment fix, max 2 per sessionaddFallbackProblems— validates enrichment + difficulty/tags filtering fixaddReviewProblemsToSession,addNewProblemsToSession,addPassiveMasteredReviewsdeduplicateById,problemSortingCriteria
Phase 2 — Data Layer & Resilience (25-28% → 38-42%)
2.1 problems.test.js (~25 tests) — src/shared/db/stores/problems.js
2.2 standard_problems.test.js (~15 tests) — src/shared/db/stores/standard_problems.js
2.3 tag_mastery.test.js (~22 tests) — src/shared/db/stores/tag_mastery.js
2.4 attempts.test.js (~16 tests) — src/shared/db/stores/attempts.js
2.5 storageService.enhanced.test.js (~22 tests) — src/shared/services/storage/storageService.js (12% → 60%)
2.6 indexedDBRetryService.test.js (~25 tests) — circuit breaker, exponential backoff, abort controller
Phase 3 — Session Features (38-42% → 48-53%)
3.1 recalibrationService.test.js (~30 tests) — decay logic, diagnostic sessions, welcome-back strategy
3.2 sessionHabitLearning.test.js (~25 tests) — streaks, cadence, circuit breaker
3.3 interviewService.test.js (~28 tests) — mode configs, readiness assessment, transfer metrics
3.4 problemServiceRetry.test.js (~18 tests) — retry wrappers, abort controller cancellation
Phase 4 — Monitoring & Infrastructure (48-53% → 55-60%)
4.1 recalibrationHelpers.test.js (~12 tests)
4.2 crashReporter.test.js (~10 tests)
4.3 ErrorReportService.test.js (~10 tests)
4.4 PerformanceMonitor.test.js (~10 tests)
4.5 logger.test.js (~8 tests)
4.6 problem_relationships.enhanced.test.js (~12 tests)
Coverage Projection
| Phase | New Files | New Tests | Cumulative Coverage |
|---|---|---|---|
| Phase 1 | 5 | ~136 | 25-28% |
| Phase 2 | 6 | ~125 | 38-42% |
| Phase 3 | 4 | ~101 | 48-53% |
| Phase 4 | 6 | ~62 | 55-60% |
| Total | 21 | ~424 | 55-60% |
Shared Infrastructure
- Extend
mockDataFactories.jswithcreateMockReviewProblem,createMockStandardProblem,createMockAttemptWithStats - Create
dbTestHelper.jsin Phase 2 forfake-indexeddbschema setup and seeding
Implementation Order (Phase 1)
problemNormalizerHelpers.test.js— pure functions, zero mocks, fast startproblemServiceHelpers.test.js— validates enrichment fixproblemNormalizer.test.js— validates the validation layerscheduleService.test.js— small file, pure scheduling logicproblemServiceSession.test.js— largest, depends on understanding helpers
Verification
After each phase:
npm run test:coverage— confirm cumulative coverage meets phase targetnpm test— all existing + new tests pass- Verify no cross-phase test dependencies