From 84197da3c609a784d872b59e1f86130d8156f55b Mon Sep 17 00:00:00 2001 From: Jayme Deffenbaugh Date: Thu, 7 Aug 2014 13:20:33 -0700 Subject: [PATCH] Fix for #3325. localizableStrings is no longer an array --- lib/devices/ios/ios-controller.js | 4 +- .../StubApp.app/en.lproj/InfoPlist.strings | Bin 0 -> 42 bytes .../StubApp.app/en.lproj/Localizable.strings | Bin 0 -> 83 bytes test/unit/ios-controller-specs.js | 2 +- test/unit/ios-device-specs.js | 66 ++++++++++++++++++ test/unit/queue-specs.js | 35 +--------- 6 files changed, 71 insertions(+), 36 deletions(-) create mode 100644 test/fixtures/localization_tests/StubApp.app/en.lproj/InfoPlist.strings create mode 100644 test/fixtures/localization_tests/StubApp.app/en.lproj/Localizable.strings create mode 100644 test/unit/ios-device-specs.js diff --git a/lib/devices/ios/ios-controller.js b/lib/devices/ios/ios-controller.js index 25aa084e0..bd018ad4a 100644 --- a/lib/devices/ios/ios-controller.js +++ b/lib/devices/ios/ios-controller.js @@ -256,8 +256,8 @@ iOSController.getLocalizedStringForSelector = function (selector) { var newSelector = selector; var strings = this.localizableStrings; - if (strings && strings.length >= 1) { - var localizedSelector = strings[0][selector]; + if (strings) { + var localizedSelector = strings[selector]; if (localizedSelector) { newSelector = localizedSelector; } else { diff --git a/test/fixtures/localization_tests/StubApp.app/en.lproj/InfoPlist.strings b/test/fixtures/localization_tests/StubApp.app/en.lproj/InfoPlist.strings new file mode 100644 index 0000000000000000000000000000000000000000..3967e063f94f2b9de2fdbeb4d90be9963443c793 GIT binary patch literal 42 dcmYc)$jK}&F)+Bm!2kw~j1ZauMnky_oB)p~1JeKi literal 0 HcmV?d00001 diff --git a/test/fixtures/localization_tests/StubApp.app/en.lproj/Localizable.strings b/test/fixtures/localization_tests/StubApp.app/en.lproj/Localizable.strings new file mode 100644 index 0000000000000000000000000000000000000000..ed5825b6a4012f8cb091d0d8ac118ee6f9cf59bc GIT binary patch literal 83 zcmYc)$jK}&F)+Bu$P_OimYbNFr> N2%#C6p)`y#000zN5)c3Y literal 0 HcmV?d00001 diff --git a/test/unit/ios-controller-specs.js b/test/unit/ios-controller-specs.js index f091f213b..c48371cd6 100644 --- a/test/unit/ios-controller-specs.js +++ b/test/unit/ios-controller-specs.js @@ -41,7 +41,7 @@ describe('ios-controller', function () { }); describe('when there are localizableStrings', function () { beforeEach(function () { - var locString = [{'someSelector': 'localSelector'}]; + var locString = {'someSelector': 'localSelector'}; controller.localizableStrings = locString; }); afterEach(function () { diff --git a/test/unit/ios-device-specs.js b/test/unit/ios-device-specs.js new file mode 100644 index 000000000..3f4d8d7d8 --- /dev/null +++ b/test/unit/ios-device-specs.js @@ -0,0 +1,66 @@ +// Run with mocha by installing dev deps: npm install --dev +// more docs on writing tests with mocha can be found here: +// http://visionmedia.github.com/mocha/ +"use strict"; + +require('chai'); + +var path = require('path') + , _ = require('underscore') + , IOS = require('../../lib/devices/ios/ios.js'); + +describe('IOS', function () { + var device; + + beforeEach(function () { + device = new IOS(); + }); + + describe('#proxy()', function () { + beforeEach(function () { + // we'd like to test ios.proxy; mock instruments + device.commandProxy = {}; + device.commandProxy.sendCommand = function (cmd, cb) { + // let's pretend we've got some latency here. + var to = Math.round(Math.random() * 10); + setTimeout(function () { cb([cmd, to]); }, to); + }; + }); + + return it('should execute one command at a time keeping the seq right', function (done) { + var intercept = [] + , iterations = 100 + , check = function (err, result) { + intercept.push(result); + if (intercept.length >= iterations) { + for (var x = 0; x < iterations; x++) { + intercept[x][0].should.equal('' + x); + } + done(); + } + }; + + for (var i = 0; i < iterations; i++) { + device.proxy("" + i, check); + } + }); + }); + + describe('#parseLocalizableStrings()', function () { + var stubApp = path.resolve(__dirname, '../fixtures/localization_tests/StubApp.app'); + + beforeEach(function () { + _.extend(device.args, { + language : 'en' + , app : stubApp + }); + }); + + it('should return a dictionary', function (done) { + device.parseLocalizableStrings(function () { + device.localizableStrings.should.eql({ 'main.button.computeSum' : 'Compute Sum' }); + done(); + }); + }); + }); +}); diff --git a/test/unit/queue-specs.js b/test/unit/queue-specs.js index 304d83a77..cd1231525 100644 --- a/test/unit/queue-specs.js +++ b/test/unit/queue-specs.js @@ -6,45 +6,14 @@ var chai = require('chai') , should = chai.should() , getAppium = require('../../lib/appium.js') - , path = require('path') , mock = require('../helpers/mock.js') - , IOS = require('../../lib/devices/ios/ios.js'); + , IOS = require('../../lib/devices/ios/ios.js') + , path = require('path'); mock.noop(IOS.prototype, 'start'); mock.noop(IOS.prototype, 'stop'); mock.noop(IOS.prototype, 'configureApp'); -describe('IOS', function () { - // we'd like to test ios.proxy; mock instruments - var inst = new IOS({}); - inst.commandProxy = {}; - inst.commandProxy.sendCommand = function (cmd, cb) { - // let's pretend we've got some latency here. - var to = Math.round(Math.random() * 10); - setTimeout(function () { cb([cmd, to]); }, to); - }; - - describe('#proxy()', function () { - return it('should execute one command at a time keeping the seq right', function (done) { - var intercept = [] - , iterations = 100 - , check = function (err, result) { - intercept.push(result); - if (intercept.length >= iterations) { - for (var x = 0; x < iterations; x++) { - intercept[x][0].should.equal('' + x); - } - done(); - } - }; - - for (var i = 0; i < iterations; i++) { - inst.proxy("" + i, check); - } - }); - }); -}); - describe('Appium', function () { var intercept = [] , logPath = path.resolve(__dirname, "../../../appium.log")