Skip to content

Commit 8489c30

Browse files
illuminati1911jokerttu
authored andcommitted
test: add route segments and multiple detinations tests
1 parent 1bb4ea6 commit 8489c30

File tree

4 files changed

+172
-3
lines changed

4 files changed

+172
-3
lines changed

example/e2e/initialization.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ describe('Initialization tests', () => {
2828

2929
it('T01 - initialize map and test default values', async () => {
3030
await selectTestByName('testMapInitialization');
31-
// await waitForStepNumber(1);
32-
// await agreeToTermsAndConditions();
3331
await waitForTestToFinish();
3432
const failureMessageLabel = element(by.id('failure_message_label'));
3533
const attributes = await failureMessageLabel.getAttributes();

example/e2e/navigation.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
selectTestByName,
2121
waitForTestToFinish,
2222
} from './shared.js';
23-
import { element, by } from 'detox';
23+
import { element, by, log } from 'detox';
2424

2525
describe('Navigation tests', () => {
2626
beforeEach(async () => {
@@ -44,4 +44,26 @@ describe('Navigation tests', () => {
4444
'Test result: Success'
4545
);
4646
});
47+
48+
it('T03 - initialize navigation controller and navigate to multiple destinations', async () => {
49+
await selectTestByName('testNavigationToMultipleDestination');
50+
await agreeToTermsAndConditions();
51+
await waitForTestToFinish();
52+
await expect(element(by.id('test_result_label'))).toHaveText(
53+
'Test result: Success'
54+
);
55+
});
56+
57+
it('T04 - initialize navigation controller and test route segments', async () => {
58+
await selectTestByName('testRouteSegments');
59+
await agreeToTermsAndConditions();
60+
const failureMessageLabel = element(by.id('failure_message_label'));
61+
const attributes = await failureMessageLabel.getAttributes();
62+
log.error(attributes.text);
63+
await expect(element(by.id('failure_message_label'))).toHaveText('');
64+
await waitForTestToFinish();
65+
await expect(element(by.id('test_result_label'))).toHaveText(
66+
'Test result: Success'
67+
);
68+
});
4769
});

example/src/screens/IntegrationTestsScreen.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
testMapInitialization,
3838
testNavigationToSingleDestination,
3939
testNavigationSessionInitialization,
40+
testNavigationToMultipleDestination,
41+
testRouteSegments,
4042
} from './integration_tests/integration_test';
4143

4244
// Utility function for showing Snackbar
@@ -174,6 +176,12 @@ const IntegrationTestsScreen = () => {
174176
case 'testNavigationToSingleDestination':
175177
await testNavigationToSingleDestination(getTestTools());
176178
break;
179+
case 'testNavigationToMultipleDestination':
180+
await testNavigationToMultipleDestination(getTestTools());
181+
break;
182+
case 'testRouteSegments':
183+
await testRouteSegments(getTestTools());
184+
break;
177185
default:
178186
resetTestState();
179187
break;
@@ -244,6 +252,20 @@ const IntegrationTestsScreen = () => {
244252
runTest('testNavigationToSingleDestination');
245253
}}
246254
/>
255+
<Button
256+
title="testNavigationToMultipleDestination"
257+
testID="testNavigationToMultipleDestination"
258+
onPress={() => {
259+
runTest('testNavigationToMultipleDestination');
260+
}}
261+
/>
262+
<Button
263+
title="testRouteSegments"
264+
testID="testRouteSegments"
265+
onPress={() => {
266+
runTest('testRouteSegments');
267+
}}
268+
/>
247269
</OverlayModal>
248270
</View>
249271
);

example/src/screens/integration_tests/integration_test.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,130 @@ export const testNavigationToSingleDestination = async (
218218
failTest('navigationController.init() exception');
219219
}
220220
};
221+
222+
export const testNavigationToMultipleDestination = async (
223+
testTools: TestTools
224+
) => {
225+
const { navigationController, addListeners, passTest, failTest } = testTools;
226+
let onArrivalCount = 0;
227+
addListeners({
228+
onNavigationReady: async () => {
229+
await navigationController.simulator.simulateLocation({
230+
lat: 37.4195823,
231+
lng: -122.0799018,
232+
});
233+
await navigationController.setDestinations(
234+
[
235+
{
236+
position: {
237+
lat: 37.4152112,
238+
lng: -122.0813741,
239+
},
240+
},
241+
{
242+
position: {
243+
lat: 37.4155112,
244+
lng: -122.0806959,
245+
},
246+
},
247+
],
248+
{
249+
travelMode: TravelMode.DRIVING,
250+
avoidFerries: true,
251+
avoidTolls: false,
252+
}
253+
);
254+
await navigationController.startGuidance();
255+
256+
// Timeout here is used to avoid issues on Android.
257+
setTimeout(() => {
258+
navigationController.simulator.simulateLocationsAlongExistingRoute({
259+
speedMultiplier: Platform.OS === 'ios' ? 5 : 10,
260+
});
261+
}, 3000);
262+
},
263+
onNavigationInitError: (errorCode: NavigationInitErrorCode) => {
264+
console.log(errorCode);
265+
failTest('onNavigatonInitError');
266+
},
267+
onArrival: async () => {
268+
onArrivalCount += 1;
269+
if (onArrivalCount > 1) {
270+
return passTest();
271+
}
272+
await navigationController.continueToNextDestination();
273+
},
274+
});
275+
try {
276+
await navigationController.init();
277+
} catch (error) {
278+
console.error('Error initializing navigator', error);
279+
failTest('navigationController.init() exception');
280+
}
281+
};
282+
283+
export const testRouteSegments = async (testTools: TestTools) => {
284+
const {
285+
navigationController,
286+
addListeners,
287+
passTest,
288+
failTest,
289+
expectFalseError,
290+
} = testTools;
291+
let beginTraveledPath;
292+
addListeners({
293+
onNavigationReady: async () => {
294+
await navigationController.simulator.simulateLocation({
295+
lat: 37.79136614772824,
296+
lng: -122.41565900473043,
297+
});
298+
await navigationController.setDestination({
299+
title: 'Grace Cathedral',
300+
position: {
301+
lat: 37.791957,
302+
lng: -122.412529,
303+
},
304+
});
305+
await navigationController.startGuidance();
306+
307+
// Timeout here is used to avoid issues on Android.
308+
setTimeout(async () => {
309+
const beginRouteSegments =
310+
await navigationController.getRouteSegments();
311+
const beginCurrentRouteSegment =
312+
await navigationController.getCurrentRouteSegment();
313+
beginTraveledPath = await navigationController.getTraveledPath();
314+
315+
if (beginRouteSegments.length === 0) {
316+
expectFalseError('beginRouteSegments.length === 0');
317+
return;
318+
}
319+
if (!beginCurrentRouteSegment) {
320+
return expectFalseError('!beginCurrentRouteSegment');
321+
}
322+
navigationController.simulator.simulateLocationsAlongExistingRoute({
323+
speedMultiplier: 5,
324+
});
325+
}, 3000);
326+
},
327+
onNavigationInitError: (errorCode: NavigationInitErrorCode) => {
328+
console.log(errorCode);
329+
failTest('onNavigatonInitError');
330+
},
331+
onArrival: async () => {
332+
const endTraveledPath = await navigationController.getTraveledPath();
333+
if (endTraveledPath.length <= beginTraveledPath.length) {
334+
return expectFalseError(
335+
'endTraveledPath.length <= beginTraveledPath.length'
336+
);
337+
}
338+
passTest();
339+
},
340+
});
341+
try {
342+
await navigationController.init();
343+
} catch (error) {
344+
console.error('Error initializing navigator', error);
345+
failTest('navigationController.init() exception');
346+
}
347+
};

0 commit comments

Comments
 (0)