Skip to content

Commit

Permalink
feat: add skipSyncUiTranslation option (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwakizaka authored Nov 24, 2023
1 parent 0be66bd commit 1833e83
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/simulator-xcode-9.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ class SimulatorXcode9 extends SimulatorXcode8 {
/**
* @typedef {Object} LanguageOptions
* @property {string} name The name of the language, for example `de` or `zh-Hant-CN`
* @property {boolean} [skipSyncUiDialogTranslation] no Simulator services will be reset if this option is set to true.
* See https://github.com/appium/appium/issues/19440 for more details
*/

/**
Expand Down Expand Up @@ -600,6 +602,8 @@ class SimulatorXcode9 extends SimulatorXcode8 {
`The 'AppleLanguages' preference is already set to '${globalPrefs.AppleLanguages}'. ` +
`Skipping services reset`
);
} else if (language?.skipSyncUiDialogTranslation) {
log.info('Skipping services reset as requested. This might leave some system UI alerts untranslated');
} else {
log.info(
`Will restart the following services in order to sync UI dialogs translation: ` +
Expand Down
4 changes: 2 additions & 2 deletions test/functional/simulator-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('advanced features', function () {
return this.skip();
}

await sim.configureLocalization({
(await sim.configureLocalization({
language: {
name: 'en'
},
Expand All @@ -290,7 +290,7 @@ describe('advanced features', function () {
name: 'en_US',
layout: 'QWERTY',
}
});
})).should.be.true;
});
});

Expand Down
94 changes: 94 additions & 0 deletions test/unit/simulator-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,98 @@ launchd_s 35621 mwakizaka 16u unix 0x7b7dbedd6d62e84f 0t0 /private/
teenProcess.exec.callCount.should.equal(1);
});
});

describe('configureLocalization', function () {
let sim;
let spawnProcessSpy;
beforeEach(async function () {
const xcodeVersion = {major: 9, versionString: '9.0.0'};
xcodeMock.expects('getVersion').atLeast(1).returns(B.resolve(xcodeVersion));
sim = await getSimulator(UDID);
spawnProcessSpy = sinon.stub(sim.simctl, 'spawnProcess');
});
afterEach(function () {
spawnProcessSpy.reset();
});

describe('locale', function () {
it('should configure locale', async function () {
const options = {locale: {name: 'en_US', calendar: 'gregorian'}};
(await sim.configureLocalization(options)).should.be.true;
spawnProcessSpy.firstCall.args[0].should.eql(
['defaults', 'write', '.GlobalPreferences.plist', 'AppleLocale', '<string>en_US@calendar=gregorian</string>']
);
spawnProcessSpy.callCount.should.eql(1);
});
});

describe('keyboard', function () {
it('should configure keyboard', async function () {
const options = {keyboard: {name: 'en_US', layout: 'QWERTY'}};
(await sim.configureLocalization(options)).should.be.true;
spawnProcessSpy.firstCall.args[0].should.eql(
['defaults', 'write', '.GlobalPreferences.plist', 'AppleKeyboards', '<array><string>en_US@sw=QWERTY</string></array>']
);
spawnProcessSpy.secondCall.args[0].should.eql(
['defaults', 'write', 'com.apple.Preferences', 'KeyboardsCurrentAndNext', '<array><string>en_US@sw=QWERTY</string></array>']
);
spawnProcessSpy.thirdCall.args[0].should.eql(
['defaults', 'write', 'com.apple.Preferences', 'KeyboardLastUsed', '<string>en_US@sw=QWERTY</string>']
);
spawnProcessSpy.getCall(3).args[0].should.eql(
['defaults', 'write', 'com.apple.Preferences', 'KeyboardLastUsedForLanguage', '<dict><key>en_US</key><string>en_US@sw=QWERTY</string></dict>']
);
spawnProcessSpy.callCount.should.eql(4);
});
});

describe('language', function () {
let getDirStub;
const stdout = JSON.stringify({AppleLanguages: ['en']});
beforeEach(function () {
getDirStub = sinon.stub(sim, 'getDir').callsFake(() => (''));
sinon.stub(teenProcess, 'exec').callsFake(() => ({ stdout }));
});
afterEach(function () {
getDirStub.reset();
teenProcess.exec.restore();
});

it('should configure language and restart services', async function () {
const options = {language: {name: 'ja'}};
(await sim.configureLocalization(options)).should.be.true;
spawnProcessSpy.firstCall.args[0].should.eql(
['defaults', 'write', '.GlobalPreferences.plist', 'AppleLanguages', '<array><string>ja</string></array>']
);
spawnProcessSpy.secondCall.args[0].should.eql(
['launchctl', 'stop', 'com.apple.SpringBoard']
);
spawnProcessSpy.thirdCall.args[0].should.eql(
['launchctl', 'stop', 'com.apple.locationd']
);
spawnProcessSpy.getCall(3).args[0].should.eql(
['launchctl', 'stop', 'com.apple.tccd']
);
spawnProcessSpy.callCount.should.eql(4);
});

it('should confirm skip restarting services if already applied', async function () {
const options = {language: {name: 'en'}};
(await sim.configureLocalization(options)).should.be.true;
spawnProcessSpy.firstCall.args[0].should.eql(
['defaults', 'write', '.GlobalPreferences.plist', 'AppleLanguages', '<array><string>en</string></array>']
);
spawnProcessSpy.callCount.should.eql(1);
});

it('should confirm skip restarting services if skipSyncUiDialogTranslation is true', async function () {
const options = {language: {name: 'ja', skipSyncUiDialogTranslation: true}};
(await sim.configureLocalization(options)).should.be.true;
spawnProcessSpy.firstCall.args[0].should.eql(
['defaults', 'write', '.GlobalPreferences.plist', 'AppleLanguages', '<array><string>ja</string></array>']
);
spawnProcessSpy.callCount.should.eql(1);
});
});
});
});

0 comments on commit 1833e83

Please sign in to comment.