Write widget and integration tests for search bar, view switcher, and screen
epic-contact-list-management-ui-components-task-012 — Write Flutter widget tests for ContactSearchBar verifying debounce fires after 300ms, clear button resets the field, and semantics labels are present. Write widget tests for ContactViewSwitcher verifying toggle state changes call onChanged, org-label overrides render correctly, and visibility flag hides the widget. Write integration tests for ContactListScreen verifying role-aware rendering, correct empty states, and that searching filters the visible card list. All tests use mock data from task-001.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 4 - 323 tasks
Can start after Tier 3 completes
Implementation Notes
Debounce tests are the trickiest part: wrap the WidgetTester pump sequence inside fakeAsync, type into the field with tester.enterText, then call fakeAsync.elapse(Duration(milliseconds: 299)) and assert callback NOT called, then elapse 1ms more and assert called. For ContactViewSwitcher visibility test, pass visible: false and assert find.byType(ContactViewSwitcher).evaluate().isEmpty or that it has zero size. Integration tests should use a FakeContactRepository injected via Riverpod ProviderScope.overrides or BLoC dependency injection — never hit Supabase. Keep fixtures in a shared test/fixtures/ directory so all test files import from the same source.
Use pump and settle carefully — avoid pumpAndSettle timeouts on animated widgets by using pump(Duration(milliseconds: 300)) instead.
Testing Requirements
Split tests across three files: contact_search_bar_test.dart, contact_view_switcher_test.dart, contact_list_screen_integration_test.dart. Use fakeAsync and FakeTimers from flutter_test to control debounce timing — do not use real delays. For integration tests, override the Riverpod/BLoC provider with a mock repository that returns fixtures from task-001. Test role-aware rendering by injecting different UserRole values via provider override.
Verify filter behaviour by asserting findsNWidgets count before and after entering a query. Run all tests headlessly with flutter test — no device required.
Design token color values used in role badges, certification status indicators, and availability chips may not meet the WCAG 2.2 AA contrast ratio of 4.5:1 when rendered against card backgrounds, requiring rework after accessibility review and potentially blocking acceptance sign-off.
Mitigation & Contingency
Mitigation: Run the contrast-ratio-validator on every new token combination during widget development. Enforce the CI accessibility lint runner on all PRs touching visualization components, and validate against the contrast-safe-color-palette before finalizing card designs.
Contingency: If contrast failures are found late, adjust token values in the design token theme centrally — since all widgets consume design tokens rather than hardcoded colors, all affected widgets will be corrected by a single token update without per-widget changes.
The ContactViewSwitcher is required for Barnekreftforeningen but must not appear for other organizations. If the organization labels provider does not yet expose a reliable feature flag for this widget, it may render universally or be conditionally hidden in an inconsistent way, breaking the role-specific layout contract.
Mitigation & Contingency
Mitigation: Implement view switcher visibility as a constructor parameter on ContactListScreen injected from a provider, defaulting to hidden. Document the integration point for the org labels provider so the flag can be wired without changing the widget's API.
Contingency: If org labels integration is delayed beyond this epic, use a feature flag constant keyed to the Barnekreftforeningen organization ID as a temporary gate, with a tracked issue to replace it with the runtime labels provider before general release.