Skip to content

Commit

Permalink
openURL now uses internal mocking mechanism instead of fbsimctl
Browse files Browse the repository at this point in the history
  • Loading branch information
rotemmiz committed Jul 4, 2017
1 parent 6510909 commit 6b6b3d3
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion detox/ios/Detox/DetoxManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 117,7 @@ - (void) websocketDidReceiveAction:(NSString *)type withParams:(NSDictionary *)p
}
else if([type isEqualToString:@"openURL"])
{
NSURL* URLToOpen = [NSURL fileURLWithPath:params[@"url"]];
NSURL* URLToOpen = [NSURL URLWithString:params[@"url"]];

NSParameterAssert(URLToOpen != nil);

Expand Down
4 changes: 4 additions & 0 deletions detox/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,10 @@ class Client {
await this.sendAction(new actions.CurrentStatus());
}

async openURL(params) {
await this.sendAction(new actions.openURL(params));
}

async execute(invocation) {
if (typeof invocation === 'function') {
invocation = invocation();
Expand Down
11 changes: 11 additions & 0 deletions detox/src/client/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 89,16 @@ class SendUserNotification extends Action {
}
}

class openURL extends Action {
constructor(params) {
super('openURL', params);
}

async handle(response) {
this.expectResponseOfType(response, 'openURLDone');
}
}

class CurrentStatus extends Action {
constructor(params) {
super('currentStatus', params);
Expand All @@ -111,6 121,7 @@ module.exports = {
Invoke,
ReloadReactNative,
Cleanup,
openURL,
SendUserNotification,
CurrentStatus
};
11 changes: 9 additions & 2 deletions detox/src/devices/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 37,9 @@ class Device {
let additionalLaunchArgs;
if (params.url) {
additionalLaunchArgs = {'detoxURLOverride': params.url};
if(params.sourceApp) {
additionalLaunchArgs['detoxSourceAppOverride'] = params.sourceApp;
}
} else if (params.userNotification) {
additionalLaunchArgs = {'detoxUserNotificationDataURL': this.deviceDriver.createPushNotificationJson(params.userNotification)};
}
Expand Down Expand Up @@ -67,8 70,12 @@ class Device {
await this.deviceDriver.reloadReactNative();
}

async openURL(url) {
await this.deviceDriver.openURL(this._deviceId, url);
async openURL(params) {
if(typeof params !== 'object' || !params.url) {
throw new Error(`openURL must be called with JSON params, and a value for 'url' key must be provided. example: await device.openURL({url: "url", sourceApp: "sourceAppBundleID"}`);
}

await this.deviceDriver.openURL(this._deviceId, params);
}

async shutdown() {
Expand Down
2 changes: 1 addition & 1 deletion detox/src/devices/DeviceDriverBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 31,7 @@ class DeviceDriverBase {
return await Promise.resolve('');
}

async openURL() {
async openURL(params) {
return await Promise.resolve('');
}

Expand Down
4 changes: 4 additions & 0 deletions detox/src/devices/IosDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 41,10 @@ class IosDriver extends DeviceDriverBase {
await super.sendUserNotification({detoxUserNotificationDataURL: notificationFilePath});
}

async openURL(deviceId, params) {
this.client.openURL(params);
}

async setURLBlacklist(urlList) {
await this.client.execute(GREYConfiguration.setURLBlacklist(urlList));
}
Expand Down
4 changes: 0 additions & 4 deletions detox/src/devices/SimulatorDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 34,6 @@ class SimulatorDriver extends IosDriver {
await this._fbsimctl.terminate(deviceId, bundleId);
}

async openURL(deviceId, url) {
await this._fbsimctl.open(deviceId, url);
}

async shutdown(deviceId) {
await this._fbsimctl.shutdown(deviceId);
}
Expand Down
10 changes: 8 additions & 2 deletions detox/test/e2e/n-deep-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 6,16 @@ describe.only('Deep Links', () => {
await expect(element(by.label(url))).toBeVisible();
});

it('device.openURL(url) should', async () => {
it('device.openURL({url: url}) should', async () => {
const url = 'detoxtesturlscheme://such-string';
await device.relaunchApp();
await device.openURL(url);

await device.openURL({url: url});
await expect(element(by.label(url))).toBeVisible();
});
});


async function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
6 changes: 3 additions & 3 deletions detox/test/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 55,7 @@ class example extends Component {
componentWillMount() {
PushNotificationIOS.addEventListener('notification', (notification) => this._onNotification(notification));
PushNotificationIOS.addEventListener('localNotification', (notification) => this._onNotification(notification));
Linking.addEventListener('url', (url) => this._handleOpenURL(url));
Linking.addEventListener('url', (params) => this._handleOpenURL(params));
}

render() {
Expand Down Expand Up @@ -98,8 98,8 @@ class example extends Component {
this.setState({notification: notification.getAlert()});
}

_handleOpenURL(url) {
this.setState({url: url});
_handleOpenURL(params) {
this.setState({url: params.url});
}
}

Expand Down

0 comments on commit 6b6b3d3

Please sign in to comment.