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

add script param in setDeviceSysLocaleViaSettingApp #372

Merged
merged 10 commits into from
Nov 5, 2018
12 changes: 9 additions & 3 deletions lib/tools/adb-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,18 @@ methods.isAnimationOn = async function () {
*
* @param {string} language - Language. e.g. en, ja
* @param {string} country - Country. e.g. US, JP
* @param {?string} script - Script. e.g. Hans in `zh-Hans-CN`
*/
methods.setDeviceSysLocaleViaSettingApp = async function (language, country) {
await this.shell(['am', 'broadcast', '-a', LOCALE_SETTING_ACTION,
methods.setDeviceSysLocaleViaSettingApp = async function (language, country, script) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be more readable if we set script to null by default (script = null)

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered the way, too. I'll follow the way.

const param = [
'am', 'broadcast',
'-a', LOCALE_SETTING_ACTION,
'-n', LOCALE_SETTING_RECEIVER,
'--es', 'lang', language.toLowerCase(),
'--es', 'country', country.toUpperCase()]);
'--es', 'country', country.toUpperCase()
].concat(_.isString(script) ? ['--es', 'script', script] : []);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather prefer to use this style:

if (script) {
  params.push('--es', 'script', script);
}


await this.shell(param);
};

/**
Expand Down
3 changes: 3 additions & 0 deletions test/functional/adb-commands-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ describe('adb commands', function () {
await adb.setDeviceSysLocaleViaSettingApp('fr', 'fr');
(await adb.getDeviceSysLocale()).should.equal('fr-FR');

await adb.setDeviceSysLocaleViaSettingApp('zh', 'CN', 'Hans');
(await adb.getDeviceSysLocale()).should.equal('zh-Hans-CN');

await adb.setDeviceSysLocaleViaSettingApp('en', 'us');
(await adb.getDeviceSysLocale()).should.equal('en-US');
});
Expand Down
17 changes: 13 additions & 4 deletions test/unit/adb-commands-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,22 @@ describe('adb commands', withMocks({adb, logcat, teen_process, net}, function (m
});
});
describe('setDeviceSysLocaleViaSettingApp', function () {
const adbArgs = ['am', 'broadcast', '-a', 'io.appium.settings.locale',
'-n', 'io.appium.settings/.receivers.LocaleSettingReceiver',
'--es', 'lang', 'en', '--es', 'country', 'US'];
it('should call shell with locale settings', async function () {
it('should call shell with locale settings without script', async function () {
const adbArgs = ['am', 'broadcast', '-a', 'io.appium.settings.locale',
'-n', 'io.appium.settings/.receivers.LocaleSettingReceiver',
'--es', 'lang', 'en', '--es', 'country', 'US'];

mocks.adb.expects("shell").once().withExactArgs(adbArgs);
await adb.setDeviceSysLocaleViaSettingApp('en', 'US');
});

it('should call shell with locale settings with script', async function () {
const adbArgs = ['am', 'broadcast', '-a', 'io.appium.settings.locale',
'-n', 'io.appium.settings/.receivers.LocaleSettingReceiver',
'--es', 'lang', 'zh', '--es', 'country', 'CN', '--es', 'script', 'Hans'];
mocks.adb.expects("shell").once().withExactArgs(adbArgs);
await adb.setDeviceSysLocaleViaSettingApp('zh', 'CN', 'Hans');
});
});
describe('setGeoLocation', function () {
const location = {
Expand Down