Skip to content

Commit 1bb4ea6

Browse files
illuminati1911jokerttu
authored andcommitted
test: refactor tests and add navigation test
1 parent 8fe5d5d commit 1bb4ea6

File tree

4 files changed

+86
-52
lines changed

4 files changed

+86
-52
lines changed

example/e2e/navigation.test.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,12 @@ describe('Navigation tests', () => {
3636
);
3737
});
3838

39-
/**
40-
it('T01 - check navigation controller defaults', async () => {
41-
await element(by.text('Tests')).tap();
42-
await element(by.text('testNavigationSessionInitialization')).tap();
43-
// await waitFor(element(by.text('Test status: Step #1')))
44-
// .toBeVisible()
45-
// .withTimeout(10000);
46-
await waitFor(element(by.id('test_status_label')))
47-
.toHaveText('Test status: Step #1')
48-
.withTimeout(10000);
49-
await agreeToTC();
50-
await waitFor(element(by.text('Test status: Success')))
51-
.toBeVisible()
52-
.withTimeout(10000);
39+
it('T02 - initialize navigation controller and navigate to single destination', async () => {
40+
await selectTestByName('testNavigationToSingleDestination');
41+
await agreeToTermsAndConditions();
42+
await waitForTestToFinish();
43+
await expect(element(by.id('test_result_label'))).toHaveText(
44+
'Test result: Success'
45+
);
5346
});
54-
*/
5547
});

example/e2e/shared.js

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

17-
import { device, element, system, waitFor, by } from 'detox';
18-
19-
export const initializeNavigationPage = async () => {
20-
await device.launchApp({ newInstance: true });
21-
await element(by.text('Navigation')).tap();
22-
if (device.getPlatform() === 'ios') {
23-
await system.element(by.system.label('Allow While Using App')).tap();
24-
await waitFor(element(by.text("YES, I'M IN")))
25-
.toBeVisible()
26-
.withTimeout(10000);
27-
await element(by.text("YES, I'M IN")).tap();
28-
} else if (device.getPlatform() === 'android') {
29-
await waitFor(element(by.text('GOT IT')))
30-
.toBeVisible()
31-
.withTimeout(10000);
32-
await element(by.text('GOT IT')).tap();
33-
}
34-
};
17+
import { device, element, waitFor, by } from 'detox';
3518

3619
export const agreeToTermsAndConditions = async () => {
3720
if (device.getPlatform() === 'ios') {
@@ -53,14 +36,17 @@ export const waitForStepNumber = async number => {
5336
.withTimeout(10000);
5437
};
5538

56-
export const waitForTestToFinish = async () => {
39+
export const waitForTestToFinish = async (timeInMs = 60000) => {
5740
await waitFor(element(by.id('test_status_label')))
5841
.toHaveText(`Test status: Finished`)
59-
.withTimeout(10000);
42+
.withTimeout(timeInMs);
6043
};
6144

6245
export const initializeIntegrationTestsPage = async () => {
63-
await device.launchApp({ newInstance: true });
46+
await device.launchApp({
47+
delete: true,
48+
permissions: { location: 'always' },
49+
});
6450
await element(by.id('integration_tests_button')).tap();
6551
};
6652

example/src/screens/IntegrationTestsScreen.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ import {
2525
type MapViewCallbacks,
2626
type MapViewController,
2727
type Marker,
28+
type NavigationViewController,
2829
type Polygon,
2930
type Polyline,
30-
MapView,
31+
NavigationView,
3132
useNavigation,
3233
} from '@googlemaps/react-native-navigation-sdk';
3334
import styles from '../styles';
3435
import OverlayModal from '../helpers/overlayModal';
3536
import {
3637
testMapInitialization,
37-
runTest3,
38+
testNavigationToSingleDestination,
3839
testNavigationSessionInitialization,
3940
} from './integration_tests/integration_test';
4041

@@ -69,6 +70,8 @@ const IntegrationTestsScreen = () => {
6970
useNavigation();
7071
const [detoxStepNumber, setDetoxStepNumber] = useState(0);
7172
const [failureMessage, setFailuremessage] = useState('');
73+
const [navigationViewController, setNavigationViewController] =
74+
useState<NavigationViewController | null>(null);
7275

7376
const onMapReady = useCallback(async () => {
7477
console.log('Map is ready, initializing navigator...');
@@ -145,6 +148,7 @@ const IntegrationTestsScreen = () => {
145148
return {
146149
navigationController,
147150
mapViewController,
151+
navigationViewController,
148152
addListeners,
149153
removeListeners,
150154
passTest,
@@ -167,8 +171,8 @@ const IntegrationTestsScreen = () => {
167171
case 'testMapInitialization':
168172
await testMapInitialization(getTestTools());
169173
break;
170-
case 'test3':
171-
await runTest3();
174+
case 'testNavigationToSingleDestination':
175+
await testNavigationToSingleDestination(getTestTools());
172176
break;
173177
default:
174178
resetTestState();
@@ -185,13 +189,14 @@ const IntegrationTestsScreen = () => {
185189

186190
return (
187191
<View style={[styles.container]}>
188-
<View style={{ flex: 1, margin: 5 }}>
189-
<MapView
192+
<View style={{ flex: 3, margin: 5 }}>
193+
<NavigationView
190194
mapViewCallbacks={mapViewCallbacks}
191195
onMapViewControllerCreated={setMapViewController}
196+
onNavigationViewControllerCreated={setNavigationViewController}
192197
/>
193198
</View>
194-
<View style={{ flex: 3 }}>
199+
<View style={{ flex: 4 }}>
195200
<Text>Selected testId: {activeTestId}</Text>
196201
<Text testID="test_status_label">Test status: {testStatusString}</Text>
197202
<Text testID="test_result_label">Test result: {testResult}</Text>
@@ -233,10 +238,10 @@ const IntegrationTestsScreen = () => {
233238
}}
234239
/>
235240
<Button
236-
title="Test3"
237-
testID="Test3"
241+
title="testNavigationToSingleDestination"
242+
testID="testNavigationToSingleDestination"
238243
onPress={() => {
239-
runTest('test3');
244+
runTest('testNavigationToSingleDestination');
240245
}}
241246
/>
242247
</OverlayModal>

example/src/screens/integration_tests/integration_test.ts

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type {
18-
MapViewController,
19-
NavigationCallbacks,
20-
NavigationController,
21-
NavigationInitErrorCode,
17+
import {
18+
TravelMode,
19+
type MapViewController,
20+
type NavigationCallbacks,
21+
type NavigationController,
22+
type NavigationInitErrorCode,
23+
type NavigationViewController,
2224
} from '@googlemaps/react-native-navigation-sdk';
2325
import { Platform } from 'react-native';
2426

2527
interface TestTools {
2628
navigationController: NavigationController;
2729
mapViewController: MapViewController | null;
30+
navigationViewController: NavigationViewController | null;
2831
addListeners: (listeners: Partial<NavigationCallbacks>) => void;
2932
removeListeners: (listeners: Partial<NavigationCallbacks>) => void;
3033
passTest: () => void;
@@ -166,4 +169,52 @@ export const testMapInitialization = async (testTools: TestTools) => {
166169
passTest();
167170
};
168171

169-
export const runTest3 = async () => {};
172+
export const testNavigationToSingleDestination = async (
173+
testTools: TestTools
174+
) => {
175+
const { navigationController, addListeners, passTest, failTest } = testTools;
176+
addListeners({
177+
onNavigationReady: async () => {
178+
await navigationController.simulator.simulateLocation({
179+
lat: 37.4195823,
180+
lng: -122.0799018,
181+
});
182+
await navigationController.setDestinations(
183+
[
184+
{
185+
position: {
186+
lat: 37.4152112,
187+
lng: -122.0813741,
188+
},
189+
},
190+
],
191+
{
192+
travelMode: TravelMode.DRIVING,
193+
avoidFerries: true,
194+
avoidTolls: false,
195+
}
196+
);
197+
await navigationController.startGuidance();
198+
199+
// Timeout here is used to avoid issues on Android.
200+
setTimeout(() => {
201+
navigationController.simulator.simulateLocationsAlongExistingRoute({
202+
speedMultiplier: 5,
203+
});
204+
}, 3000);
205+
},
206+
onNavigationInitError: (errorCode: NavigationInitErrorCode) => {
207+
console.log(errorCode);
208+
failTest('onNavigatonInitError');
209+
},
210+
onArrival() {
211+
passTest();
212+
},
213+
});
214+
try {
215+
await navigationController.init();
216+
} catch (error) {
217+
console.error('Error initializing navigator', error);
218+
failTest('navigationController.init() exception');
219+
}
220+
};

0 commit comments

Comments
 (0)