Write widget tests for BadgeCardWidget
epic-achievement-badges-foundation-task-013 — Write Flutter widget tests for BadgeCardWidget covering: earned badge renders unlocked icon and correct name label, locked badge renders locked icon with muted styling, milestone progress indicator displays correct percentage, semantic labels are present and correctly describe earned state and progress for screen reader accessibility, and tapping an earned card fires an optional onTap callback. Run flutter_test with accessibility checks enabled.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
Wrap each testWidgets call with tester.ensureSemantics() and dispose the handle in tearDown or at end of test to avoid state leakage. Use find.byType(Semantics) or find.bySemanticsLabel() to assert on accessibility. For locked/muted styling, assert using find.byWidgetPredicate() checking Opacity or color property of Text/Icon widgets against design token values — avoid hardcoded hex colors in assertions. Stub BadgeIconAssetManager by passing a known asset path string directly to the widget rather than relying on asset resolution in tests (asset resolution can fail in test environments without full asset bundle setup).
Use pumpAndSettle() only when animations are present; prefer pump() for static widget tests. Follow the existing test conventions in the project test/ directory.
Testing Requirements
All tests are widget-level using flutter_test testWidgets(). Write at minimum 6 test cases: (1) earned badge full render, (2) locked badge muted render, (3) milestone progress percentage display, (4) semantic label for earned state, (5) semantic label for locked/progress state, (6) onTap callback invocation. Enable SemanticsHandle via tester.ensureSemantics() in each accessibility test and assert using tester.getSemantics(). Use a shared BadgeCardWidget factory helper to reduce boilerplate.
No mocking frameworks needed beyond simple stub model instances. Tests must be deterministic — avoid any DateTime.now() in widget state without injection.
Badge criteria are stored as structured JSON in badge_definitions. If the JSON schema for criteria (threshold counts, streak lengths, training completion flags) is not well-defined upfront, the evaluation service will be built against a moving target, requiring costly migrations and refactors.
Mitigation & Contingency
Mitigation: Define and document the criteria JSON schema in a shared type file before any repository code is written. Review the schema with all three organisations' badge requirements — especially Blindeforbundet's honorar thresholds — and version the JSON schema using a 'criteria_version' field from day one.
Contingency: If the criteria schema must change after services are built, write a Supabase migration to backfill existing rows and add a migration version column. Keep the evaluation service criteria parser isolated behind an interface so only one function needs updating.
Badge icon assets may not yet exist or may fail WCAG 2.2 AA contrast validation (minimum 3:1 for graphical objects) when rendered over design-token backgrounds. Missing or non-compliant icons could block UI epic delivery for Blindeforbundet, for whom screen reader and visual accessibility is non-negotiable.
Mitigation & Contingency
Mitigation: During this epic, implement the contrast-ratio validator in badge-icon-asset-manager and run it as a Flutter test against all candidate icon assets early. Coordinate with the design team to provide WCAG-compliant SVG icons in both locked and unlocked variants before the UI epic begins.
Contingency: If assets are late or fail contrast checks, ship placeholder icons that are guaranteed compliant (solid design-token colour fills with text labels) and swap in final assets post-QA without requiring a code change.