Skip to content

Commit 52ed1b9

Browse files
test: add integration tests
1 parent 16c337c commit 52ed1b9

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

example/integration_test/t07_event_listener_test.dart

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ void main() {
184184
GoogleMapsNavigator.setNavInfoListener(
185185
expectAsync1((NavInfoEvent event) {
186186
expectSync(event.navInfo, isA<NavInfo>());
187+
expectSync(event.navInfo.currentStep?.image, isNull);
187188

188189
/// Complete the eventReceived completer only once.
189190
if (!eventReceived.isCompleted) {
@@ -204,6 +205,85 @@ void main() {
204205
},
205206
);
206207

208+
patrol(
209+
'Test NavInfo event listener with generatedStepImagesType value set to bitmap and fetching the image',
210+
(PatrolIntegrationTester $) async {
211+
final Completer<void> eventReceived = Completer<void>();
212+
213+
/// Set up navigation.
214+
final GoogleNavigationViewController navigationController =
215+
await startNavigationWithoutDestination($);
216+
await $.pumpAndSettle();
217+
218+
/// Simulate location (1298 California St)
219+
await GoogleMapsNavigator.simulator.setUserLocation(
220+
const LatLng(
221+
latitude: 37.79136614772824,
222+
longitude: -122.41565900473043,
223+
),
224+
);
225+
await $.tester.runAsync(() => Future.delayed(const Duration(seconds: 1)));
226+
227+
/// Set Destination.
228+
final Destinations destinations = Destinations(
229+
waypoints: <NavigationWaypoint>[
230+
NavigationWaypoint.withLatLngTarget(
231+
title: 'California St & Jones St',
232+
target: const LatLng(latitude: 37.791424, longitude: -122.414139),
233+
),
234+
],
235+
displayOptions: NavigationDisplayOptions(showDestinationMarkers: false),
236+
);
237+
final NavigationRouteStatus status =
238+
await GoogleMapsNavigator.setDestinations(destinations);
239+
expect(status, NavigationRouteStatus.statusOk);
240+
await $.pumpAndSettle();
241+
242+
/// Start guidance.
243+
await GoogleMapsNavigator.startGuidance();
244+
await $.pumpAndSettle();
245+
246+
ImageDescriptor? currentManeuverImageDescriptor;
247+
248+
/// Set up the listener and the test.
249+
final StreamSubscription<NavInfoEvent> subscription =
250+
GoogleMapsNavigator.setNavInfoListener(
251+
expectAsync1((NavInfoEvent event) {
252+
expectSync(event.navInfo, isA<NavInfo>());
253+
expectSync(event.navInfo.currentStep?.image, isNotNull);
254+
expectSync(
255+
event.navInfo.remainingSteps.lastOrNull?.image,
256+
isNotNull,
257+
);
258+
currentManeuverImageDescriptor = event.navInfo.currentStep?.image;
259+
260+
/// Complete the eventReceived completer only once.
261+
if (!eventReceived.isCompleted) {
262+
eventReceived.complete();
263+
}
264+
}, max: -1),
265+
numNextStepsToPreview: null,
266+
generatedStepImagesType: GeneratedStepImagesType.bitmap,
267+
);
268+
269+
/// Start simulation.
270+
await GoogleMapsNavigator.simulator.simulateLocationsAlongExistingRoute();
271+
await $.pumpAndSettle();
272+
273+
/// Wait until the event is received and then test cancelling the subscription.
274+
await eventReceived.future;
275+
await subscription.cancel();
276+
277+
/// Test that the image descriptor can be used to get the image data.
278+
final image = await getRegisteredImageData(
279+
currentManeuverImageDescriptor!,
280+
);
281+
expect(image, isNotNull);
282+
283+
await navigationController.clear();
284+
},
285+
);
286+
207287
patrol('Test navigation RouteChanged event listener', (
208288
PatrolIntegrationTester $,
209289
) async {

0 commit comments

Comments
 (0)