Skip to content

Commit

Permalink
feat: bump generic iPhone for iOS 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham committed Sep 16, 2019
1 parent 30c63b6 commit 4da3461
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
10 changes: 10 additions & 0 deletions lib/ios-generic-simulators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
'ipad simulator': [
['0.0', 'iPad Retina'],
['10.3', 'iPad Air'],
],
'iphone simulator': [
['0.0', 'iPhone 6'],
['13.0', 'iPhone X'],
]
};
36 changes: 23 additions & 13 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SubProcess, exec } from 'teen_process';
import xcode from 'appium-xcode';
import _ from 'lodash';
import log from './logger';
import iosGenericSimulators from './ios-generic-simulators';
import _fs from 'fs';
import url from 'url';
import v8 from 'v8';
Expand Down Expand Up @@ -57,23 +58,32 @@ async function getAndCheckIosSdkVersion () {
}
}

function translateDeviceName (platformVersion, devName = '') {
let deviceName = devName;
switch (devName.toLowerCase().trim()) {
case 'iphone simulator':
deviceName = 'iPhone 6';
break;
case 'ipad simulator':
// iPad Retina is no longer available for ios 10.3
// so we pick another iPad to use as default
deviceName = platformVersion && util.compareVersions(platformVersion, '<', '10.3') ? 'iPad Retina' : 'iPad Air';
/**
* Get the generic simulator for a given IOS version and device type (iPhone, iPad)
*
* @param {string|number} platformVersion IOS version. e.g.) 13.0
* @param {string} deviceName Type of IOS device. Can be iPhone, iPad (possibly more in the future)
*/
function getGenericSimulatorForIosVersion (platformVersion, deviceName) {
const genericSimulators = iosGenericSimulators[deviceName];
let genericIosSimulator;

// Find the highest iOS version in the list that is below the provided version
for (const [platformVersionFromList, iosSimulator] of genericSimulators) {
if (util.compareVersions(platformVersionFromList, '>', platformVersion)) {
break;
}
genericIosSimulator = iosSimulator;
}
return genericIosSimulator;
}

if (deviceName !== devName) {
log.debug(`Changing deviceName from '${devName}' to '${deviceName}'`);
function translateDeviceName (platformVersion, deviceName = '') {
const translatedDeviceName = getGenericSimulatorForIosVersion(platformVersion, deviceName.toLowerCase().trim());
if (translatedDeviceName !== deviceName) {
log.debug(`Changing deviceName from '${deviceName}' to '${translatedDeviceName}'`);
}
return deviceName;
return translatedDeviceName;
}

// This map contains derived data logs folders as keys
Expand Down
26 changes: 22 additions & 4 deletions test/unit/utils-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,38 @@ describe('utils', function () {
}));

describe('determineDevice', function () {
const ipadDeviceName = 'iPad Simulator';
const iphoneDeviceName = 'iPhone Simulator';
const outrageouslyHighIosVersion = '999999.999999';

it('should set the correct iPad simulator generic device', function () {
const ipadDeviceName = 'iPad Simulator';
let deviceName = translateDeviceName('10.1.2', ipadDeviceName);
deviceName.should.equal('iPad Retina');
deviceName = translateDeviceName(10.103, ipadDeviceName);
});
it('should set the correct iPad simulator generic device for iOS >= 10.3', function () {
let deviceName = translateDeviceName(10.103, ipadDeviceName);
deviceName.should.equal('iPad Air');
deviceName = translateDeviceName('10.3', ipadDeviceName);
deviceName.should.equal('iPad Air');
deviceName = translateDeviceName(10.3, ipadDeviceName);
deviceName.should.equal('iPad Air');
});
it('should set the correct iPhone simulator generic device', function () {
let deviceName = translateDeviceName(10.3, 'iPhone Simulator');
deviceName.should.equal('iPhone 6');
translateDeviceName('0.0', iphoneDeviceName).should.equal('iPhone 6');
translateDeviceName('10.3', iphoneDeviceName).should.equal('iPhone 6');
});
it('should set the correct iPhone simulator generic device for simulators gte iOS 13.0', function () {
translateDeviceName('13.0', iphoneDeviceName).should.equal('iPhone X');
});
it('should set the default iPhone simulator to the highest generic device that is defined in ios-generic-simulators.js', function () {
// The highest iOS version we define for iPhone in ios-generic-simulators.js is currently iOS 13.0
// If this changes, update this test
translateDeviceName(outrageouslyHighIosVersion, iphoneDeviceName).should.equal('iPhone X');
});
it('should set the default iPad simulator to the highest generic device that is defined in ios-generic-simulators.js', function () {
// The highest iOS version for iPad we define in ios-generic-simulators.js is currently iOS 10.3
// If this changes, update this test
translateDeviceName(outrageouslyHighIosVersion, ipadDeviceName).should.equal('iPad Air');
});
});

Expand Down

0 comments on commit 4da3461

Please sign in to comment.