Skip to content

Commit

Permalink
Merge pull request #161 from KazuCocoa/fix-get-biometric
Browse files Browse the repository at this point in the history
fix getting biometric
  • Loading branch information
KazuCocoa committed Jul 8, 2018
2 parents 640be51 + 7a6d9da commit 44e0139
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/simulator-xcode-9.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ class SimulatorXcode9 extends SimulatorXcode8 {
`;
}

/**
* Return proper biometric menu name object.
* @param {string} biometricName A key in BIOMETRICS like 'bundleId'
* @returns {object} Object in BIOMETRICS
*/
getBiometric (biometricName) {
const {BIOMETRICS} = SimulatorXcode9;
if (!BIOMETRICS[biometricName]) {
Expand All @@ -298,7 +303,7 @@ class SimulatorXcode9 extends SimulatorXcode8 {
* Get the current state of a biometric (touch id, face id) enrollment.
* @override
*/
async isBiometricEnrolled (biometricName=SimulatorXcode9.BIOMETRICS.touchId) {
async isBiometricEnrolled (biometricName = 'touchId') {
const {menuName} = this.getBiometric(biometricName);
const output = await this.executeUIClientScript(`
tell application "System Events"
Expand All @@ -317,7 +322,7 @@ class SimulatorXcode9 extends SimulatorXcode8 {
* Execute a special Apple script, which enrolls biometric (TouchId, FaceId) feature testing in Simulator UI client.
* @override
*/
async enrollBiometric (isEnabled = true, biometricName=SimulatorXcode9.BIOMETRICS.touchId) {
async enrollBiometric (isEnabled = true, biometricName = 'touchId') {
const {menuName} = this.getBiometric(biometricName);
await this.executeUIClientScript(`
tell application "System Events"
Expand Down
36 changes: 36 additions & 0 deletions test/unit/simulator-xcode-9-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// transpile:mocha

import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import SimulatorXcode9 from "../../lib/simulator-xcode-9";

chai.should();
chai.use(chaiAsPromised);

const XCODE_VERSION_9 = {
versionString: '9.0',
versionFloat: 9.0,
major: 9,
minor: 0,
patch: undefined
};

describe('SimulatorXcode9', function () {
let simulatorXcode9;

beforeEach(function () {
simulatorXcode9 = new SimulatorXcode9('1234', XCODE_VERSION_9);
});

describe('getBiometric', function () {
it('return touch id object', async function () {
simulatorXcode9.getBiometric('touchId').should.eql({ menuName: 'Touch Id' });
});

it('raise an error since the argument does not exist in biometric', async function () {
(function () {
simulatorXcode9.getBiometric('no-touchId');
}).should.throw(Error, 'no-touchId is not a valid biometric. Use one of: ["touchId","faceId"]');
});
});
});

0 comments on commit 44e0139

Please sign in to comment.