Integration Test: End-to-End Declaration Flow
epic-driver-and-confidentiality-management-ui-task-015 — Write integration tests covering the complete declaration flow: coordinator views driver assignment list → taps pending declaration badge → declaration send screen loads template → coordinator sends declaration → driver receives and opens acknowledgement screen → scrolls full text → checks confirmation checkbox → submits acknowledgement with timestamp → assignment list refreshes badge to acknowledged state. Test both success and network error recovery paths.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 6 - 158 tasks
Can start after Tier 5 completes
Implementation Notes
Structure the test file as a group() per flow phase (coordinator phase, driver phase, error recovery phase) to keep failures locatable. Use a TestWidgetsFlutterBinding and a shared fakeSupabaseClient fixture initialized in setUpAll(). For the badge refresh step, prefer testing BLoC state changes (expect the BLoC to emit AssignmentAcknowledged state) rather than relying on Supabase Realtime subscription timing, which is flaky in CI. The scroll gate check should assert that the submit button's enabled state is false when scrollController.position is not at maxScrollExtent.
Use pumpAndSettle() carefully — if animations are involved in badge transition, cap settle duration to avoid infinite loops. Document each test with a one-line comment referencing the flow step number (e.g., // Step 5: Driver scrolls full declaration text).
Testing Requirements
Use flutter integration_test package for end-to-end widget tree tests running on a real device or emulator. Write at minimum: (1) happy-path test covering all 8 flow steps, (2) network error on send with recovery, (3) network error on acknowledgement with recovery, (4) edge case where driver attempts to submit before scrolling full text. Use bloc_test or manual BLoC emission fakes to control state transitions. Seed the fake Supabase client with fixture data representing a pending assignment.
Assert UI state after each BLoC emission using expect(find.byKey(...), findsOneWidget) patterns. Aim for 100% coverage of the declared flow steps. Run tests in CI via flutter test integration_test/.
The declaration acknowledgement screen has the most complex accessibility requirements of any screen in this feature: scrollable long-form legal text, a conditional checkbox that is only enabled after reading, and a timestamp capture. Incorrect focus management or missing semantics annotations could fail VoiceOver navigation or cause the screen reader to announce the checkbox as available before the driver has scrolled, undermining the legal validity of the acknowledgement.
Mitigation & Contingency
Mitigation: Build the acknowledgement screen against the WCAG 2.2 AA checklist from the start, not as a post-hoc audit. Use semantics-wrapper-widget and live-region-announcer from the platform's accessibility toolkit. Include a VoiceOver test session in the acceptance criteria with a tester using the screen reader.
Contingency: If WCAG compliance cannot be fully achieved within the sprint, ship the screen with a documented list of accessibility gaps and a follow-up sprint commitment. Do not block the declaration workflow launch if the core interaction works but a non-critical semantics annotation is missing.
Drivers receive a push notification with a deep link to the declaration acknowledgement screen for a specific assignment. If the deep link handler does not correctly route to the right screen and assignment context — particularly when the app is launched cold from the notification — the driver may see a blank screen or the wrong declaration.
Mitigation & Contingency
Mitigation: Implement and test all three notification scenarios: app foregrounded, app backgrounded, and cold start. Use the platform's existing deep-link-handler infrastructure. Add integration tests that simulate notification tap events and assert correct screen and data loading.
Contingency: If cold-start deep link routing proves unreliable, implement a notification-centre fallback where the driver can find the pending declaration from the notification centre screen, ensuring the workflow can always complete even if the direct deep link fails.
If the driver-feature-flag-guard has any rendering edge case — such as a brief flash of driver UI before the flag value is loaded, or a guard that fails open on a flag service error — driver-specific UI elements could be momentarily visible to coordinators in organizations that have not opted in, causing confusion and potentially a support escalation.
Mitigation & Contingency
Mitigation: Default the guard to rendering nothing (not a loading indicator) until the flag value is definitively resolved. Treat flag service errors as flag-disabled to fail closed. Write widget tests covering the loading, disabled, and enabled states including the error case.
Contingency: If fail-closed cannot be guaranteed within the sprint, add a server-side RLS check on the driver assignment endpoints so that even if the UI guard leaks, the data layer refuses to return driver data for organizations without the flag enabled.