Skip to content

Commit fe5c59f

Browse files
test: add camera tests
1 parent 65e1128 commit fe5c59f

File tree

4 files changed

+156
-1
lines changed

4 files changed

+156
-1
lines changed
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from './shared.js';
2222
import { element, by, log } from 'detox';
2323

24-
describe('Initialization tests', () => {
24+
describe('Map view tests', () => {
2525
beforeEach(async () => {
2626
await initializeIntegrationTestsPage();
2727
});
@@ -37,4 +37,28 @@ describe('Initialization tests', () => {
3737
'Test result: Success'
3838
);
3939
});
40+
41+
it('T02 - initialize map and test move camera', async () => {
42+
await selectTestByName('testMoveCamera');
43+
await waitForTestToFinish();
44+
const failureMessageLabel = element(by.id('failure_message_label'));
45+
const attributes = await failureMessageLabel.getAttributes();
46+
log.error(attributes.text);
47+
await expect(element(by.id('failure_message_label'))).toHaveText('');
48+
await expect(element(by.id('test_result_label'))).toHaveText(
49+
'Test result: Success'
50+
);
51+
});
52+
53+
it('T03 - initialize map and test camera tilt bearing zoom', async () => {
54+
await selectTestByName('testTiltZoomBearingCamera');
55+
await waitForTestToFinish();
56+
const failureMessageLabel = element(by.id('failure_message_label'));
57+
const attributes = await failureMessageLabel.getAttributes();
58+
log.error(attributes.text);
59+
await expect(element(by.id('failure_message_label'))).toHaveText('');
60+
await expect(element(by.id('test_result_label'))).toHaveText(
61+
'Test result: Success'
62+
);
63+
});
4064
});

example/src/screens/IntegrationTestsScreen.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
testNavigationToMultipleDestination,
4141
testRouteSegments,
4242
testGetCurrentTimeAndDistance,
43+
testMoveCamera,
44+
testTiltZoomBearingCamera,
4345
} from './integration_tests/integration_test';
4446

4547
// Utility function for showing Snackbar
@@ -186,6 +188,12 @@ const IntegrationTestsScreen = () => {
186188
case 'testGetCurrentTimeAndDistance':
187189
await testGetCurrentTimeAndDistance(getTestTools());
188190
break;
191+
case 'testMoveCamera':
192+
await testMoveCamera(getTestTools());
193+
break;
194+
case 'testTiltZoomBearingCamera':
195+
await testTiltZoomBearingCamera(getTestTools());
196+
break;
189197
default:
190198
resetTestState();
191199
break;
@@ -277,6 +285,20 @@ const IntegrationTestsScreen = () => {
277285
runTest('testGetCurrentTimeAndDistance');
278286
}}
279287
/>
288+
<Button
289+
title="testMoveCamera"
290+
testID="testMoveCamera"
291+
onPress={() => {
292+
runTest('testMoveCamera');
293+
}}
294+
/>
295+
<Button
296+
title="testTiltZoomBearingCamera"
297+
testID="testTiltZoomBearingCamera"
298+
onPress={() => {
299+
runTest('testTiltZoomBearingCamera');
300+
}}
301+
/>
280302
</OverlayModal>
281303
</View>
282304
);

example/src/screens/integration_tests/integration_test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
type TimeAndDistance,
2525
} from '@googlemaps/react-native-navigation-sdk';
2626
import { Platform } from 'react-native';
27+
import { delay, roundDown } from './utils';
2728

2829
interface TestTools {
2930
navigationController: NavigationController;
@@ -415,3 +416,85 @@ export const testGetCurrentTimeAndDistance = async (testTools: TestTools) => {
415416
failTest('navigationController.init() exception');
416417
}
417418
};
419+
420+
export const testMoveCamera = async (testTools: TestTools) => {
421+
const { mapViewController, passTest, failTest, expectFalseError } = testTools;
422+
if (!mapViewController) {
423+
return failTest('mapViewController was expected to exist');
424+
}
425+
426+
// Move camera to Hong Kong
427+
mapViewController.moveCamera({
428+
target: {
429+
lat: 22.2987849,
430+
lng: 114.1719271,
431+
},
432+
});
433+
434+
await delay(3000);
435+
const hongKongPosition = await mapViewController.getCameraPosition();
436+
437+
if (
438+
roundDown(hongKongPosition.target.lat) !== 22 ||
439+
roundDown(hongKongPosition.target.lng) !== 114
440+
) {
441+
expectFalseError(
442+
'roundDown(hongKongPosition.target.lat) !== 22 || roundDown(hongKongPosition.target.lng) !== 114'
443+
);
444+
}
445+
446+
// Move camera to Tokyo
447+
mapViewController.moveCamera({
448+
target: {
449+
lat: 35.6805707,
450+
lng: 139.7658596,
451+
},
452+
});
453+
454+
await delay(3000);
455+
const tokyoPosition = await mapViewController.getCameraPosition();
456+
457+
if (
458+
roundDown(tokyoPosition.target.lat) !== 35 ||
459+
roundDown(tokyoPosition.target.lng) !== 139
460+
) {
461+
expectFalseError(
462+
'roundDown(hongKongPosition.target.lat) !== 22 || roundDown(hongKongPosition.target.lng) !== 114'
463+
);
464+
}
465+
466+
passTest();
467+
};
468+
469+
export const testTiltZoomBearingCamera = async (testTools: TestTools) => {
470+
const { mapViewController, passTest, failTest, expectFalseError } = testTools;
471+
if (!mapViewController) {
472+
return failTest('mapViewController was expected to exist');
473+
}
474+
475+
// Move camera to Hong Kong and set bearing, tilt and zoom.
476+
mapViewController.moveCamera({
477+
target: {
478+
lat: 22.2987849,
479+
lng: 114.1719271,
480+
},
481+
bearing: 270,
482+
tilt: 20,
483+
zoom: 6,
484+
});
485+
486+
await delay(3000);
487+
const hongKongPosition = await mapViewController.getCameraPosition();
488+
489+
if (
490+
hongKongPosition.bearing !== 270 ||
491+
hongKongPosition.tilt !== 20 ||
492+
hongKongPosition.zoom !== 6
493+
) {
494+
expectFalseError(
495+
'hongKongPosition.bearing !== 270 || hongKongPosition.tilt !== 20 || hongKongPosition.zoom !== 6'
496+
);
497+
}
498+
499+
passTest();
500+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
// Delay function execution by given time in ms.
18+
export const delay = (timeInMs: number): Promise<void> => {
19+
return new Promise(resolve => setTimeout(resolve, timeInMs));
20+
};
21+
22+
// Remove decimals from any floating point number.
23+
export const roundDown = (value: number) => {
24+
const factor = Math.pow(10, 0);
25+
return Math.floor(value * factor) / factor;
26+
};

0 commit comments

Comments
 (0)