Write widget tests for NotificationDetailView
epic-certificate-expiry-notifications-user-interface-task-011 — Write Flutter widget tests for NotificationDetailView covering: peer mentor layout renders certificate name, expiry date, status indicator, and view-certification-status action; coordinator layout additionally renders trigger-course-enrollment and acknowledge-lapse actions; role-gating ensures wrong-role layouts are never rendered; action buttons dispatch correct BLoC events; accessibility semantics nodes are present and correctly labelled for all interactive controls.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Create a test file at test/features/certificate_expiry_notifications/notification_detail_view_test.dart. Use setUp to create a fresh MockBloc per test to avoid state leakage. Define const test keys for each conditional widget (e.g. const Key('action_view_certification_status')) in the widget implementation so tests can target them reliably without depending on text strings that may be localised.
Use a helper method buildWidget(role, certificationState) to reduce boilerplate across test cases. For BLoC event verification, prefer bloc_test's verify() helper over capturing events manually. Ensure Semantics wrapper is added to each interactive button in the widget under test before writing the semantics assertions — do not write tests that will fail against the current implementation unless a corresponding implementation fix is included in the same PR.
Testing Requirements
Use flutter_test with WidgetTester. Wrap the widget under test in a BlocProvider supplying a MockBloc or FakeBloc seeded with a CertificationExpiryState containing a stub certification entity. Use tester.pumpWidget with a MaterialApp wrapper. For role-gating, inject role via the appropriate BLoC or dependency-injected auth context.
Use expect(find.byKey(...), findsOneWidget) and expect(find.byKey(...), findsNothing) assertions for role-conditional widgets. Verify BLoC event dispatch with bloc_test verify helpers or by capturing emitted events on the FakeBloc. Run tester.ensureSemantics() and use SemanticsController to assert label presence. Aim for 100% branch coverage across role variants and action dispatch paths.
The persistent banner must remain visible across app sessions and only disappear when a specific backend condition is met (renewal or coordinator acknowledgement). If the BLoC state is not properly sourced from the notification record repository on every app launch, the banner may disappear prematurely or fail to reappear after a session restart.
Mitigation & Contingency
Mitigation: Drive the banner's visibility exclusively from a Supabase real-time subscription on the notification records table filtered by mentor_id and acknowledged_at IS NULL. Never persist banner visibility state locally. Write an integration test that restarts the BLoC and verifies the banner reappears from the database source.
Contingency: If real-time subscriptions introduce latency or connection reliability issues in offline-first scenarios, add a local cache flag that is only cleared when the repository confirms the acknowledgement write succeeded, with a cache TTL of 24 hours as a fallback.
The notification detail view must conditionally render coordinator-specific actions based on the authenticated user's role. Incorrect role resolution could expose the 'Acknowledge Lapse' action to peer mentors or hide it from coordinators, breaking the workflow and potentially allowing unauthorised state changes.
Mitigation & Contingency
Mitigation: Source the role check from the existing role_state_manager BLoC that is already authenticated against Supabase role claims. Do not rely on a local flag. The coordinator acknowledgement service backend also validates role server-side, providing defence in depth. Add widget tests that render the detail view with mentor and coordinator role fixtures and assert the presence or absence of coordinator actions.
Contingency: If a role resolution bug is found in production, immediately disable the acknowledge action via a feature flag and patch the role check in a hotfix release. The server-side validation in the coordinator acknowledgement service ensures no actual state change can occur even if the button is incorrectly rendered.