/// A recording fake for the run foreground service. library; import 'package:workout_app/services/foreground_run_client.dart'; /// Stands in for `flutter_foreground_task` on the run screen's side. class FakeForegroundRunClient implements ForegroundRunClient { /// Creates a fake describing a healthy Android device. FakeForegroundRunClient({ this.isSupported = true, this.permissionGranted = true, this.grantOnRequest = true, this.startSucceeds = true, this.onStart, }); @override bool isSupported; /// Whether notifications are already allowed. bool permissionGranted; /// Whether asking for them succeeds. bool grantOnRequest; /// Whether the service starts. bool startSucceeds; /// Runs inside [start], to record what had happened by then. void Function()? onStart; /// `withLocation` of each start. final starts = []; /// Notification redraws as `title|text`, the first being the start. final drawn = []; /// Calls recorded in order. final calls = []; @override Future hasNotificationPermission() async { calls.add('has'); return permissionGranted; } @override Future requestNotificationPermission() async { calls.add('request'); return permissionGranted = grantOnRequest; } @override Future start({ required bool withLocation, required String title, required String text, }) async { calls.add('start'); onStart?.call(); starts.add(withLocation); drawn.add('$title|$text'); return startSucceeds; } @override Future update({required String title, required String text}) async { drawn.add('$title|$text'); } @override Future stop() async => calls.add('stop'); }