From 5582bcc73bf1d5783d7d406d9c5d2eb6c462537e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Thu, 9 Jan 2025 10:26:57 +0800 Subject: [PATCH] test: ios ground overlay unit tests --- .../test/google_maps_flutter_ios_test.dart | 139 ++++++++++++++++++ .../google_maps_flutter_ios_test.mocks.dart | 19 +++ 2 files changed, 158 insertions(+) diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.dart b/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.dart index 2aef6b0e3913..0b2633efafbd 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.dart @@ -612,6 +612,145 @@ void main() { expectTileOverlay(toAdd.first, object3); }); + test('updateGroundOverlays passes expected arguments', () async { + const int mapId = 1; + final (GoogleMapsFlutterIOS maps, MockMapsApi api) = + setUpMockMap(mapId: mapId); + + final AssetMapBitmap image = AssetMapBitmap( + 'assets/red_square.png', + imagePixelRatio: 1.0, + ); + + final GroundOverlay object1 = GroundOverlay.fromBounds( + groundOverlayId: const GroundOverlayId('1'), + bounds: LatLngBounds( + southwest: const LatLng(10, 20), northeast: const LatLng(30, 40)), + image: image); + final GroundOverlay object2old = GroundOverlay.fromBounds( + groundOverlayId: const GroundOverlayId('2'), + bounds: LatLngBounds( + southwest: const LatLng(10, 20), northeast: const LatLng(30, 40)), + image: image); + final GroundOverlay object2new = object2old.copyWith( + visibleParam: false, + bearingParam: 10, + clickableParam: false, + transparencyParam: 0.5, + zIndexParam: 100, + ); + final GroundOverlay object3 = GroundOverlay.fromPosition( + groundOverlayId: const GroundOverlayId('3'), + position: const LatLng(10, 20), + width: 100, + image: image, + zoomLevel: 14.0); + await maps.updateGroundOverlays( + GroundOverlayUpdates.from({object1, object2old}, + {object2new, object3}), + mapId: mapId); + + final VerificationResult verification = + verify(api.updateGroundOverlays(captureAny, captureAny, captureAny)); + + final List toAdd = + verification.captured[0] as List; + final List toChange = + verification.captured[1] as List; + final List toRemove = verification.captured[2] as List; + // Object one should be removed. + expect(toRemove.length, 1); + expect(toRemove.first, object1.groundOverlayId.value); + // Object two should be changed. + { + expect(toChange.length, 1); + final PlatformGroundOverlay firstChanged = toChange.first; + expect(firstChanged.anchor?.x, object2new.anchor?.dx); + expect(firstChanged.anchor?.y, object2new.anchor?.dy); + expect(firstChanged.bearing, object2new.bearing); + expect(firstChanged.bounds?.northeast.latitude, + object2new.bounds?.northeast.latitude); + expect(firstChanged.bounds?.northeast.longitude, + object2new.bounds?.northeast.longitude); + expect(firstChanged.bounds?.southwest.latitude, + object2new.bounds?.southwest.latitude); + expect(firstChanged.bounds?.southwest.longitude, + object2new.bounds?.southwest.longitude); + expect(firstChanged.visible, object2new.visible); + expect(firstChanged.clickable, object2new.clickable); + expect(firstChanged.zIndex, object2new.zIndex); + expect(firstChanged.position?.latitude, object2new.position?.latitude); + expect(firstChanged.position?.longitude, object2new.position?.longitude); + expect(firstChanged.zoomLevel, object2new.zoomLevel); + expect(firstChanged.transparency, object2new.transparency); + expect( + firstChanged.image.bitmap.runtimeType, + GoogleMapsFlutterIOS.platformBitmapFromBitmapDescriptor( + object2new.image) + .bitmap + .runtimeType); + } + // Object three should be added. + { + expect(toAdd.length, 1); + final PlatformGroundOverlay firstAdded = toAdd.first; + expect(firstAdded.anchor?.x, object3.anchor?.dx); + expect(firstAdded.anchor?.y, object3.anchor?.dy); + expect(firstAdded.bearing, object3.bearing); + expect(firstAdded.bounds?.northeast.latitude, + object3.bounds?.northeast.latitude); + expect(firstAdded.bounds?.northeast.longitude, + object3.bounds?.northeast.longitude); + expect(firstAdded.bounds?.southwest.latitude, + object3.bounds?.southwest.latitude); + expect(firstAdded.bounds?.southwest.longitude, + object3.bounds?.southwest.longitude); + expect(firstAdded.visible, object3.visible); + expect(firstAdded.clickable, object3.clickable); + expect(firstAdded.zIndex, object3.zIndex); + expect(firstAdded.position?.latitude, object3.position?.latitude); + expect(firstAdded.position?.longitude, object3.position?.longitude); + expect(firstAdded.zoomLevel, object3.zoomLevel); + expect(firstAdded.transparency, object3.transparency); + expect( + firstAdded.image.bitmap.runtimeType, + GoogleMapsFlutterIOS.platformBitmapFromBitmapDescriptor( + object3.image) + .bitmap + .runtimeType); + } + }); + + test( + 'updateGroundOverlays throws assertion error on unsupported ground overlays', + () async { + const int mapId = 1; + final (GoogleMapsFlutterIOS maps, MockMapsApi api) = + setUpMockMap(mapId: mapId); + + final AssetMapBitmap image = AssetMapBitmap( + 'assets/red_square.png', + imagePixelRatio: 1.0, + ); + + final GroundOverlay object3 = GroundOverlay.fromPosition( + groundOverlayId: const GroundOverlayId('1'), + position: const LatLng(10, 20), + // Assert should be thrown because zoomLevel is not set for position-based + // ground overlay on iOS. + // ignore: avoid_redundant_argument_values + zoomLevel: null, + image: image); + + expect( + () async => maps.updateGroundOverlays( + GroundOverlayUpdates.from( + const {}, {object3}), + mapId: mapId), + throwsAssertionError, + ); + }); + test('markers send drag event to correct streams', () async { const int mapId = 1; const String dragStartId = 'drag-start-marker'; diff --git a/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.mocks.dart b/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.mocks.dart index e94375876150..6cc9404de70b 100644 --- a/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.mocks.dart +++ b/packages/google_maps_flutter/google_maps_flutter_ios/test/google_maps_flutter_ios_test.mocks.dart @@ -225,6 +225,25 @@ class MockMapsApi extends _i1.Mock implements _i2.MapsApi { returnValueForMissingStub: _i4.Future.value(), ) as _i4.Future); + @override + _i4.Future updateGroundOverlays( + List<_i2.PlatformGroundOverlay>? toAdd, + List<_i2.PlatformGroundOverlay>? toChange, + List? idsToRemove, + ) => + (super.noSuchMethod( + Invocation.method( + #updateGroundOverlays, + [ + toAdd, + toChange, + idsToRemove, + ], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override _i4.Future<_i2.PlatformPoint> getScreenCoordinate( _i2.PlatformLatLng? latLng) =>