-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[google_maps] Add initial google_maps tests #1409
Changes from all commits
f219dc6
7da145e
9919710
5873d0b
b28925e
4e32075
52e305e
759299a
6e07157
e73d48f
097d2ac
60798e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,10 @@ | |
<meta-data | ||
android:name="com.google.android.gms.version" | ||
android:value="@integer/google_play_services_version" /> | ||
<!-- Update this value to your google maps api key. --> | ||
<meta-data | ||
android:name="com.google.android.geo.API_KEY" | ||
android:value="YOUR KEY HERE" /> | ||
android:value="${mapsApiKey}" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment saying this should be replaced(for those running locally) |
||
<activity | ||
android:name=".MainActivity" | ||
android:launchMode="singleTop" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,14 @@ | |
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application | ||
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
- (BOOL)application:(UIApplication*)application | ||
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | ||
// Provide the GoogleMaps API key. | ||
[GMSServices provideAPIKey:@"YOUR KEY HERE"]; | ||
NSString* mapsApiKey = [[NSProcessInfo processInfo] environment][@"MAPS_API_KEY"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be confusing for users, what do you think about still using the key "YOUR KEY HERE" if the env variable is not set? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking of making it so that in the future for local runs we require the api key to be set via env var. That way we do not need to edit these files, and flutter run will automatically pick them up. But for short term, i'm cool with making this be |
||
if ([mapsApiKey length] == 0) { | ||
mapsApiKey = @"YOUR KEY HERE"; | ||
} | ||
[GMSServices provideAPIKey:mapsApiKey]; | ||
|
||
// Register Flutter plugins. | ||
[GeneratedPluginRegistrant registerWithRegistry:self]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:flutter/services.dart'; | ||
|
||
/// Inspect Google Maps state using the platform SDK. | ||
/// | ||
/// This class is primarily used for testing. The methods on this | ||
/// class should call "getters" on the GoogleMap object or equivalent | ||
/// on the platform side. | ||
class GoogleMapInspector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add a doc comment explaining the role of this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused about why this is its own class. Why not put methods on the |
||
GoogleMapInspector(this._channel); | ||
|
||
final MethodChannel _channel; | ||
|
||
Future<bool> isCompassEnabled() async { | ||
return await _channel.invokeMethod<bool>('map#isCompassEnabled'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_driver/driver_extension.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:google_maps_flutter/google_maps_flutter.dart'; | ||
|
||
import 'google_map_inspector.dart'; | ||
import 'test_widgets.dart'; | ||
|
||
const CameraPosition _kInitialCameraPosition = | ||
CameraPosition(target: LatLng(0, 0)); | ||
|
||
void main() { | ||
final Completer<String> allTestsCompleter = Completer<String>(); | ||
enableFlutterDriverExtension(handler: (_) => allTestsCompleter.future); | ||
|
||
tearDownAll(() => allTestsCompleter.complete(null)); | ||
|
||
test('testCompassToggle', () async { | ||
final Completer<GoogleMapInspector> inspectorCompleter = | ||
Completer<GoogleMapInspector>(); | ||
|
||
await pumpWidget(Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: GoogleMap( | ||
initialCameraPosition: _kInitialCameraPosition, | ||
compassEnabled: false, | ||
onMapCreated: (GoogleMapController controller) { | ||
final GoogleMapInspector inspector = | ||
// ignore: invalid_use_of_visible_for_testing_member | ||
GoogleMapInspector(controller.channel); | ||
inspectorCompleter.complete(inspector); | ||
}, | ||
), | ||
)); | ||
|
||
final GoogleMapInspector inspector = await inspectorCompleter.future; | ||
bool compassEnabled = await inspector.isCompassEnabled(); | ||
expect(compassEnabled, false); | ||
|
||
await pumpWidget(Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: GoogleMap( | ||
initialCameraPosition: _kInitialCameraPosition, | ||
compassEnabled: true, | ||
onMapCreated: (GoogleMapController controller) { | ||
fail("OnMapCreated should get called only once."); | ||
}, | ||
), | ||
)); | ||
|
||
compassEnabled = await inspector.isCompassEnabled(); | ||
expect(compassEnabled, true); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter_driver/flutter_driver.dart'; | ||
|
||
Future<void> main() async { | ||
final FlutterDriver driver = await FlutterDriver.connect(); | ||
await driver.requestData(null, timeout: const Duration(minutes: 1)); | ||
driver.close(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
|
||
Future<void> pumpWidget(Widget widget) { | ||
runApp(widget); | ||
return WidgetsBinding.instance.endOfFrame; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a bugfix? if so be clear about it in the PR description, changelog, etc (probably worth considering splitting this to a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the PR description.