Skip to content

Commit fa6697e

Browse files
illuminati1911jokerttu
authored andcommitted
test: add event listener tests
1 parent e6cf8e6 commit fa6697e

File tree

6 files changed

+214
-25
lines changed

6 files changed

+214
-25
lines changed

example/e2e/event_listener.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {
18+
initializeIntegrationTestsPage,
19+
agreeToTermsAndConditions,
20+
selectTestByName,
21+
waitForTestToFinish,
22+
expectSuccess,
23+
} from './shared.js';
24+
25+
describe('Even listener tests', () => {
26+
beforeEach(async () => {
27+
await initializeIntegrationTestsPage();
28+
});
29+
30+
it('T01 - test navigation onRemainingTimeOrDistanceChanged event listener', async () => {
31+
await selectTestByName('testOnRemainingTimeOrDistanceChanged');
32+
await agreeToTermsAndConditions();
33+
await waitForTestToFinish();
34+
await expectSuccess();
35+
});
36+
37+
it('T02 - test navigation onArrival event listener', async () => {
38+
await selectTestByName('testOnArrival');
39+
await agreeToTermsAndConditions();
40+
await waitForTestToFinish();
41+
await expectSuccess();
42+
});
43+
44+
it('T03 - test navigation OnRouteChanged event listener', async () => {
45+
await selectTestByName('testOnRouteChanged');
46+
await agreeToTermsAndConditions();
47+
await waitForTestToFinish();
48+
await expectSuccess();
49+
});
50+
});

example/e2e/map.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
initializeIntegrationTestsPage,
1919
selectTestByName,
2020
waitForTestToFinish,
21+
expectSuccess,
2122
} from './shared.js';
2223
import { element, by, log } from 'detox';
2324

@@ -33,9 +34,7 @@ describe('Map view tests', () => {
3334
const attributes = await failureMessageLabel.getAttributes();
3435
log.error(attributes.text);
3536
await expect(element(by.id('failure_message_label'))).toHaveText('');
36-
await expect(element(by.id('test_result_label'))).toHaveText(
37-
'Test result: Success'
38-
);
37+
await expectSuccess();
3938
});
4039

4140
it('T02 - initialize map and test move camera', async () => {
@@ -45,9 +44,7 @@ describe('Map view tests', () => {
4544
const attributes = await failureMessageLabel.getAttributes();
4645
log.error(attributes.text);
4746
await expect(element(by.id('failure_message_label'))).toHaveText('');
48-
await expect(element(by.id('test_result_label'))).toHaveText(
49-
'Test result: Success'
50-
);
47+
await expectSuccess();
5148
});
5249

5350
it('T03 - initialize map and test camera tilt bearing zoom', async () => {
@@ -57,8 +54,6 @@ describe('Map view tests', () => {
5754
const attributes = await failureMessageLabel.getAttributes();
5855
log.error(attributes.text);
5956
await expect(element(by.id('failure_message_label'))).toHaveText('');
60-
await expect(element(by.id('test_result_label'))).toHaveText(
61-
'Test result: Success'
62-
);
57+
await expectSuccess();
6358
});
6459
});

example/e2e/navigation.test.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
agreeToTermsAndConditions,
2020
selectTestByName,
2121
waitForTestToFinish,
22+
expectSuccess,
2223
} from './shared.js';
2324
import { element, by, log } from 'detox';
2425

@@ -31,27 +32,21 @@ describe('Navigation tests', () => {
3132
await selectTestByName('testNavigationSessionInitialization');
3233
await agreeToTermsAndConditions();
3334
await waitForTestToFinish();
34-
await expect(element(by.id('test_result_label'))).toHaveText(
35-
'Test result: Success'
36-
);
35+
await expectSuccess();
3736
});
3837

3938
it('T02 - initialize navigation controller and navigate to single destination', async () => {
4039
await selectTestByName('testNavigationToSingleDestination');
4140
await agreeToTermsAndConditions();
4241
await waitForTestToFinish();
43-
await expect(element(by.id('test_result_label'))).toHaveText(
44-
'Test result: Success'
45-
);
42+
await expectSuccess();
4643
});
4744

4845
it('T03 - initialize navigation controller and navigate to multiple destinations', async () => {
4946
await selectTestByName('testNavigationToMultipleDestination');
5047
await agreeToTermsAndConditions();
5148
await waitForTestToFinish();
52-
await expect(element(by.id('test_result_label'))).toHaveText(
53-
'Test result: Success'
54-
);
49+
await expectSuccess();
5550
});
5651

5752
it('T04 - initialize navigation controller and test route segments', async () => {
@@ -62,9 +57,7 @@ describe('Navigation tests', () => {
6257
log.error(attributes.text);
6358
await expect(element(by.id('failure_message_label'))).toHaveText('');
6459
await waitForTestToFinish();
65-
await expect(element(by.id('test_result_label'))).toHaveText(
66-
'Test result: Success'
67-
);
60+
await expectSuccess();
6861
});
6962

7063
it('T05 - initialize navigation controller and test remaining time and distance', async () => {
@@ -75,8 +68,6 @@ describe('Navigation tests', () => {
7568
log.error(attributes.text);
7669
await expect(element(by.id('failure_message_label'))).toHaveText('');
7770
await waitForTestToFinish();
78-
await expect(element(by.id('test_result_label'))).toHaveText(
79-
'Test result: Success'
80-
);
71+
await expectSuccess();
8172
});
8273
});

example/e2e/shared.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { device, element, waitFor, by } from 'detox';
17+
import { device, element, waitFor, by, expect } from 'detox';
1818

1919
export const agreeToTermsAndConditions = async () => {
2020
if (device.getPlatform() === 'ios') {
@@ -42,6 +42,12 @@ export const waitForTestToFinish = async (timeInMs = 60000) => {
4242
.withTimeout(timeInMs);
4343
};
4444

45+
export const expectSuccess = async () => {
46+
await expect(element(by.id('test_result_label'))).toHaveText(
47+
'Test result: Success'
48+
);
49+
};
50+
4551
export const initializeIntegrationTestsPage = async () => {
4652
await device.launchApp({
4753
delete: true,

example/src/screens/IntegrationTestsScreen.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ import {
4242
testGetCurrentTimeAndDistance,
4343
testMoveCamera,
4444
testTiltZoomBearingCamera,
45+
testOnRemainingTimeOrDistanceChanged,
46+
testOnArrival,
47+
testOnRouteChanged,
4548
} from './integration_tests/integration_test';
4649

4750
// Utility function for showing Snackbar
@@ -194,6 +197,15 @@ const IntegrationTestsScreen = () => {
194197
case 'testTiltZoomBearingCamera':
195198
await testTiltZoomBearingCamera(getTestTools());
196199
break;
200+
case 'testOnRemainingTimeOrDistanceChanged':
201+
await testOnRemainingTimeOrDistanceChanged(getTestTools());
202+
break;
203+
case 'testOnArrival':
204+
await testOnArrival(getTestTools());
205+
break;
206+
case 'testOnRouteChanged':
207+
await testOnRouteChanged(getTestTools());
208+
break;
197209
default:
198210
resetTestState();
199211
break;
@@ -299,6 +311,27 @@ const IntegrationTestsScreen = () => {
299311
runTest('testTiltZoomBearingCamera');
300312
}}
301313
/>
314+
<Button
315+
title="testOnRemainingTimeOrDistanceChanged"
316+
testID="testOnRemainingTimeOrDistanceChanged"
317+
onPress={() => {
318+
runTest('testOnRemainingTimeOrDistanceChanged');
319+
}}
320+
/>
321+
<Button
322+
title="testOnArrival"
323+
testID="testOnArrival"
324+
onPress={() => {
325+
runTest('testOnArrival');
326+
}}
327+
/>
328+
<Button
329+
title="testOnRouteChanged"
330+
testID="testOnRouteChanged"
331+
onPress={() => {
332+
runTest('testOnRouteChanged');
333+
}}
334+
/>
302335
</OverlayModal>
303336
</View>
304337
);

example/src/screens/integration_tests/integration_test.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,117 @@ export const testTiltZoomBearingCamera = async (testTools: TestTools) => {
537537

538538
passTest();
539539
};
540+
541+
export const testOnRemainingTimeOrDistanceChanged = async (
542+
testTools: TestTools
543+
) => {
544+
const { navigationController, addListeners, passTest, failTest } = testTools;
545+
addListeners({
546+
onRemainingTimeOrDistanceChanged: async () => {
547+
const timeAndDistance =
548+
await navigationController.getCurrentTimeAndDistance();
549+
if (timeAndDistance.meters > 0 && timeAndDistance.seconds > 0) {
550+
return passTest();
551+
}
552+
},
553+
onNavigationReady: async () => {
554+
await navigationController.simulator.simulateLocation({
555+
lat: 37.79136614772824,
556+
lng: -122.41565900473043,
557+
});
558+
await navigationController.setDestination({
559+
title: 'Grace Cathedral',
560+
position: {
561+
lat: 37.791957,
562+
lng: -122.412529,
563+
},
564+
});
565+
await navigationController.startGuidance();
566+
await navigationController.simulator.simulateLocationsAlongExistingRoute({
567+
speedMultiplier: 5,
568+
});
569+
},
570+
onNavigationInitError: (errorCode: NavigationInitErrorCode) => {
571+
console.log(errorCode);
572+
failTest('onNavigatonInitError');
573+
},
574+
});
575+
try {
576+
await navigationController.init();
577+
} catch (error) {
578+
console.error('Error initializing navigator', error);
579+
failTest('navigationController.init() exception');
580+
}
581+
};
582+
583+
export const testOnArrival = async (testTools: TestTools) => {
584+
const { navigationController, addListeners, passTest, failTest } = testTools;
585+
addListeners({
586+
onArrival: async () => {
587+
passTest();
588+
},
589+
onNavigationReady: async () => {
590+
await navigationController.simulator.simulateLocation({
591+
lat: 37.79136614772824,
592+
lng: -122.41565900473043,
593+
});
594+
await navigationController.setDestination({
595+
title: 'Grace Cathedral',
596+
position: {
597+
lat: 37.791957,
598+
lng: -122.412529,
599+
},
600+
});
601+
await navigationController.startGuidance();
602+
await navigationController.simulator.simulateLocationsAlongExistingRoute({
603+
speedMultiplier: 5,
604+
});
605+
},
606+
onNavigationInitError: (errorCode: NavigationInitErrorCode) => {
607+
console.log(errorCode);
608+
failTest('onNavigatonInitError');
609+
},
610+
});
611+
try {
612+
await navigationController.init();
613+
} catch (error) {
614+
console.error('Error initializing navigator', error);
615+
failTest('navigationController.init() exception');
616+
}
617+
};
618+
619+
export const testOnRouteChanged = async (testTools: TestTools) => {
620+
const { navigationController, addListeners, passTest, failTest } = testTools;
621+
addListeners({
622+
onRouteChanged: async () => {
623+
passTest();
624+
},
625+
onNavigationReady: async () => {
626+
await navigationController.simulator.simulateLocation({
627+
lat: 37.79136614772824,
628+
lng: -122.41565900473043,
629+
});
630+
await navigationController.setDestination({
631+
title: 'Grace Cathedral',
632+
position: {
633+
lat: 37.791957,
634+
lng: -122.412529,
635+
},
636+
});
637+
await navigationController.startGuidance();
638+
await navigationController.simulator.simulateLocationsAlongExistingRoute({
639+
speedMultiplier: 5,
640+
});
641+
},
642+
onNavigationInitError: (errorCode: NavigationInitErrorCode) => {
643+
console.log(errorCode);
644+
failTest('onNavigatonInitError');
645+
},
646+
});
647+
try {
648+
await navigationController.init();
649+
} catch (error) {
650+
console.error('Error initializing navigator', error);
651+
failTest('navigationController.init() exception');
652+
}
653+
};

0 commit comments

Comments
 (0)