Widget tests for WrappedSummaryScreen UI states
epic-annual-impact-summary-orchestration-task-017 — Write widget tests for all WrappedSummaryScreen UI states: loading skeleton, loaded first slide, loaded slide navigation, offline banner with stale timestamp, sharing loading overlay, error state with retry action, and empty state when no summary data is available. Mock WrappedSummaryBloc stream to inject each state and assert correct widget tree rendering.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 9 - 22 tasks
Can start after Tier 8 completes
Implementation Notes
Create a test helper file (e.g. test/helpers/wrapped_summary_test_helpers.dart) with factory functions that build the mock BLoC and inject standard test states — this reduces boilerplate across the 7 tests. For the offline state, ensure the WrappedSummaryBloc state model includes an isOffline bool and lastFetchedAt DateTime so the widget can render the banner and timestamp — if these fields don't exist yet, coordinate with the task that defines the state model. For the sharing loading overlay state, the BLoC state may be a variant like WrappedSummarySharing extends WrappedSummaryState — assert that InteractiveViewer or GestureDetector on the slide area has ignoringSemantics: true or equivalent blocking during this state.
Use tester.pumpWidget() followed by tester.pump() (not pumpAndSettle()) in most cases to avoid infinite animation loops from any shimmer or slide-transition animations — pass explicit durations where needed. Follow existing test file conventions (e.g. snake_case file names, _test.dart suffix, test group labelling).
Testing Requirements
This task IS the testing requirement. Use flutter_test's testWidgets for all tests. Inject mock BLoC states using bloc_test's MockBloc with whenListen to emit a stream of states. Wrap the widget under test in a MaterialApp + BlocProvider
Use find.byType() and find.byKey() to assert widget presence/absence. For the retry test, use tester.tap(find.byType(RetryButton)) and then verify(mockBloc.add(argThat(isA
If the device transitions between online and offline states while the user is mid-session in the wrapped screen, the BLoC may emit conflicting state transitions (loaded → error → offline) that cause visual flickering or an inconsistent UI state such as showing the offline banner over an already-loaded summary.
Mitigation & Contingency
Mitigation: Implement a connectivity stream listener in the BLoC that only triggers a state re-evaluation when transitioning from online to offline, not on every connectivity event. Once a summary is in the Loaded state, the BLoC should not transition to error/offline unless the user explicitly requests a refresh. Store the last-loaded data in BLoC state so it survives connectivity changes.
Contingency: If state flickering is observed in testing, add a minimum 3-second debounce on connectivity state changes before the BLoC reacts, and display a non-blocking top banner rather than replacing the entire screen state.
The push notification deep-link to the wrapped-summary-screen must work correctly whether the app is in the foreground, background, or terminated state. Handling all three app launch states on both iOS and Android is a common source of edge-case bugs, particularly when authentication state must be restored before the deep link can be resolved.
Mitigation & Contingency
Mitigation: Implement deep-link handling through the existing notification-deep-link-handler component which already manages app-state-aware routing. Define the wrapped-summary route in the navigation config early in the epic so the router is ready before notification dispatch is wired. Test all three app states (foreground, background, terminated) explicitly in the QA checklist.
Contingency: If terminated-state deep-linking fails on specific platforms, fall back to launching the app to the home screen with an in-app notification banner prompting the user to open their summary, rather than direct deep-link navigation.
The wrapped-summary-screen manages a large number of AnimationController instances (one or more per slide) via the wrapped-animation-controller. If disposal is not triggered correctly when the user exits mid-flow (e.g., via system back gesture or deep-link away), memory leaks will accumulate across session navigation.
Mitigation & Contingency
Mitigation: Implement screen disposal via Flutter's dispose() lifecycle method calling a single wrapped-animation-controller.disposeAll() method that iterates the named controller registry. Write a test that navigates to the screen, starts animations, then navigates away and verifies no active AnimationController listeners remain using Flutter's test binding.
Contingency: If disposal bugs are detected in production via memory profiling, patch by converting all AnimationControllers to use AutomaticKeepAliveClientMixin false and wrap each slide in a widget that disposes its own controller when removed from the widget tree.