Skip to content

Commit

Permalink
wip make test binding a bit more usable
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Oct 12, 2023
1 parent 138ee0f commit 483712a
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions test/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class TestZulipBinding extends ZulipBinding {
FakeFlutterLocalNotificationsPlugin? _notifPlugin;

@override
FlutterLocalNotificationsPlugin get notif {
FakeFlutterLocalNotificationsPlugin get notif {
return (_notifPlugin ??= FakeFlutterLocalNotificationsPlugin());
}
}
Expand All @@ -214,13 +214,6 @@ class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNo
DidReceiveNotificationResponseCallback? onDidReceiveNotificationResponse;
DidReceiveBackgroundNotificationResponseCallback? onDidReceiveBackgroundNotificationResponse;

FlutterLocalNotificationsPlatform? _platform;

List<(
int id, String? title, String? body,
NotificationDetails? notificationDetails, {String? payload}
)> showCalls = [];

@override
Future<bool?> initialize(
InitializationSettings initializationSettings, {
Expand All @@ -234,6 +227,8 @@ class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNo
return true;
}

FlutterLocalNotificationsPlatform? _platform;

@override
T? resolvePlatformSpecificImplementation<T extends FlutterLocalNotificationsPlatform>() {
// This follows the logic of the base class's implementation,
Expand All @@ -260,14 +255,30 @@ class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNo
}
}

/// Consume the log of calls made to [show].
///
/// This returns a list of the arguments to all calls made
/// to [show] since the last call to this method.
List<FlutterLocalNotificationsPluginShowCall> takeShowCalls() {
final result = _showCalls;
_showCalls = [];
return result;
}
List<FlutterLocalNotificationsPluginShowCall> _showCalls = [];

@override
Future<void> show(int id, String? title, String? body,
NotificationDetails? notificationDetails, {String? payload}) async {
assert(initializationSettings != null);
showCalls.add((id, title, body, notificationDetails, payload: payload));
_showCalls.add((id, title, body, notificationDetails, payload: payload));
}
}

typedef FlutterLocalNotificationsPluginShowCall = (
int id, String? title, String? body,
NotificationDetails? notificationDetails, {String? payload}
);

class FakeAndroidFlutterLocalNotificationsPlugin extends Fake implements AndroidFlutterLocalNotificationsPlugin {
List<AndroidNotificationChannel> createdChannels = [];

Expand Down

0 comments on commit 483712a

Please sign in to comment.