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

Commit 608d42f

Browse files
committed
[google_maps_flutter] Adds traffic layer tests
1 parent b37e26a commit 608d42f

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
329329
result.success(googleMap.getUiSettings().isMyLocationButtonEnabled());
330330
break;
331331
}
332+
case "map#isTrafficEnabled":
333+
{
334+
result.success(googleMap.isTrafficEnabled());
335+
break;
336+
}
332337
case "map#setStyle":
333338
{
334339
String mapStyle = (String) call.arguments;

packages/google_maps_flutter/example/test_driver/google_map_inspector.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ class GoogleMapInspector {
4949
Future<bool> isMyLocationButtonEnabled() async {
5050
return await _channel.invokeMethod<bool>('map#isMyLocationButtonEnabled');
5151
}
52+
53+
Future<bool> isTrafficEnabled() async {
54+
return await _channel.invokeMethod<bool>('map#isTrafficEnabled');
55+
}
5256
}

packages/google_maps_flutter/example/test_driver/google_maps.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,31 @@ void main() {
375375
expect(secondVisibleRegion.contains(newCenter), isTrue);
376376
});
377377

378+
test('testTraffic', () async {
379+
final Key key = GlobalKey();
380+
final Completer<GoogleMapInspector> inspectorCompleter =
381+
Completer<GoogleMapInspector>();
382+
383+
await pumpWidget(Directionality(
384+
textDirection: TextDirection.ltr,
385+
child: GoogleMap(
386+
key: key,
387+
initialCameraPosition: _kInitialCameraPosition,
388+
trafficEnabled: true,
389+
onMapCreated: (GoogleMapController controller) {
390+
final GoogleMapInspector inspector =
391+
// ignore: invalid_use_of_visible_for_testing_member
392+
GoogleMapInspector(controller.channel);
393+
inspectorCompleter.complete(inspector);
394+
},
395+
),
396+
));
397+
398+
final GoogleMapInspector inspector = await inspectorCompleter.future;
399+
final bool isTrafficEnabled = await inspector.isTrafficEnabled();
400+
expect(isTrafficEnabled, true);
401+
});
402+
378403
test('testMyLocationButtonToggle', () async {
379404
final Key key = GlobalKey();
380405
final Completer<GoogleMapInspector> inspectorCompleter =

packages/google_maps_flutter/ios/Classes/GoogleMapController.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
229229
} else if ([call.method isEqualToString:@"map#isMyLocationButtonEnabled"]) {
230230
NSNumber* isMyLocationButtonEnabled = @(_mapView.settings.myLocationButton);
231231
result(isMyLocationButtonEnabled);
232+
} else if ([call.method isEqualToString:@"map#isTrafficEnabled"]) {
233+
NSNumber* isTrafficEnabled = @(_mapView.trafficEnabled);
234+
result(isTrafficEnabled);
232235
} else if ([call.method isEqualToString:@"map#setStyle"]) {
233236
NSString* mapStyle = [call arguments];
234237
NSString* error = [self setMapStyle:mapStyle];

packages/google_maps_flutter/test/fake_maps_controllers.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class FakePlatformGoogleMap {
4747

4848
bool myLocationEnabled;
4949

50+
bool trafficEnabled;
51+
5052
bool myLocationButtonEnabled;
5153

5254
List<dynamic> padding;
@@ -341,6 +343,9 @@ class FakePlatformGoogleMap {
341343
if (options.containsKey('myLocationButtonEnabled')) {
342344
myLocationButtonEnabled = options['myLocationButtonEnabled'];
343345
}
346+
if (options.containsKey('trafficEnabled')) {
347+
trafficEnabled = options['trafficEnabled'];
348+
}
344349
if (options.containsKey('padding')) {
345350
padding = options['padding'];
346351
}

packages/google_maps_flutter/test/google_map_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,33 @@ void main() {
498498

499499
expect(platformGoogleMap.padding, <double>[60, 50, 80, 70]);
500500
});
501+
502+
testWidgets('Can update traffic', (WidgetTester tester) async {
503+
await tester.pumpWidget(
504+
const Directionality(
505+
textDirection: TextDirection.ltr,
506+
child: GoogleMap(
507+
initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)),
508+
trafficEnabled: false,
509+
),
510+
),
511+
);
512+
513+
final FakePlatformGoogleMap platformGoogleMap =
514+
fakePlatformViewsController.lastCreatedView;
515+
516+
expect(platformGoogleMap.trafficEnabled, false);
517+
518+
await tester.pumpWidget(
519+
const Directionality(
520+
textDirection: TextDirection.ltr,
521+
child: GoogleMap(
522+
initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)),
523+
trafficEnabled: true,
524+
),
525+
),
526+
);
527+
528+
expect(platformGoogleMap.trafficEnabled, true);
529+
});
501530
}

0 commit comments

Comments
 (0)