From 09620801da7b6127fdc8f42f31dc7fd5a499cae8 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 30 Mar 2023 13:53:21 -0700 Subject: [PATCH 1/2] [go_router] Migrate tests away from old handlePlatformMessage --- .../go_router/example/test/path_and_query_params_test.dart | 4 ++-- packages/go_router/example/test/redirection_test.dart | 4 ++-- packages/go_router/test/go_router_test.dart | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/go_router/example/test/path_and_query_params_test.dart b/packages/go_router/example/test/path_and_query_params_test.dart index b59c8c844077..e4af48b7baee 100644 --- a/packages/go_router/example/test/path_and_query_params_test.dart +++ b/packages/go_router/example/test/path_and_query_params_test.dart @@ -18,7 +18,7 @@ void main() { ByteData message = const JSONMethodCodec().encodeMethodCall( MethodCall('pushRouteInformation', testRouteInformation), ); - await ServicesBinding.instance.defaultBinaryMessenger + await tester.binding.defaultBinaryMessenger .handlePlatformMessage('flutter/navigation', message, (_) {}); await tester.pumpAndSettle(); @@ -34,7 +34,7 @@ void main() { message = const JSONMethodCodec().encodeMethodCall( MethodCall('pushRouteInformation', testRouteInformation), ); - await ServicesBinding.instance.defaultBinaryMessenger + await tester.binding.defaultBinaryMessenger .handlePlatformMessage('flutter/navigation', message, (_) {}); await tester.pumpAndSettle(); diff --git a/packages/go_router/example/test/redirection_test.dart b/packages/go_router/example/test/redirection_test.dart index 21a366eaa628..2d0e286ed3b9 100644 --- a/packages/go_router/example/test/redirection_test.dart +++ b/packages/go_router/example/test/redirection_test.dart @@ -19,7 +19,7 @@ void main() { ByteData message = const JSONMethodCodec().encodeMethodCall( MethodCall('pushRouteInformation', testRouteInformation), ); - await ServicesBinding.instance.defaultBinaryMessenger + await tester.binding.defaultBinaryMessenger .handlePlatformMessage('flutter/navigation', message, (_) {}); await tester.pumpAndSettle(); @@ -36,7 +36,7 @@ void main() { message = const JSONMethodCodec().encodeMethodCall( MethodCall('pushRouteInformation', testRouteInformation), ); - await ServicesBinding.instance.defaultBinaryMessenger + await tester.binding.defaultBinaryMessenger .handlePlatformMessage('flutter/navigation', message, (_) {}); await tester.pumpAndSettle(); diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart index 833c16e0fb7d..5f4828996836 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -28,7 +28,7 @@ Future sendPlatformUrl(String url) async { final ByteData message = const JSONMethodCodec().encodeMethodCall( MethodCall('pushRouteInformation', testRouteInformation), ); - await ServicesBinding.instance.defaultBinaryMessenger + await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .handlePlatformMessage('flutter/navigation', message, (_) {}); } From e2cbd8b1a0bc23b98d4fa92c4cd7a96602059fc2 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 30 Mar 2023 14:02:43 -0700 Subject: [PATCH 2/2] make analyzer happy --- packages/go_router/test/go_router_test.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart index 5f4828996836..271ac0f310ca 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -21,14 +21,14 @@ import 'test_helpers.dart'; const bool enableLogs = false; final Logger log = Logger('GoRouter tests'); -Future sendPlatformUrl(String url) async { +Future sendPlatformUrl(String url, WidgetTester tester) async { final Map testRouteInformation = { 'location': url, }; final ByteData message = const JSONMethodCodec().encodeMethodCall( MethodCall('pushRouteInformation', testRouteInformation), ); - await TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + await tester.binding.defaultBinaryMessenger .handlePlatformMessage('flutter/navigation', message, (_) {}); } @@ -1495,7 +1495,7 @@ void main() { redirected = false; // Directly set the url through platform message. - await sendPlatformUrl('/dummy'); + await sendPlatformUrl('/dummy', tester); await tester.pumpAndSettle(); expect(router.location, '/login'); @@ -1528,7 +1528,7 @@ void main() { expect(router.location, '/'); // Directly set the url through platform message. - await sendPlatformUrl('/dummy'); + await sendPlatformUrl('/dummy', tester); await tester.pumpAndSettle(); expect(router.location, '/dummy'); }); @@ -1631,7 +1631,7 @@ void main() { }); redirected = false; // Directly set the url through platform message. - await sendPlatformUrl('/dummy'); + await sendPlatformUrl('/dummy', tester); await tester.pumpAndSettle(); expect(router.location, '/login'); @@ -2024,7 +2024,7 @@ void main() { final GoRouter router = await createRouter(routes, tester); // Directly set the url through platform message. - await sendPlatformUrl('/dummy/dummy2'); + await sendPlatformUrl('/dummy/dummy2', tester); await tester.pumpAndSettle(); expect(router.location, '/other');