|
| 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 'dart:async'; |
| 6 | +import 'dart:js_util'; |
| 7 | + |
| 8 | +import 'package:google_maps_flutter_web/google_maps_flutter_web.dart'; |
| 9 | +import 'package:flutter/widgets.dart'; |
| 10 | +import 'package:flutter_test/flutter_test.dart'; |
| 11 | +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; |
| 12 | +import 'package:mockito/annotations.dart'; |
| 13 | +import 'package:mockito/mockito.dart'; |
| 14 | +// ignore: implementation_imports |
| 15 | +import 'package:google_maps_flutter_web/src/third_party/js_types/google_maps.dart' |
| 16 | +as gmaps; |
| 17 | + |
| 18 | +import 'google_maps_controller_test.mocks.dart'; |
| 19 | +import 'gmaps_mocks.dart'; |
| 20 | + |
| 21 | +const String _kCloudMapId = 'test-map-id'; |
| 22 | + |
| 23 | +@GenerateMocks(<Type>[ |
| 24 | + StreamController, |
| 25 | +]) |
| 26 | +void main() { |
| 27 | + late MockStreamController<MapEvent<Object?>> streamController; |
| 28 | + late MockMap map; |
| 29 | + |
| 30 | + setUp(() { |
| 31 | + streamController = MockStreamController<MapEvent<Object?>>(); |
| 32 | + map = MockMap(); |
| 33 | + when(map.onTilesloaded).thenAnswer((_) => Stream<void>.value(null)); |
| 34 | + when(map.onClick).thenAnswer( |
| 35 | + (_) => Stream<gmaps.MapMouseEvent>.value(MockMapMouseEvent())); |
| 36 | + when(map.onRightclick).thenAnswer( |
| 37 | + (_) => Stream<gmaps.MapMouseEvent>.value(MockMapMouseEvent())); |
| 38 | + when(map.onBoundsChanged).thenAnswer((_) => Stream<void>.value(null)); |
| 39 | + when(map.onIdle).thenAnswer((_) => Stream<void>.value(null)); |
| 40 | + when(map.isZoomDefined()).thenReturn(true); |
| 41 | + when(map.zoom).thenReturn(10); |
| 42 | + }); |
| 43 | + |
| 44 | + GoogleMapController createController({ |
| 45 | + MapWidgetConfiguration widgetConfiguration = const MapWidgetConfiguration( |
| 46 | + initialCameraPosition: CameraPosition(target: LatLng(0, 0)), |
| 47 | + ), |
| 48 | + MapObjects mapObjects = const MapObjects(), |
| 49 | + MapConfiguration mapConfiguration = const MapConfiguration(), |
| 50 | + }) { |
| 51 | + return GoogleMapController( |
| 52 | + mapId: 0, |
| 53 | + streamController: streamController, |
| 54 | + widgetConfiguration: widgetConfiguration, |
| 55 | + mapObjects: mapObjects, |
| 56 | + mapConfiguration: mapConfiguration, |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + testWidgets( |
| 61 | + 'disables rotate control when fortyFiveDegreeImageryEnabled is disabled', |
| 62 | + (WidgetTester tester) async { |
| 63 | + gmaps.MapOptions? capturedOptions; |
| 64 | + final GoogleMapController controller = createController( |
| 65 | + mapConfiguration: |
| 66 | + const MapConfiguration(fortyFiveDegreeImageryEnabled: false)); |
| 67 | + controller.debugSetOverrides(createMap: (_, gmaps.MapOptions options) { |
| 68 | + capturedOptions = options; |
| 69 | + return map; |
| 70 | + }); |
| 71 | + |
| 72 | + controller.init(); |
| 73 | + |
| 74 | + expect(capturedOptions, isNotNull); |
| 75 | + expect(capturedOptions!.rotateControl, isFalse); |
| 76 | + expect(capturedOptions!.tilt, 0); |
| 77 | + }); |
| 78 | + |
| 79 | + testWidgets('style is ignored when mapId is set', |
| 80 | + (WidgetTester tester) async { |
| 81 | + gmaps.MapOptions? capturedOptions; |
| 82 | + const String style = |
| 83 | + '''[{ "featureType": "poi.park", "elementType": "labels.text.fill", "stylers": [{"color": "#6b9a76"}]}]'''; |
| 84 | + final GoogleMapController controller = createController( |
| 85 | + mapConfiguration: const MapConfiguration( |
| 86 | + style: style, |
| 87 | + mapId: _kCloudMapId, |
| 88 | + )); |
| 89 | + controller.debugSetOverrides(createMap: (_, gmaps.MapOptions options) { |
| 90 | + capturedOptions = options; |
| 91 | + return map; |
| 92 | + }); |
| 93 | + |
| 94 | + controller.init(); |
| 95 | + |
| 96 | + expect(capturedOptions, isNotNull); |
| 97 | + expect(capturedOptions!.styles, isNull, |
| 98 | + reason: 'styles should be null when mapId is provided.'); |
| 99 | + expect(capturedOptions!.mapId, _kCloudMapId); |
| 100 | + }); |
| 101 | +} |
0 commit comments