Widget and integration tests for all three components
epic-scenario-push-engagement-ui-task-012 — Write flutter_test widget tests for notification-preferences-screen (toggle persistence, initial load), in-app-notification-banner (auto-dismiss timer, tap navigation, screen-reader announcement), and scenario-notification-detail-view (data rendering, mark-as-read on mount, CTA navigation). Add integration tests verifying the Supabase Realtime trigger path for the banner and the route resolution through scenario-deep-link-router.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Organise test files mirroring the source structure: test/features/notifications/widget/ and test/features/notifications/integration/. For the Supabase Realtime integration test, insert a row into the test notifications table programmatically (via the Supabase admin client in test setup) and listen for the Flutter UI reaction rather than simulating the WebSocket event directly — this tests the real integration path. Use FakeAsync for the auto-dismiss timer test to avoid slow real-time waits in the widget test suite. When mocking Riverpod providers, use ProviderScope(overrides: [...]) rather than injecting mocks into constructors — this is the idiomatic Riverpod testing pattern.
Ensure each test file has a clear tearDown/tearDownAll that disposes ProviderContainers and closes Supabase subscriptions to prevent test pollution. Add a Makefile or script target run_notification_tests for CI convenience.
Testing Requirements
Widget tests: use ProviderScope with overrides to inject mock implementations of all Riverpod providers. Use fake_async / fakeAsync from flutter_test for timer-based tests (auto-dismiss). Use tester.getSemantics() to verify semantic announcements. Use mocktail or mockito for repository and router mocks.
Integration tests: configure a test Supabase project with a seeded notification record. Use flutter_driver or integration_test package. Test the full path: Supabase Realtime event → banner appears → tap → detail screen → deep-link resolved. Capture and assert final route name in the router to confirm correct navigation.
Run integration tests in CI against TestFlight build configuration where feasible.
The in-app notification banner depends on a Supabase Realtime subscription to detect new notification records. If the subscription reconnects slowly after an app resume from background, or if Realtime delivery is delayed under high load, the banner may not appear within the 2-second acceptance criterion.
Mitigation & Contingency
Mitigation: Implement an explicit subscription reconnect handler on app foreground events using Flutter's AppLifecycleState.resumed hook, and add a polling fallback that queries for unread notifications once per app foreground event as a safety net against missed Realtime events.
Contingency: If Realtime proves unreliable in production, promote the polling fallback to the primary mechanism with a 30-second interval, accepting slight latency in exchange for reliability.
Cold-start deep linking (app not running when push notification is tapped) requires deferred navigation after the Flutter engine and Supabase session are fully initialised. If the deep link is consumed before authentication completes, the router may navigate to a protected route without a valid session, causing an error or redirect loop.
Mitigation & Contingency
Mitigation: Implement a deferred navigation queue in scenario-deep-link-router that holds the parsed deep-link target until the auth session restoration lifecycle event fires, following the existing deep-link-handler pattern used in the BankID and Vipps authentication flows.
Contingency: If deferred navigation is not achievable within the epic's scope, fall back to navigating the user to the notification centre (which is always accessible post-login) where the relevant notification record is visible and tappable.