Skip to content

Commit

Permalink
Calls helpers.ensureDeviceLocale if the opts has either language or l…
Browse files Browse the repository at this point in the history
…ocale (#477)
  • Loading branch information
KazuCocoa committed Dec 2, 2018
1 parent d651af0 commit 41c9a5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/android-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 26 additions & 4 deletions test/unit/android-helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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");
Expand All @@ -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));
Expand All @@ -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);
Expand Down

0 comments on commit 41c9a5f

Please sign in to comment.