Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter] Fix integration tests #6350

Merged
merged 1 commit into from
Sep 1, 2022
Merged
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 @@ -22,6 +22,28 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
GoogleMapsFlutterPlatform.instance.enableDebugInspection();

// Repeatedly checks an asynchronous value against a test condition, waiting
// one frame between each check, returing the value if it passes the predicate
// before [maxTries] is reached.
//
// Returns null if the predicate is never satisfied.
//
// This is useful for cases where the Maps SDK has some internally
// asynchronous operation that we don't have visibility into (e.g., native UI
// animations).
Future<T?> waitForValueMatchingPredicate<T>(WidgetTester tester,
Future<T> Function() getValue, bool Function(T) predicate,
{int maxTries = 100}) async {
for (int i = 0; i < maxTries; i++) {
final T value = await getValue();
if (predicate(value)) {
return value;
}
await tester.pump();
}
return null;
}

testWidgets('testCompassToggle', (WidgetTester tester) async {
final Key key = GlobalKey();
final Completer<int> mapIdCompleter = Completer<int>();
Expand Down Expand Up @@ -481,12 +503,13 @@ void main() {
final GoogleMapController mapController =
await mapControllerCompleter.future;

// Wait for the visible region to be non-zero.
final LatLngBounds firstVisibleRegion =
await mapController.getVisibleRegion();

expect(firstVisibleRegion, isNotNull);
expect(firstVisibleRegion.southwest, isNotNull);
expect(firstVisibleRegion.northeast, isNotNull);
await waitForValueMatchingPredicate<LatLngBounds>(
tester,
() => mapController.getVisibleRegion(),
(LatLngBounds bounds) => bounds != zeroLatLngBounds) ??
zeroLatLngBounds;
expect(firstVisibleRegion, isNot(zeroLatLngBounds));
expect(firstVisibleRegion.contains(_kInitialMapCenter), isTrue);

Expand Down Expand Up @@ -517,9 +540,6 @@ void main() {
final LatLngBounds secondVisibleRegion =
await mapController.getVisibleRegion();

expect(secondVisibleRegion, isNotNull);
expect(secondVisibleRegion.southwest, isNotNull);
expect(secondVisibleRegion.northeast, isNotNull);
expect(secondVisibleRegion, isNot(zeroLatLngBounds));

expect(firstVisibleRegion, isNot(secondVisibleRegion));
Expand Down Expand Up @@ -906,7 +926,13 @@ void main() {
expect(iwVisibleStatus, false);

await controller.showMarkerInfoWindow(marker.markerId);
iwVisibleStatus = await controller.isMarkerInfoWindowShown(marker.markerId);
// The Maps SDK doesn't always return true for whether it is shown
// immediately after showing it, so wait for it to report as shown.
iwVisibleStatus = await waitForValueMatchingPredicate<bool>(
tester,
() => controller.isMarkerInfoWindowShown(marker.markerId),
(bool visible) => visible) ??
false;
expect(iwVisibleStatus, true);

await controller.hideMarkerInfoWindow(marker.markerId);
Expand Down