Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public class JsErrors {
public static final String NO_MAP_ERROR_CODE = "NO_MAP_ERROR_CODE";
public static final String NO_MAP_ERROR_MESSAGE =
"Make sure to initialize the map view has been initialized before executing.";

public static final String NO_DESTINATIONS_ERROR_CODE = "NO_DESTINATIONS";
public static final String NO_DESTINATIONS_ERROR_MESSAGE = "Destinations not set";
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ public Map<String, Object> getConstants() {
}

@ReactMethod
private void cleanup() {
public void cleanup(final Promise promise) {
if (!ensureNavigatorAvailable(promise)) {
return;
}

stopUpdatingLocation();
removeNavigationListeners();
mWaypoints.clear();
Expand All @@ -160,10 +164,12 @@ private void cleanup() {
listener.onReady(false);
}

final Navigator navigator = mNavigator;
UiThreadUtil.runOnUiThread(
() -> {
mNavigator.clearDestinations();
mNavigator.cleanup();
navigator.clearDestinations();
navigator.cleanup();
promise.resolve(true);
});
}

Expand Down Expand Up @@ -282,6 +288,10 @@ public void onError(@NavigationApi.ErrorCode int errorCode) {
public void setTurnByTurnLoggingEnabled(boolean isEnabled) {
final Activity currentActivity = getReactApplicationContext().getCurrentActivity();
if (currentActivity == null) return;
if (mNavigator == null) {
logDebugInfo(JsErrors.NO_NAVIGATOR_ERROR_MESSAGE);
return;
}

if (isEnabled) {
NavForwardingManager.startNavForwarding(mNavigator, currentActivity, this);
Expand All @@ -295,6 +305,9 @@ public void setTurnByTurnLoggingEnabled(boolean isEnabled) {
* navigation events occur (e.g. the driver's route changes or the destination is reached).
*/
private void registerNavigationListeners() {
if (mNavigator == null) {
return;
}
removeNavigationListeners();

mArrivalListener =
Expand Down Expand Up @@ -353,6 +366,9 @@ public void onRemainingTimeOrDistanceChanged() {
}

private void removeNavigationListeners() {
if (mNavigator == null) {
return;
}
if (mArrivalListener != null) {
mNavigator.removeArrivalListener(mArrivalListener);
}
Expand Down Expand Up @@ -417,19 +433,20 @@ private void createWaypoint(Map map) {
public void setDestination(
ReadableMap waypoint,
@Nullable ReadableMap routingOptions,
@Nullable ReadableMap displayOptions) {
@Nullable ReadableMap displayOptions,
final Promise promise) {
WritableArray array = new WritableNativeArray();
array.pushMap(waypoint);
setDestinations(array, routingOptions, displayOptions);
setDestinations(array, routingOptions, displayOptions, promise);
}

@ReactMethod
public void setDestinations(
ReadableArray waypoints,
@Nullable ReadableMap routingOptions,
@Nullable ReadableMap displayOptions) {
if (mNavigator == null) {
// TODO: HANDLE THIS
@Nullable ReadableMap displayOptions,
final Promise promise) {
if (!ensureNavigatorAvailable(promise)) {
return;
}

Expand Down Expand Up @@ -462,42 +479,63 @@ public void setDestinations(
if (pendingRoute != null) {
// Set an action to perform when a route is determined to the destination
pendingRoute.setOnResultListener(
code -> sendCommandToReactNative("onRouteStatusResult", code.toString()));
code -> {
sendCommandToReactNative("onRouteStatusResult", code.toString());
promise.resolve(true);
});
} else {
promise.resolve(true);
}
}

@ReactMethod
public void clearDestinations() {
if (mNavigator != null) {
mWaypoints.clear(); // reset waypoints
mNavigator.clearDestinations();
public void clearDestinations(final Promise promise) {
if (!ensureNavigatorAvailable(promise)) {
return;
}
mWaypoints.clear(); // reset waypoints
mNavigator.clearDestinations();
promise.resolve(true);
}

@ReactMethod
public void continueToNextDestination() {
if (mNavigator != null) {
mNavigator.continueToNextDestination();
public void continueToNextDestination(final Promise promise) {
if (!ensureNavigatorAvailable(promise)) {
return;
}
mNavigator.continueToNextDestination();
promise.resolve(true);
}

@ReactMethod
public void startGuidance() {
public void startGuidance(final Promise promise) {
if (!ensureNavigatorAvailable(promise)) {
return;
}
if (mWaypoints.isEmpty()) {
promise.reject(JsErrors.NO_DESTINATIONS_ERROR_CODE, JsErrors.NO_DESTINATIONS_ERROR_MESSAGE);
return;
}

mNavigator.startGuidance();
sendCommandToReactNative("onStartGuidance", null);
promise.resolve(true);
}

@ReactMethod
public void stopGuidance() {
public void stopGuidance(final Promise promise) {
if (!ensureNavigatorAvailable(promise)) {
return;
}
mNavigator.stopGuidance();
promise.resolve(true);
}

@ReactMethod
public void simulateLocationsAlongExistingRoute(float speedMultiplier) {
if (mNavigator == null) {
return;
}
if (mWaypoints.isEmpty()) {
return;
}
Expand All @@ -510,16 +548,25 @@ public void simulateLocationsAlongExistingRoute(float speedMultiplier) {

@ReactMethod
public void stopLocationSimulation() {
if (mNavigator == null) {
return;
}
mNavigator.getSimulator().unsetUserLocation();
}

@ReactMethod
public void pauseLocationSimulation() {
if (mNavigator == null) {
return;
}
mNavigator.getSimulator().pause();
}

@ReactMethod
public void resumeLocationSimulation() {
if (mNavigator == null) {
return;
}
mNavigator.getSimulator().resume();
}

Expand All @@ -530,6 +577,9 @@ public void setAbnormalTerminatingReportingEnabled(boolean isOn) {

@ReactMethod
public void setSpeedAlertOptions(@Nullable ReadableMap options) {
if (mNavigator == null) {
return;
}
if (options == null) {
mNavigator.setSpeedAlertOptions(null);
return;
Expand Down Expand Up @@ -650,6 +700,14 @@ private void sendCommandToReactNative(String functionName, @Nullable Object para
}
}

private boolean ensureNavigatorAvailable(final Promise promise) {
if (mNavigator == null) {
promise.reject(JsErrors.NO_NAVIGATOR_ERROR_CODE, JsErrors.NO_NAVIGATOR_ERROR_MESSAGE);
return false;
}
return true;
}

@ReactMethod
public void simulateLocation(ReadableMap location) {
if (mNavigator != null) {
Expand Down
2 changes: 1 addition & 1 deletion example/.detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = {
type: 'ios.simulator',
device: {
type: 'iPhone 16 Pro',
os: 'iOS 18.5',
os: 'iOS 18.6',
},
},
attached: {
Expand Down
6 changes: 5 additions & 1 deletion example/e2e/event_listener.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {
selectTestByName,
waitForTestToFinish,
expectSuccess,
expectNoErrors,
} from './shared.js';

describe('Even listener tests', () => {
describe('Event listener tests', () => {
beforeEach(async () => {
await initializeIntegrationTestsPage();
});
Expand All @@ -31,20 +32,23 @@ describe('Even listener tests', () => {
await selectTestByName('testOnRemainingTimeOrDistanceChanged');
await agreeToTermsAndConditions();
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T02 - test onArrival event listener', async () => {
await selectTestByName('testOnArrival');
await agreeToTermsAndConditions();
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T03 - test onRouteChanged event listener', async () => {
await selectTestByName('testOnRouteChanged');
await agreeToTermsAndConditions();
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});
});
17 changes: 4 additions & 13 deletions example/e2e/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import {
selectTestByName,
waitForTestToFinish,
expectSuccess,
expectNoErrors,
} from './shared.js';
import { element, by, log } from 'detox';

describe('Map view tests', () => {
beforeEach(async () => {
Expand All @@ -30,30 +30,21 @@ describe('Map view tests', () => {
it('T01 - initialize map and test default values', async () => {
await selectTestByName('testMapInitialization');
await waitForTestToFinish();
const failureMessageLabel = element(by.id('failure_message_label'));
const attributes = await failureMessageLabel.getAttributes();
log.error(attributes.text);
await expect(element(by.id('failure_message_label'))).toHaveText('');
await expectNoErrors();
await expectSuccess();
});

it('T02 - initialize map and test move camera', async () => {
await selectTestByName('testMoveCamera');
await waitForTestToFinish();
const failureMessageLabel = element(by.id('failure_message_label'));
const attributes = await failureMessageLabel.getAttributes();
log.error(attributes.text);
await expect(element(by.id('failure_message_label'))).toHaveText('');
await expectNoErrors();
await expectSuccess();
});

it('T03 - initialize map and test camera tilt bearing zoom', async () => {
await selectTestByName('testTiltZoomBearingCamera');
await waitForTestToFinish();
const failureMessageLabel = element(by.id('failure_message_label'));
const attributes = await failureMessageLabel.getAttributes();
log.error(attributes.text);
await expect(element(by.id('failure_message_label'))).toHaveText('');
await expectNoErrors();
await expectSuccess();
});
});
30 changes: 21 additions & 9 deletions example/e2e/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
selectTestByName,
waitForTestToFinish,
expectSuccess,
expectNoErrors,
} from './shared.js';
import { element, by, log } from 'detox';

describe('Navigation tests', () => {
beforeEach(async () => {
Expand All @@ -32,42 +32,54 @@ describe('Navigation tests', () => {
await selectTestByName('testNavigationSessionInitialization');
await agreeToTermsAndConditions();
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T02 - initialize navigation controller and navigate to single destination', async () => {
await selectTestByName('testNavigationToSingleDestination');
await agreeToTermsAndConditions();
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T03 - initialize navigation controller and navigate to multiple destinations', async () => {
await selectTestByName('testNavigationToMultipleDestination');
await agreeToTermsAndConditions();
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T04 - initialize navigation controller and test route segments', async () => {
await selectTestByName('testRouteSegments');
await agreeToTermsAndConditions();
const failureMessageLabel = element(by.id('failure_message_label'));
const attributes = await failureMessageLabel.getAttributes();
log.error(attributes.text);
await expect(element(by.id('failure_message_label'))).toHaveText('');
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T05 - initialize navigation controller and test remaining time and distance', async () => {
await selectTestByName('testGetCurrentTimeAndDistance');
await agreeToTermsAndConditions();
const failureMessageLabel = element(by.id('failure_message_label'));
const attributes = await failureMessageLabel.getAttributes();
log.error(attributes.text);
await expect(element(by.id('failure_message_label'))).toHaveText('');
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T06 - expect navigation controller calls to fail when not initialized', async () => {
await selectTestByName('testNavigationStateGuards');
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});

it('T07 - require destinations before starting guidance', async () => {
await selectTestByName('testStartGuidanceWithoutDestinations');
await agreeToTermsAndConditions();
await waitForTestToFinish();
await expectNoErrors();
await expectSuccess();
});
});
Loading
Loading