Skip to content

Commit

Permalink
test: ios ground overlay unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
illuminati1911 committed Jan 9, 2025
1 parent 6a8c0cf commit 5582bcc
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(<GroundOverlay>{object1, object2old},
<GroundOverlay>{object2new, object3}),
mapId: mapId);

final VerificationResult verification =
verify(api.updateGroundOverlays(captureAny, captureAny, captureAny));

final List<PlatformGroundOverlay> toAdd =
verification.captured[0] as List<PlatformGroundOverlay>;
final List<PlatformGroundOverlay> toChange =
verification.captured[1] as List<PlatformGroundOverlay>;
final List<String> toRemove = verification.captured[2] as List<String>;
// 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 <GroundOverlay>{}, <GroundOverlay>{object3}),
mapId: mapId),
throwsAssertionError,
);
});

test('markers send drag event to correct streams', () async {
const int mapId = 1;
const String dragStartId = 'drag-start-marker';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,25 @@ class MockMapsApi extends _i1.Mock implements _i2.MapsApi {
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);

@override
_i4.Future<void> updateGroundOverlays(
List<_i2.PlatformGroundOverlay>? toAdd,
List<_i2.PlatformGroundOverlay>? toChange,
List<String>? idsToRemove,
) =>
(super.noSuchMethod(
Invocation.method(
#updateGroundOverlays,
[
toAdd,
toChange,
idsToRemove,
],
),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);

@override
_i4.Future<_i2.PlatformPoint> getScreenCoordinate(
_i2.PlatformLatLng? latLng) =>
Expand Down

0 comments on commit 5582bcc

Please sign in to comment.