Skip to content

Commit 695e139

Browse files
stuartmorgan-gmauricioluz
authored andcommitted
[google_maps_flutter] Add an interface for test inspection (flutter#6133)
1 parent ca513ca commit 695e139

File tree

6 files changed

+164
-1
lines changed

6 files changed

+164
-1
lines changed

packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.1
2+
3+
* Adds a new interface for inspecting the platform map state in tests.
4+
15
## 2.2.0
26

37
* Adds new versions of `buildView` and `updateOptions` that take a new option

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/google_maps_flutter_platform_interface.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export 'src/events/map_event.dart';
66
export 'src/method_channel/method_channel_google_maps_flutter.dart'
77
show MethodChannelGoogleMapsFlutter;
88
export 'src/platform_interface/google_maps_flutter_platform.dart';
9+
export 'src/platform_interface/google_maps_inspector_platform.dart';
910
export 'src/types/types.dart';

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/platform_interface/google_maps_flutter_platform.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,12 @@ abstract class GoogleMapsFlutterPlatform extends PlatformInterface {
463463
mapOptions: jsonForMapConfiguration(mapConfiguration),
464464
);
465465
}
466+
467+
/// Populates [GoogleMapsFlutterInspectorPlatform.instance] to allow
468+
/// inspecting the platform map state.
469+
@visibleForTesting
470+
void enableDebugInspection() {
471+
throw UnimplementedError(
472+
'enableDebugInspection() has not been implemented.');
473+
}
466474
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
6+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
7+
8+
/// The interface that platform-specific implementations of
9+
/// `google_maps_flutter` can extend to support state inpsection in tests.
10+
///
11+
/// Avoid `implements` of this interface. Using `implements` makes adding any
12+
/// new methods here a breaking change for end users of your platform!
13+
///
14+
/// Do `extends GoogleMapsInspectorPlatform` instead, so new methods
15+
/// added here are inherited in your code with the default implementation (that
16+
/// throws at runtime), rather than breaking your users at compile time.
17+
abstract class GoogleMapsInspectorPlatform extends PlatformInterface {
18+
/// Constructs a GoogleMapsFlutterPlatform.
19+
GoogleMapsInspectorPlatform() : super(token: _token);
20+
21+
static final Object _token = Object();
22+
23+
static GoogleMapsInspectorPlatform? _instance;
24+
25+
/// The instance of [GoogleMapsInspectorPlatform], if any.
26+
///
27+
/// This is usually populated by calling
28+
/// [GoogleMapsFlutterPlatform.enableDebugInspection].
29+
static GoogleMapsInspectorPlatform? get instance => _instance;
30+
31+
/// Platform-specific plugins should set this with their own platform-specific
32+
/// class that extends [GoogleMapsInspectorPlatform] in their
33+
/// implementation of [GoogleMapsFlutterPlatform.enableDebugInspection].
34+
static set instance(GoogleMapsInspectorPlatform? instance) {
35+
if (instance != null) {
36+
PlatformInterface.verify(instance, _token);
37+
}
38+
_instance = instance;
39+
}
40+
41+
/// Returns the minimum and maxmimum zoom level settings.
42+
Future<MinMaxZoomPreference> getMinMaxZoomLevels({required int mapId}) {
43+
throw UnimplementedError('getMinMaxZoomLevels() has not been implemented.');
44+
}
45+
46+
/// Returns true if the compass is enabled.
47+
Future<bool> isCompassEnabled({required int mapId}) {
48+
throw UnimplementedError('isCompassEnabled() has not been implemented.');
49+
}
50+
51+
/// Returns true if lite mode is enabled.
52+
Future<bool> isLiteModeEnabled({required int mapId}) {
53+
throw UnimplementedError('isLiteModeEnabled() has not been implemented.');
54+
}
55+
56+
/// Returns true if the map toolbar is enabled.
57+
Future<bool> isMapToolbarEnabled({required int mapId}) {
58+
throw UnimplementedError('isMapToolbarEnabled() has not been implemented.');
59+
}
60+
61+
/// Returns true if the "my location" button is enabled.
62+
Future<bool> isMyLocationButtonEnabled({required int mapId}) {
63+
throw UnimplementedError(
64+
'isMyLocationButtonEnabled() has not been implemented.');
65+
}
66+
67+
/// Returns true if the traffic overlay is enabled.
68+
Future<bool> isTrafficEnabled({required int mapId}) {
69+
throw UnimplementedError('isTrafficEnabled() has not been implemented.');
70+
}
71+
72+
/// Returns true if the building layer is enabled.
73+
Future<bool> areBuildingsEnabled({required int mapId}) {
74+
throw UnimplementedError('areBuildingsEnabled() has not been implemented.');
75+
}
76+
77+
/// Returns true if rotate gestures are enabled.
78+
Future<bool> areRotateGesturesEnabled({required int mapId}) {
79+
throw UnimplementedError(
80+
'areRotateGesturesEnabled() has not been implemented.');
81+
}
82+
83+
/// Returns true if scroll gestures are enabled.
84+
Future<bool> areScrollGesturesEnabled({required int mapId}) {
85+
throw UnimplementedError(
86+
'areScrollGesturesEnabled() has not been implemented.');
87+
}
88+
89+
/// Returns true if tilt gestures are enabled.
90+
Future<bool> areTiltGesturesEnabled({required int mapId}) {
91+
throw UnimplementedError(
92+
'areTiltGesturesEnabled() has not been implemented.');
93+
}
94+
95+
/// Returns true if zoom controls are enabled.
96+
Future<bool> areZoomControlsEnabled({required int mapId}) {
97+
throw UnimplementedError(
98+
'areZoomControlsEnabled() has not been implemented.');
99+
}
100+
101+
/// Returns true if zoom gestures are enabled.
102+
Future<bool> areZoomGesturesEnabled({required int mapId}) {
103+
throw UnimplementedError(
104+
'areZoomGesturesEnabled() has not been implemented.');
105+
}
106+
107+
/// Returns information about the tile overlay with the given ID.
108+
///
109+
/// The returned object will be synthesized from platform data, so will not
110+
/// be the same Dart object as the original [TileOverlay] provided to the
111+
/// platform interface with that ID, and not all fields (e.g.,
112+
/// [TileOverlay.tileProvider]) will be populated.
113+
Future<TileOverlay?> getTileOverlayInfo(TileOverlayId tileOverlayId,
114+
{required int mapId}) {
115+
throw UnimplementedError('getTileOverlayInfo() has not been implemented.');
116+
}
117+
}

packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_fl
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.2.0
7+
version: 2.2.1
88

99
environment:
1010
sdk: '>=2.12.0 <3.0.0'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
7+
import 'package:mockito/mockito.dart';
8+
9+
void main() {
10+
// Store the initial instance before any tests change it.
11+
final GoogleMapsInspectorPlatform? initialInstance =
12+
GoogleMapsInspectorPlatform.instance;
13+
14+
test('default instance is null', () {
15+
expect(initialInstance, isNull);
16+
});
17+
18+
test('cannot be implemented with `implements`', () {
19+
expect(() {
20+
GoogleMapsInspectorPlatform.instance =
21+
ImplementsGoogleMapsInspectorPlatform();
22+
}, throwsA(isInstanceOf<AssertionError>()));
23+
});
24+
25+
test('can be implement with `extends`', () {
26+
GoogleMapsInspectorPlatform.instance = ExtendsGoogleMapsInspectorPlatform();
27+
});
28+
}
29+
30+
class ImplementsGoogleMapsInspectorPlatform extends Mock
31+
implements GoogleMapsInspectorPlatform {}
32+
33+
class ExtendsGoogleMapsInspectorPlatform extends GoogleMapsInspectorPlatform {}

0 commit comments

Comments
 (0)