Unit test UrlLauncherUtil
epic-no-access-screen-foundation-task-007 — Write unit tests for UrlLauncherUtil covering: successful URL launch, unsupported URL scheme returning error result, platform exception mapped to error result, and fallback feedback callback invoked on failure. Mock the underlying url_launcher canLaunchUrl and launchUrl methods.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
To mock `url_launcher` without brittle platform-channel patching, rely on the constructor-injected interface introduced in task-005. With `mocktail`, create a `MockUrlLauncherInterface extends Mock implements UrlLauncherInterface` and stub `canLaunchUrl` / `launchUrl` with `when(() => mock.canLaunchUrl(any())).thenAnswer(...)`. For the `PlatformException` scenario, use `.thenThrow(PlatformException(code: 'ACTIVITY_NOT_FOUND'))`. The callback invocation tests should use a simple closure that appends to a list: `final calls =
Testing Requirements
Pure unit tests using `flutter_test` and `mocktail`. Mock the `UrlLauncherPlatform` (or the injected interface from task-005) at the constructor level. Use a captured `onFailure` callback (a simple `bool callbackInvoked` flag or a `List
No widget pumping required—this is a plain Dart class test. Target ≥95% line coverage on `url_launcher_util.dart`.
Supabase remote config may be unavailable at app startup (network error, cold start), causing the repository to return no blocked-role list. If the fallback is empty, blocked users could access the app.
Mitigation & Contingency
Mitigation: Define a local constants fallback list of blocked roles compiled into the app binary. Remote config enriches or overrides this list when available.
Contingency: If remote config repeatedly fails in production, pin the blocked-role list to local constants only and disable remote override until the Supabase config endpoint is stabilised.
url_launcher package behaviour differs between iOS and Android (e.g. canLaunchUrl returning false on some Android configurations), leading to silent failures when the admin portal link is tapped.
Mitigation & Contingency
Mitigation: Run canLaunchUrl check before every launch attempt and surface a descriptive inline error message (e.g. 'Could not open link — visit admin.example.org manually') when the check fails.
Contingency: If canLaunchUrl is consistently unreliable on a target platform, replace the tap-to-open pattern with a copyable text field showing the URL as a fallback.