Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

device: add resetContentAndSettings #217

Merged
merged 2 commits into from
Aug 15, 2017
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
4 changes: 4 additions & 0 deletions detox/src/devices/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class Device {
await this.deviceDriver.disableSynchronization();
}

async resetContentAndSettings() {
await this.deviceDriver.resetContentAndSettings(this._deviceId);
}

getPlatform() {
return this.deviceDriver.getPlatform(this._deviceId);
}
Expand Down
7 changes: 7 additions & 0 deletions detox/src/devices/Device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ describe('Device', () => {
expect(device.deviceDriver.disableSynchronization).toHaveBeenCalledTimes(1);
});

it(`resetContentAndSettings() should pass to device driver`, async () => {
device = validDevice();
await device.resetContentAndSettings();

expect(device.deviceDriver.resetContentAndSettings).toHaveBeenCalledTimes(1);
});

it(`getPlatform() should pass to device driver`, async () => {
device = validDevice();
device.getPlatform();
Expand Down
4 changes: 4 additions & 0 deletions detox/src/devices/DeviceDriverBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class DeviceDriverBase {
return await Promise.resolve('');
}

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

defaultLaunchArgsPrefix() {
return '';
}
Expand Down
8 changes: 8 additions & 0 deletions detox/src/devices/Fbsimctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ class Fbsimctl {
await this._execFbsimctlCommand(options);
}

async resetContentAndSettings(udid) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is better suited as an input param to device.launchApp(), inline with other API we have.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would you name that param? clean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it fits launchApp since it has no relation to the app, it's more of a device function (like setLocation or setOrientation)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean can be confusing, since a user might think this option cleans the app, not resets the entire simulator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so is it alright then or do you want me to change something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeoNatan just wanted to know if there are still concerns about the PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Need @rotemmiz to approve it, as he is the JS master around here. 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never wished for this title :( ...
Let's talk a bit about the API:

  1. I don't this is not a good API for reseting a permission, I much prefer if we can add an unset state to permissions with appleSimUtils Unsetting an already set permission AppleSimulatorUtils#8
  2. Can there still can be a valid test case for resetting a device?
  3. Since we aim Detox to be multi-platform framework I prefer not to give this method a name which is strongly recognized with Apple's terms, let's try thinking of something more generic maybe, like reset or clearData (not sure if these are better names). WDYT ?

await this.shutdown(udid);
const result = await exec.execWithRetriesAndLogs(`/usr/bin/xcrun simctl erase ${udid}`);
const resultCode = parseInt(result.stdout.trim().split(':')[1]);
await this.boot(udid);
return resultCode;
}

async _execFbsimctlCommand(options, statusLogs, retries, interval) {
const bin = `fbsimctl --json`;
return await exec.execWithRetriesAndLogs(bin, options, statusLogs, retries, interval);
Expand Down
11 changes: 11 additions & 0 deletions detox/src/devices/Fbsimctl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ describe('Fbsimctl', () => {
await validateFbsimctlisCalledOn(fbsimctl, async () => fbsimctl.setLocation(simUdid));
});

it(`resetContentAndSettings() - is triggering shutdown, exec and boot`, async() => {
fs.existsSync.mockReturnValue(true);
exec.mockReturnValue({stdout: "appId: 22 \n"});
fbsimctl.shutdown = jest.fn();
fbsimctl.boot = jest.fn();
await fbsimctl.resetContentAndSettings(simUdid);
expect(fbsimctl.shutdown).toHaveBeenCalledTimes(1);
expect(exec).toHaveBeenCalledTimes(1);
expect(fbsimctl.boot).toHaveBeenCalledTimes(1);
});

it(`exec simulator command successfully`, async() => {
const result = returnSuccessfulWithValue("");
exec.mockReturnValue(Promise.resolve(result));
Expand Down
4 changes: 4 additions & 0 deletions detox/src/devices/SimulatorDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class SimulatorDriver extends IosDriver {
await this._applesimutils.setPermissions(deviceId, bundleId, permissions);
}

async resetContentAndSettings(deviceId) {
return await this._fbsimctl.resetContentAndSettings(deviceId);
}

validateDeviceConfig(deviceConfig) {
if (!deviceConfig.binaryPath) {
configuration.throwOnEmptyBinaryPath();
Expand Down
9 changes: 9 additions & 0 deletions detox/test/e2e/f-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describe('Device', () => {
await expect(element(by.label('Hello!!!'))).toBeVisible();
});

it('resetContentAndSettings() + install() + relaunch() - should tap successfully', async () => {
await device.resetContentAndSettings();
await device.installApp();
await device.launchApp({ newInstance: true });
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
});

describe('device orientation', () => {
beforeEach(async() => {
await device.reloadReactNative();
Expand Down
12 changes: 11 additions & 1 deletion docs/APIRef.DeviceObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [`device.setURLBlacklist([urls])`](#deviceseturlblacklisturls)
- [`device.enableSynchronization()`](#deviceenablesynchronization)
- [`device.disableSynchronization()`](#devicedisablesynchronization)
- [`device.resetContentAndSettings()`](#resetcontentandsettings)

### `device.launchApp(params)`
Launch the app defined in the current [`configuration`](APIRef.Configuration.md).
Expand Down Expand Up @@ -190,4 +191,13 @@ Disable [EarlGrey's synchronization mechanism](https://github.com/google/EarlGre

```js
await device.disableSynchronization();
```
```


### `device.resetContentAndSettings()`
Resets the Simulator to clean state (like the Simulator > Reset Content and Settings... menu item), especially removing
previously set permissions.

```js
await device.resetContentAndSettings();
```