Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add initial ios integration tests #12

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ void runTests() {
transparency: 0.7,
bearing: 10,
zIndex: 10,
zoomLevel: 14.0,
);

void expectGroundOverlayEquals(
Expand Down Expand Up @@ -549,6 +550,12 @@ void runTests() {
expect(response.width, source.width);
expect(response.height, source.height);
}

// Only iOS supports zoomLevel
if (isIOS) {
expect(response.zoomLevel, source.zoomLevel);
}

// Only Android (using position) and iOS supports `anchor`
if ((isAndroid && source.position != null) || isIOS) {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ class GroundOverlayBodyState extends State<GroundOverlayBody> {
groundOverlayId: id,
image: assetMapBitmap,
position: _currentGroundOverlayPos,
width: _dimensions.dx,
height: _dimensions.dy,
width: _dimensions.dx, // Android only
height: _dimensions.dy, // Android only
zoomLevel: 14.0, // iOS only
anchor: _anchor,
onTap: () {
_onGroundOverlayTapped();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;

Expand Down Expand Up @@ -996,7 +995,7 @@ void googleMapsTests() {
},
// TODO(cyanglaz): un-skip the test when we can test this on CI with API key enabled.
// https://github.com/flutter/flutter/issues/57057
skip: Platform.isAndroid);
skip: true);

testWidgets(
'set tileOverlay correctly',
Expand Down Expand Up @@ -1499,13 +1498,10 @@ void googleMapsTests() {
expect(response.clickable, source.clickable);
expect(response.zIndex, source.zIndex);

// Only Android supports width and height
if (Platform.isAndroid) {
expect(response.width, source.width);
expect(response.height, source.height);
}
expect(response.width, source.width);
expect(response.height, source.height);
// Only Android (using position) and iOS supports `anchor`
if ((Platform.isAndroid && source.position != null) || Platform.isIOS) {
if (source.position != null) {
expect(
response.anchor?.dx,
moreOrLessEquals(source.anchor!.dx, epsilon: _floatTolerance),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const double _kInitialZoomLevel = 5;
const CameraPosition _kInitialCameraPosition =
CameraPosition(target: _kInitialMapCenter, zoom: _kInitialZoomLevel);
const String _kCloudMapId = '000000000000000'; // Dummy map ID.
const double _floatTolerance = 1e-6;

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -1292,6 +1293,256 @@ void main() {
));
await controllerCompleter.future;
});

group('GroundOverlay', () {
final LatLngBounds kGroundOverlayBounds = LatLngBounds(
southwest: const LatLng(37.77483, -122.41942),
northeast: const LatLng(37.78183, -122.39105),
);

final GroundOverlay groundOverlayBounds1 = GroundOverlay.fromBounds(
groundOverlayId: const GroundOverlayId('bounds_1'),
bounds: kGroundOverlayBounds,
image: AssetMapBitmap(
'assets/red_square.png',
imagePixelRatio: 1.0,
),
);

final GroundOverlay groundOverlayPosition1 = GroundOverlay.fromPosition(
groundOverlayId: const GroundOverlayId('position_1'),
position: kGroundOverlayBounds.northeast,
width: 100,
height: 100,
anchor: const Offset(0.1, 0.2),
zoomLevel: 14.0,
image: AssetMapBitmap(
'assets/red_square.png',
imagePixelRatio: 1.0,
));

void expectGroundOverlayEquals(
GroundOverlay source, GroundOverlay response) {
expect(response.groundOverlayId, source.groundOverlayId);
expect(
response.transparency,
moreOrLessEquals(source.transparency, epsilon: _floatTolerance),
);
expect(
response.bearing,
moreOrLessEquals(source.bearing, epsilon: _floatTolerance),
);

// Only test bounds if it was given in the original object
if (source.bounds != null) {
expect(response.bounds, source.bounds);
}

// Only test position if it was given in the original object
if (source.position != null) {
expect(response.position, source.position);
}

expect(response.clickable, source.clickable);
expect(response.zIndex, source.zIndex);
expect(response.zoomLevel, source.zoomLevel);
expect(
response.anchor?.dx,
moreOrLessEquals(source.anchor!.dx, epsilon: _floatTolerance),
);
expect(
response.anchor?.dy,
moreOrLessEquals(source.anchor!.dy, epsilon: _floatTolerance),
);
}

testWidgets('set ground overlays correctly', (WidgetTester tester) async {
final Completer<int> mapIdCompleter = Completer<int>();
final GroundOverlay groundOverlayBounds2 = GroundOverlay.fromBounds(
groundOverlayId: const GroundOverlayId('bounds_2'),
bounds: groundOverlayBounds1.bounds!,
image: groundOverlayBounds1.image,
);

await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: ExampleGoogleMap(
initialCameraPosition: _kInitialCameraPosition,
groundOverlays: <GroundOverlay>{
groundOverlayBounds1,
groundOverlayBounds2,
groundOverlayPosition1,
},
onMapCreated: (ExampleGoogleMapController controller) {
mapIdCompleter.complete(controller.mapId);
},
),
),
);
await tester.pumpAndSettle(const Duration(seconds: 3));

final int mapId = await mapIdCompleter.future;
final GoogleMapsInspectorPlatform inspector =
GoogleMapsInspectorPlatform.instance!;

if (inspector.supportsGettingGroundOverlayInfo()) {
final GroundOverlay groundOverlayBoundsInfo1 = (await inspector
.getGroundOverlayInfo(groundOverlayBounds1.mapsId, mapId: mapId))!;
final GroundOverlay groundOverlayBoundsInfo2 = (await inspector
.getGroundOverlayInfo(groundOverlayBounds2.mapsId, mapId: mapId))!;
final GroundOverlay groundOverlayPositionInfo1 =
(await inspector.getGroundOverlayInfo(groundOverlayPosition1.mapsId,
mapId: mapId))!;

expectGroundOverlayEquals(
groundOverlayBounds1,
groundOverlayBoundsInfo1,
);
expectGroundOverlayEquals(
groundOverlayBounds2,
groundOverlayBoundsInfo2,
);
expectGroundOverlayEquals(
groundOverlayPosition1,
groundOverlayPositionInfo1,
);
}
});

testWidgets('update ground overlays correctly',
(WidgetTester tester) async {
final Completer<int> mapIdCompleter = Completer<int>();
final Key key = GlobalKey();

await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: ExampleGoogleMap(
key: key,
initialCameraPosition: _kInitialCameraPosition,
groundOverlays: <GroundOverlay>{
groundOverlayBounds1,
groundOverlayPosition1
},
onMapCreated: (ExampleGoogleMapController controller) {
mapIdCompleter.complete(controller.mapId);
},
),
),
);

final int mapId = await mapIdCompleter.future;
final GoogleMapsInspectorPlatform inspector =
GoogleMapsInspectorPlatform.instance!;

final GroundOverlay groundOverlayBounds1New =
groundOverlayBounds1.copyWith(
bearingParam: 10,
clickableParam: false,
transparencyParam: 0.5,
visibleParam: false,
zIndexParam: 10,
);

final GroundOverlay groundOverlayPosition1New =
groundOverlayPosition1.copyWith(
bearingParam: 10,
clickableParam: false,
transparencyParam: 0.5,
visibleParam: false,
zIndexParam: 10,
);

await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: ExampleGoogleMap(
key: key,
initialCameraPosition: _kInitialCameraPosition,
groundOverlays: <GroundOverlay>{
groundOverlayBounds1New,
groundOverlayPosition1New
},
onMapCreated: (ExampleGoogleMapController controller) {
fail('update: OnMapCreated should get called only once.');
},
),
),
);

await tester.pumpAndSettle(const Duration(seconds: 3));

if (inspector.supportsGettingGroundOverlayInfo()) {
final GroundOverlay groundOverlayBounds1Info = (await inspector
.getGroundOverlayInfo(groundOverlayBounds1.mapsId, mapId: mapId))!;
final GroundOverlay groundOverlayPosition1Info =
(await inspector.getGroundOverlayInfo(groundOverlayPosition1.mapsId,
mapId: mapId))!;

expectGroundOverlayEquals(
groundOverlayBounds1New,
groundOverlayBounds1Info,
);
expectGroundOverlayEquals(
groundOverlayPosition1New,
groundOverlayPosition1Info,
);
}
});

testWidgets('remove ground overlays correctly',
(WidgetTester tester) async {
final Completer<int> mapIdCompleter = Completer<int>();
final Key key = GlobalKey();

await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: ExampleGoogleMap(
key: key,
initialCameraPosition: _kInitialCameraPosition,
groundOverlays: <GroundOverlay>{
groundOverlayBounds1,
groundOverlayPosition1
},
onMapCreated: (ExampleGoogleMapController controller) {
mapIdCompleter.complete(controller.mapId);
},
),
),
);

final int mapId = await mapIdCompleter.future;
final GoogleMapsInspectorPlatform inspector =
GoogleMapsInspectorPlatform.instance!;

await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: ExampleGoogleMap(
key: key,
initialCameraPosition: _kInitialCameraPosition,
onMapCreated: (ExampleGoogleMapController controller) {
fail('OnMapCreated should get called only once.');
},
),
),
);

await tester.pumpAndSettle(const Duration(seconds: 3));

if (inspector.supportsGettingGroundOverlayInfo()) {
final GroundOverlay? groundOverlayBounds1Info = await inspector
.getGroundOverlayInfo(groundOverlayBounds1.mapsId, mapId: mapId);
final GroundOverlay? groundOverlayPositionInfo = await inspector
.getGroundOverlayInfo(groundOverlayPosition1.mapsId, mapId: mapId);

expect(groundOverlayBounds1Info, isNull);
expect(groundOverlayPositionInfo, isNull);
}
});
});
}

class _DebugTileProvider implements TileProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 60;
objectVersion = 54;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what causes this. could this change be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generated by Xcode based on the xcode version. It tells the project the format version of the project files. Which Xcode are you using? I'm not completely sure if it's safe to change it. We could try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored to 60.

objects = {

/* Begin PBXBuildFile section */
Expand Down
Loading
Loading