Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[url_launcher] and [url_launcher_platform_interface] Fix tests broken…
Browse files Browse the repository at this point in the history
… my ChannelBuffers migration (#3966)

* Remove redundant test.

This test broke because it relies on implementation details that are no longer valid. We believe it is redundant with the test above it and the test in the interface package at this point.

* ChannelBuffers is actually async

...so we have to run the test using runAsync otherwise the future will never complete.
  • Loading branch information
Hixie authored May 22, 2021
1 parent 7b47511 commit bca7c9f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 106 deletions.
104 changes: 0 additions & 104 deletions packages/url_launcher/url_launcher/test/link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/link.dart';
import 'package:url_launcher/src/link.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

import 'mock_url_launcher_platform.dart';

final MethodCodec _codec = const JSONMethodCodec();

void main() {
late MockUrlLauncher mock;

PlatformMessageCallback? realOnPlatformMessage;
setUp(() {
mock = MockUrlLauncher();
UrlLauncherPlatform.instance = mock;
realOnPlatformMessage = window.onPlatformMessage;
});
tearDown(() {
window.onPlatformMessage = realOnPlatformMessage;
});

group('$Link', () {
Expand Down Expand Up @@ -147,99 +137,5 @@ void main() {
// Restore the original function.
pushRouteToFrameworkFunction = originalPushFunction;
});

testWidgets('sends router platform messages for internal route names',
(WidgetTester tester) async {
// Intercept messages sent to the engine.
final List<MethodCall> engineCalls = <MethodCall>[];
SystemChannels.navigation.setMockMethodCallHandler((MethodCall call) {
engineCalls.add(call);
return Future<void>.value();
});

// Intercept messages sent to the framework.
final List<MethodCall> frameworkCalls = <MethodCall>[];
window.onPlatformMessage = (
String name,
ByteData? data,
PlatformMessageResponseCallback? callback,
) {
frameworkCalls.add(_codec.decodeMethodCall(data));
realOnPlatformMessage!(name, data, callback);
};

final Uri uri = Uri.parse('/foo/bar');
FollowLink? followLink;

final Link link = Link(
uri: uri,
builder: (BuildContext context, FollowLink? followLink2) {
followLink = followLink2;
return Container();
},
);
await tester.pumpWidget(MaterialApp.router(
routeInformationParser: MockRouteInformationParser(),
routerDelegate: MockRouterDelegate(
builder: (BuildContext context) => link,
),
));

engineCalls.clear();
frameworkCalls.clear();
await followLink!();

// Shouldn't use url_launcher when uri is an internal route name.
expect(mock.canLaunchCalled, isFalse);
expect(mock.launchCalled, isFalse);

// Sends route information update to the engine.
expect(engineCalls, hasLength(1));
expect(
engineCalls.single,
isMethodCall('routeInformationUpdated', arguments: <dynamic, dynamic>{
'location': '/foo/bar',
'state': null
}),
);

// Also pushes route information update to the Router.
expect(frameworkCalls, hasLength(1));
expect(
frameworkCalls.single,
isMethodCall(
'pushRouteInformation',
arguments: <dynamic, dynamic>{
'location': '/foo/bar',
'state': null,
},
),
);
});
});
}

class MockRouteInformationParser extends Mock
implements RouteInformationParser<bool> {
@override
Future<bool> parseRouteInformation(RouteInformation routeInformation) {
return Future<bool>.value(true);
}
}

class MockRouterDelegate extends Mock implements RouterDelegate<Object> {
MockRouterDelegate({required this.builder});

final WidgetBuilder builder;

@override
Widget build(BuildContext context) {
return builder(context);
}

@override
Future<void> setInitialRoutePath(Object configuration) async {}

@override
Future<void> setNewRoutePath(Object configuration) async {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
));
expect(find.byKey(Key('home')), findsOneWidget);
expect(find.byKey(Key('a')), findsNothing);
await pushRouteNameToFramework(null, '/a');
await tester.runAsync(() => pushRouteNameToFramework(null, '/a'));
// start animation
await tester.pump();
// skip past animation (5s is arbitrary, just needs to be long enough)
Expand All @@ -36,7 +36,7 @@ void main() {
));
expect(find.byKey(Key('/')), findsOneWidget);
expect(find.byKey(Key('/a')), findsNothing);
await pushRouteNameToFramework(null, '/a');
await tester.runAsync(() => pushRouteNameToFramework(null, '/a'));
// start animation
await tester.pump();
// skip past animation (5s is arbitrary, just needs to be long enough)
Expand Down

0 comments on commit bca7c9f

Please sign in to comment.