Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calls helpers.ensureDeviceLocale if the opts has either language or locale #477

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be || or && ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| is fine here since if users set only language (or locale), then we should show a message in ensureDeviceLocale to guide them.
We can skip calling the ensureDeviceLocale when they do not specify both language and locale in their capability.

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