Skip to content

Commit 65e1128

Browse files
test: add remaining time distance test
1 parent cd6751f commit 65e1128

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

example/e2e/navigation.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,17 @@ describe('Navigation tests', () => {
6666
'Test result: Success'
6767
);
6868
});
69+
70+
it('T05 - initialize navigation controller and test remaining time and distance', async () => {
71+
await selectTestByName('testGetCurrentTimeAndDistance');
72+
await agreeToTermsAndConditions();
73+
const failureMessageLabel = element(by.id('failure_message_label'));
74+
const attributes = await failureMessageLabel.getAttributes();
75+
log.error(attributes.text);
76+
await expect(element(by.id('failure_message_label'))).toHaveText('');
77+
await waitForTestToFinish();
78+
await expect(element(by.id('test_result_label'))).toHaveText(
79+
'Test result: Success'
80+
);
81+
});
6982
});

example/src/screens/IntegrationTestsScreen.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
testNavigationSessionInitialization,
4040
testNavigationToMultipleDestination,
4141
testRouteSegments,
42+
testGetCurrentTimeAndDistance,
4243
} from './integration_tests/integration_test';
4344

4445
// Utility function for showing Snackbar
@@ -182,6 +183,9 @@ const IntegrationTestsScreen = () => {
182183
case 'testRouteSegments':
183184
await testRouteSegments(getTestTools());
184185
break;
186+
case 'testGetCurrentTimeAndDistance':
187+
await testGetCurrentTimeAndDistance(getTestTools());
188+
break;
185189
default:
186190
resetTestState();
187191
break;
@@ -266,6 +270,13 @@ const IntegrationTestsScreen = () => {
266270
runTest('testRouteSegments');
267271
}}
268272
/>
273+
<Button
274+
title="testGetCurrentTimeAndDistance"
275+
testID="testGetCurrentTimeAndDistance"
276+
onPress={() => {
277+
runTest('testGetCurrentTimeAndDistance');
278+
}}
279+
/>
269280
</OverlayModal>
270281
</View>
271282
);

example/src/screens/integration_tests/integration_test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
type NavigationController,
2222
type NavigationInitErrorCode,
2323
type NavigationViewController,
24+
type TimeAndDistance,
2425
} from '@googlemaps/react-native-navigation-sdk';
2526
import { Platform } from 'react-native';
2627

@@ -345,3 +346,72 @@ export const testRouteSegments = async (testTools: TestTools) => {
345346
failTest('navigationController.init() exception');
346347
}
347348
};
349+
350+
export const testGetCurrentTimeAndDistance = async (testTools: TestTools) => {
351+
const {
352+
navigationController,
353+
addListeners,
354+
passTest,
355+
failTest,
356+
expectFalseError,
357+
} = testTools;
358+
let beginTimeAndDistance: TimeAndDistance;
359+
addListeners({
360+
onNavigationReady: async () => {
361+
await navigationController.simulator.simulateLocation({
362+
lat: 37.79136614772824,
363+
lng: -122.41565900473043,
364+
});
365+
await navigationController.setDestination({
366+
title: 'Grace Cathedral',
367+
position: {
368+
lat: 37.791957,
369+
lng: -122.412529,
370+
},
371+
});
372+
await navigationController.startGuidance();
373+
374+
// Timeout here is used to avoid issues on Android.
375+
setTimeout(async () => {
376+
beginTimeAndDistance =
377+
await navigationController.getCurrentTimeAndDistance();
378+
if (beginTimeAndDistance.seconds <= 0) {
379+
return expectFalseError('beginTimeAndDistance.seconds <= 0');
380+
}
381+
if (beginTimeAndDistance.meters <= 0) {
382+
return expectFalseError('beginTimeAndDistance.meters <= 0');
383+
}
384+
await navigationController.simulator.simulateLocationsAlongExistingRoute(
385+
{
386+
speedMultiplier: 5,
387+
}
388+
);
389+
}, 3000);
390+
},
391+
onNavigationInitError: (errorCode: NavigationInitErrorCode) => {
392+
console.log(errorCode);
393+
failTest('onNavigatonInitError');
394+
},
395+
onArrival: async () => {
396+
const endTimeAndDistance =
397+
await navigationController.getCurrentTimeAndDistance();
398+
if (endTimeAndDistance.meters >= beginTimeAndDistance.meters) {
399+
return expectFalseError(
400+
'endTimeAndDistance.meters >= beginTimeAndDistance.meters'
401+
);
402+
}
403+
if (endTimeAndDistance.seconds >= beginTimeAndDistance.seconds) {
404+
return expectFalseError(
405+
'endTimeAndDistance.seconds >= beginTimeAndDistance.seconds'
406+
);
407+
}
408+
passTest();
409+
},
410+
});
411+
try {
412+
await navigationController.init();
413+
} catch (error) {
414+
console.error('Error initializing navigator', error);
415+
failTest('navigationController.init() exception');
416+
}
417+
};

0 commit comments

Comments
 (0)