Integration and widget tests for org selection and context switcher
epic-organization-selection-and-onboarding-ui-task-010 — Write widget and integration tests covering: (1) OrgSelectionScreen renders org list from mocked OrganizationRepository; (2) tapping an org card triggers OrgSelectionService and shows loading state; (3) service error renders localized error widget; (4) OnboardingProgressIndicator is shown for new users and hidden for returning users; (5) MultiOrgContextSwitcher renders all user orgs with active org highlighted; (6) confirmation dialog appears before swap and cancellation aborts the switch; (7) successful swap updates the active context indicator. All tests must pass without real Supabase calls.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 7 - 84 tasks
Can start after Tier 6 completes
Implementation Notes
Structure the test file with a shared setUp() that builds the minimal ProviderScope override tree needed for both screens. Create lightweight fake implementations (not Mockito mocks) for OrganizationRepository and OrgSelectionService — fakes are easier to read and maintain. For the confirmation dialog test, use tester.tap(find.byKey(Key('confirm-org-switch-button'))) — coordinate with the UI task to ensure consistent Key assignments. For the OnboardingProgressIndicator visibility test, inject a UserSessionFake that returns isNewUser: true or false — avoid relying on Supabase auth state.
For the loading state test, use a Completer-backed fake that holds the future open so you can assert the loading indicator before resolving. Verify the active org indicator by asserting a specific widget (e.g., find.byKey(Key('active-org-checkmark-${org.id}'))) is present. Document all Key values used in tests with a comment linking to the widget file where they are defined.
Testing Requirements
All tests are widget tests using flutter_test with WidgetTester. Use Riverpod's ProviderScope with overrides to inject mock implementations of OrganizationRepository and OrgSelectionService — do not use real Supabase. For BLoC-based state, use a mock BLoC or emit states directly in test setup. Test each of the 7 scenarios in its own test() block inside a group().
Use tester.pump() and tester.pumpAndSettle() appropriately: pump() after triggering async actions to advance one frame, pumpAndSettle() only when waiting for animations. Assert widget presence using find.byType() and find.byKey(). Assert widget absence using findsNothing. Verify method calls on mocks using Mockito or manual call-counting fakes.
No golden/screenshot tests required for this task.
OrgSelectionScreen and OrgContextSwitcher render partner-specific logos, colors, and text from dynamic data. Golden tests (pixel-comparison screenshots) will fail whenever branding assets are updated in the backend, causing CI failures that block unrelated PRs and eroding developer trust in the test suite.
Mitigation & Contingency
Mitigation: Use fixture-based golden tests with static mock Organization models containing embedded test assets rather than network-fetched assets. Separate branding asset acceptance tests into a dedicated CI job that only runs on branding-related PRs and is maintained by the design team.
Contingency: If golden test maintenance overhead becomes excessive, replace pixel-comparison goldens with semantic widget tests that assert widget tree structure and key property values, reserving golden tests for only the most stable, design-critical elements.
Several partner organizations (especially Blindeforbundet) have users who rely entirely on VoiceOver or TalkBack. Complex branded card layouts with overlaid logos, names, and selection states are notoriously difficult to make fully accessible; missing semantics or incorrect focus order could make the selection screen completely unusable for screen reader users before launch.
Mitigation & Contingency
Mitigation: Involve an accessibility specialist in the design review before any widget implementation begins. Use Flutter's Semantics widget with explicit label, hint, and button role on OrgCardWidget. Conduct manual screen reader testing on both iOS (VoiceOver) and Android (TalkBack) for every sprint that touches these screens, not just before release.
Contingency: If full WCAG compliance cannot be achieved within the sprint, implement a simplified text-list fallback mode that activates when the system detects an active screen reader, presenting orgs as plain accessible list tiles instead of the branded card layout.