Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix unit-test failed
  • Loading branch information
nploi committed May 2, 2023
commit d07ac62e4ad89207db79e9d9fb2bdbe0e4046459
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ void main() {
myLocationEnabled: true,
myLocationButtonEnabled: true,
));

controller.debugSetOverrides(
createMap: (_, __) => map,
markers: markers,
Expand All @@ -516,8 +517,8 @@ void main() {
when(mockCoordinates.latitude).thenReturn(currentLocation.latitude);

when(mockGeolocation.getCurrentPosition(
timeout: const Duration(seconds: 30)))
.thenAnswer((_) async => mockGeoposition);
timeout: anyNamed('timeout'),
)).thenAnswer((_) async => mockGeoposition);

when(mockGeolocation.watchPosition()).thenAnswer((_) {
return Stream<MockGeoposition>.fromIterable(
Expand All @@ -526,19 +527,13 @@ void main() {

controller.init();

await Future<void>.delayed(const Duration(milliseconds: 50));

final Set<Marker> capturedMarkers =
verify(markers.addMarkers(captureAny)).captured[1] as Set<Marker>;

final gmaps.LatLng gmCenter = map.center!;

expect(controller.myLocationButton, isNotNull);
expect(capturedMarkers.length, 1);
expect(capturedMarkers.first.position, currentLocation);
expect(capturedMarkers.first.zIndex, 0.5);
expect(gmCenter.lat, currentLocation.latitude);
expect(gmCenter.lng, currentLocation.longitude);
});

testWidgets('initializes with my location only',
Expand Down Expand Up @@ -576,19 +571,13 @@ void main() {

controller.init();

await Future<void>.delayed(const Duration(milliseconds: 50));

final Set<Marker> capturedMarkers =
verify(markers.addMarkers(captureAny)).captured[1] as Set<Marker>;

final gmaps.LatLng gmCenter = map.center!;

expect(controller.myLocationButton, isNull);
expect(capturedMarkers.length, 1);
expect(capturedMarkers.first.position, currentLocation);
expect(capturedMarkers.first.zIndex, 0.5);
expect(gmCenter.lat, currentLocation.latitude);
expect(gmCenter.lng, currentLocation.longitude);
});
});

Expand All @@ -609,8 +598,7 @@ void main() {
geolocation: mockGeolocation,
);

when(mockGeolocation.getCurrentPosition(
timeout: const Duration(seconds: 30)))
when(mockGeolocation.getCurrentPosition(timeout: anyNamed('timeout')))
.thenAnswer(
(_) async => throw Exception('permission denied'),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Future<void> _displayAndWatchMyLocation(MarkersController controller) async {

// Get current location
Future<LatLng> _getCurrentLocation() async {
final Geoposition location = await _geolocation.getCurrentPosition();
final Geoposition location = await _geolocation.getCurrentPosition(
timeout: const Duration(seconds: 5),
);
return LatLng(
location.coords?.latitude?.toDouble() ?? _nullLatLng.latitude,
location.coords?.longitude?.toDouble() ?? _nullLatLng.longitude,
Expand Down