Skip to content

Commit

Permalink
Merge pull request #18 from salesforce/l10n
Browse files Browse the repository at this point in the history
L10n of all strings.
  • Loading branch information
dbreese committed Jun 14, 2023
2 parents 1c5b423 + 9f617b3 commit 1e23875
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 38 deletions.
41 changes: 19 additions & 22 deletions src/commands/authorizeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,34 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { commands, window } from 'vscode';
import { commands, window, l10n } from 'vscode';
import { OrgUtils } from '../utils/orgUtils';

export class AuthorizeCommand {
static async authorizeToOrg(): Promise<boolean> {
const user = await OrgUtils.getDefaultUser();

// Ask user to authorize to an org now only if not authorized yet.
if (user === 'undefined') {
try {
await OrgUtils.getDefaultUser();
return Promise.resolve(true);
} catch {
// Ask user to authorize to an org now only if not authorized yet.
const result = await window.showInformationMessage(
'Do you want to authorize an Org now?',
{ title: 'Authorize' },
{ title: 'No' }
l10n.t('Do you want to authorize an Org now?'),
{ title: l10n.t('Authorize') },
{ title: l10n.t('No') }
);

if (result) {
if (result.title === 'No') {
return Promise.resolve(false);
} else {
await commands.executeCommand('sfdx.force.auth.web.login');
await window.showInformationMessage(
"Once you've authorized your Org, click here to continue.",
{ title: 'OK' }
);
return Promise.resolve(true);
}
} else {
if (!result || result.title === l10n.t('No')) {
return Promise.resolve(false);
} else {
await commands.executeCommand('sfdx.force.auth.web.login');
await window.showInformationMessage(
l10n.t(
"Once you've authorized your Org, click here to continue."
),
{ title: l10n.t('OK') }
);
return Promise.resolve(true);
}
} else {
return Promise.resolve(true);
}
}
}
9 changes: 5 additions & 4 deletions src/commands/briefcaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import { InstructionsWebviewProvider } from '../webviews';
export class BriefcaseCommand {
static async setupBriefcase(extensionUri: Uri): Promise<boolean> {
await window.showInformationMessage(
'Click OK to launch your org to the Briefcase Builder page. After ' +
'launching, return here for instructions to set up a Briefcase rule.',
{ title: 'OK' }
l10n.t(
'Click OK to launch your org to the Briefcase Builder page. After launching, return here for instructions to set up a Briefcase rule.'
),
{ title: l10n.t('OK') }
);

// TODO: this `withProgress` call probably needs tweaking on UX.
await window.withProgress(
{
location: ProgressLocation.Notification,
title: 'Launching Briefcase Builder...'
title: l10n.t('Launching Briefcase Builder...')
},
async (progress, token) => {
await CommonUtils.executeCommandAsync(
Expand Down
16 changes: 9 additions & 7 deletions src/commands/deployToOrgCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@
*/

import path = require('path');
import { Uri, commands, window, workspace } from 'vscode';
import { Uri, commands, window, workspace, l10n } from 'vscode';

export class DeployToOrgCommand {
static async deployToOrg(): Promise<boolean> {
const currentWorkspace = workspace;
if (!currentWorkspace.workspaceFolders) {
await window.showErrorMessage(
'There are no workspace folders defined in your project.',
{ title: 'OK' }
l10n.t(
'There are no workspace folders defined in your project.'
),
{ title: l10n.t('OK') }
);
return Promise.resolve(false);
}

const result = await window.showInformationMessage(
'Do you want to deploy to an already-authorized Org?',
{ title: 'Deploy' },
{ title: 'Cancel' }
l10n.t('Do you want to deploy to an already-authorized Org?'),
{ title: l10n.t('Deploy') },
{ title: l10n.t('Cancel') }
);

if (!result || result.title === 'Cancel') {
if (!result || result.title === l10n.t('Cancel')) {
return Promise.resolve(false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/commands/authorizeToOrgCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ suite('Authorize Org Command Test Suite', () => {
test('Authorization cancelled by the user', async () => {
// setup up so that org is not authorized yet
const getDefaultUserStub = sinon.stub(OrgUtils, 'getDefaultUser');
getDefaultUserStub.onCall(0).resolves('undefined');
getDefaultUserStub.onCall(0).rejects(false);

// simulate user choosing not to authorize
const showInformationMessageStub = sinon.stub(
Expand Down
26 changes: 26 additions & 0 deletions src/test/suite/utils/orgUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ suite('Org Utils Test Suite', () => {
assert.equal(reloadSpy.called, true, 'reload should be invoked');
});

test('Username is not determined.', async () => {
const reloadSpy = sinon.spy(() => {
return Promise.resolve;
});

const config: SinonStub = sinon.stub(ConfigAggregator, 'create');
config.returns({
getInfo: (key: OrgConfigProperties) => {
switch (key) {
case OrgConfigProperties.TARGET_ORG:
return undefined;
default:
return 'BAD';
}
},
reload: reloadSpy
});

let expectedConditionReached = false;
const defaultUser = await OrgUtils.getDefaultUser().catch((err) => {
expectedConditionReached = true;
});

assert.equal(expectedConditionReached, true);
});

test('Returns list of sobjects', async () => {
const orgStub: SinonStub = sinon.stub(Org, 'create');
const stubConnection = sinon.createStubInstance(Connection);
Expand Down
9 changes: 5 additions & 4 deletions src/utils/orgUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ export class OrgUtils {
const currentUserConfig = aggregator.getInfo(
OrgConfigProperties.TARGET_ORG
);
const currentUser = currentUserConfig.value
? currentUserConfig.value
: 'undefined';
return Promise.resolve(currentUser.toString());

if (currentUserConfig && currentUserConfig.value) {
return Promise.resolve(currentUserConfig.value.toString());
}
return Promise.reject('no user');
}
}

0 comments on commit 1e23875

Please sign in to comment.