From 41c9a5f40d8d90fe00dec6f2a9cd5f3a5a6117b8 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 3 Dec 2018 08:35:43 +0900 Subject: [PATCH] Calls helpers.ensureDeviceLocale if the opts has either language or locale (#477) --- lib/android-helpers.js | 4 +++- test/unit/android-helper-specs.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/android-helpers.js b/lib/android-helpers.js index a8e247be..c090a3da 100644 --- a/lib/android-helpers.js +++ b/lib/android-helpers.js @@ -635,7 +635,9 @@ helpers.initDevice = async function (adb, opts) { await helpers.setMockLocationApp(adb, SETTINGS_HELPER_PKG_ID); } - await helpers.ensureDeviceLocale(adb, opts.language, opts.locale, opts.localeScript); + if (opts.language || opts.locale) { + await helpers.ensureDeviceLocale(adb, opts.language, opts.locale, opts.localeScript); + } await adb.startLogcat(); if (opts.unicodeKeyboard) { return await helpers.initUnicodeKeyboard(adb); diff --git a/test/unit/android-helper-specs.js b/test/unit/android-helper-specs.js index 4c1fb820..7a28ca57 100644 --- a/test/unit/android-helper-specs.js +++ b/test/unit/android-helper-specs.js @@ -673,12 +673,34 @@ describe('Android Helpers', function () { mocks.helpers.verify(); mocks.adb.verify(); }); + it('should init device without locale and language', async function () { + const opts = {}; + mocks.adb.expects('waitForDevice').once(); + mocks.adb.expects('startLogcat').once(); + mocks.helpers.expects('pushSettingsApp').once(); + mocks.helpers.expects('ensureDeviceLocale').never(); + mocks.helpers.expects('setMockLocationApp').withExactArgs(adb, 'io.appium.settings').once(); + await helpers.initDevice(adb, opts); + mocks.helpers.verify(); + mocks.adb.verify(); + }); + it('should init device with either locale or language', async function () { + const opts = {language: "en"}; + mocks.adb.expects('waitForDevice').once(); + mocks.adb.expects('startLogcat').once(); + mocks.helpers.expects('pushSettingsApp').once(); + mocks.helpers.expects('ensureDeviceLocale').withExactArgs(adb, opts.language, opts.locale, opts.localeScript).once(); + mocks.helpers.expects('setMockLocationApp').withExactArgs(adb, 'io.appium.settings').once(); + await helpers.initDevice(adb, opts); + mocks.helpers.verify(); + mocks.adb.verify(); + }); it('should not install mock location on emulator', async function () { const opts = {avd: "avd"}; mocks.adb.expects('waitForDevice').once(); mocks.adb.expects('startLogcat').once(); mocks.helpers.expects('pushSettingsApp').once(); - mocks.helpers.expects('ensureDeviceLocale').withArgs(adb).once(); + mocks.helpers.expects('ensureDeviceLocale').never(); mocks.helpers.expects('setMockLocationApp').never(); await helpers.initDevice(adb, opts); mocks.helpers.verify(); @@ -689,7 +711,7 @@ describe('Android Helpers', function () { mocks.adb.expects('waitForDevice').once(); mocks.adb.expects('startLogcat').once(); mocks.helpers.expects('pushSettingsApp').once(); - mocks.helpers.expects('ensureDeviceLocale').once(); + mocks.helpers.expects('ensureDeviceLocale').never(); mocks.helpers.expects('setMockLocationApp').once(); mocks.helpers.expects('initUnicodeKeyboard').withExactArgs(adb).once().returns("defaultIME"); await helpers.initDevice(adb, opts).should.become("defaultIME"); @@ -701,7 +723,7 @@ describe('Android Helpers', function () { mocks.adb.expects('waitForDevice').once(); mocks.adb.expects('startLogcat').once(); mocks.helpers.expects('pushSettingsApp').once(); - mocks.helpers.expects('ensureDeviceLocale').once(); + mocks.helpers.expects('ensureDeviceLocale').never(); mocks.helpers.expects('setMockLocationApp').once(); mocks.helpers.expects('initUnicodeKeyboard').never(); should.not.exist(await helpers.initDevice(adb, opts)); @@ -713,7 +735,7 @@ describe('Android Helpers', function () { mocks.adb.expects('waitForDevice').once(); mocks.adb.expects('startLogcat').once(); mocks.helpers.expects('pushSettingsApp').once(); - mocks.helpers.expects('ensureDeviceLocale').once(); + mocks.helpers.expects('ensureDeviceLocale').never(); mocks.helpers.expects('setMockLocationApp').once(); mocks.helpers.expects('initUnicodeKeyboard').never(); await helpers.initDevice(adb, opts);