import 'dart:async'; import 'package:pipelines_app/features/notification_service/notification_service_bridge.dart'; /// A scripted background service: records calls and reports [current]. class FakeNotificationService implements NotificationServiceBridge { FakeNotificationService({NotificationServiceStatus? status}) : current = status ?? const NotificationServiceStatus( enabled: true, configured: true, state: DeliveryState.connected, notificationsAllowed: true, batteryExempt: false, ); NotificationServiceStatus current; List events = const []; final calls = <(String, Map)>[]; final _changes = StreamController.broadcast(); bool batteryGranted = true; void push(NotificationServiceStatus status) { current = status; _changes.add(status); } NotificationServiceStatus copy({ bool? enabled, DeliveryState? state, bool? notificationsAllowed, bool? batteryExempt, }) => NotificationServiceStatus( enabled: enabled ?? current.enabled, configured: current.configured, state: state ?? current.state, notificationsAllowed: notificationsAllowed ?? current.notificationsAllowed, batteryExempt: batteryExempt ?? current.batteryExempt, ); @override bool get supported => true; @override Stream get changes => _changes.stream; @override Future status() async { calls.add(('status', const {})); return current; } @override Future start() async { calls.add(('start', const {})); return current; } @override Future configure({ required String serverId, required List endpoints, required String cookie, }) async { calls.add(( 'configure', {'serverId': serverId, 'endpoints': endpoints, 'cookie': cookie}, )); return current; } @override Future setEnabled(bool enabled) async { calls.add(('setEnabled', {'enabled': enabled})); current = copy( enabled: enabled, state: enabled ? DeliveryState.connecting : DeliveryState.off, ); return current; } @override Future requestBatteryExemption() async { calls.add(('requestBatteryExemption', const {})); if (batteryGranted) current = copy(batteryExempt: true); return true; } // Not recorded in [calls]: the log is re-read after every action, and the // tests assert on the action calls themselves. @override Future> connectionEvents() async => events; }