Skip to content

Commit

Permalink
Merge pull request #21 from salesforce/briecase_tests
Browse files Browse the repository at this point in the history
Briefcase Command Tests.
  • Loading branch information
dbreese authored Jun 14, 2023
2 parents d89f12b + 1f143ff commit 2d742da
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/commands/briefcaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { CommonUtils } from '@salesforce/lwc-dev-mobile-core/lib/common/CommonUt
import { InstructionsWebviewProvider } from '../webviews';

export class BriefcaseCommand {
static readonly OPEN_ORG_BRIEFCASE_PAGE_CMD =
"sfdx org open -p '/lightning/setup/Briefcase/home'";

static async setupBriefcase(extensionUri: Uri): Promise<boolean> {
await window.showInformationMessage(
l10n.t(
Expand All @@ -24,9 +27,9 @@ export class BriefcaseCommand {
location: ProgressLocation.Notification,
title: l10n.t('Launching Briefcase Builder...')
},
async (progress, token) => {
async (_progress, _token) => {
await CommonUtils.executeCommandAsync(
"sfdx org open -p '/lightning/setup/Briefcase/home'"
BriefcaseCommand.OPEN_ORG_BRIEFCASE_PAGE_CMD
);
}
);
Expand Down
61 changes: 59 additions & 2 deletions src/test/suite/commands/briefcaseCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import * as assert from 'assert';
import * as sinon from 'sinon';
import { afterEach, beforeEach } from 'mocha';
import { BriefcaseCommand } from '../../../commands/briefcaseCommand';
import { Uri, l10n, window, Progress, CancellationToken } from 'vscode';
import { CommonUtils } from '@salesforce/lwc-dev-mobile-core/lib/common/CommonUtils';
import { InstructionsWebviewProvider } from '../../../webviews';

suite('Briefcase Command Test Suite', () => {
beforeEach(function () {});
Expand All @@ -15,7 +20,59 @@ suite('Briefcase Command Test Suite', () => {
sinon.restore();
});

test.skip('TODO', async () => {
// TODO
test('Shows informational messages and excutes the open-to-briefcase command', async () => {
// stub for showInformationMessage
const showInfoMsgStub = sinon.stub(window, 'showInformationMessage');
showInfoMsgStub.onCall(0).resolves();

// stub for executing the open briefcase command
const windowWithProgressStub = sinon.stub(window, 'withProgress');
windowWithProgressStub.onCall(0).resolves();
const cmdStub = sinon.stub(CommonUtils, 'executeCommandAsync');
cmdStub.onCall(0).resolves();

// stub for showDismissableInstructions
const showDismissableInstructionsStub = sinon.stub(
InstructionsWebviewProvider,
'showDismissableInstructions'
);

const extensionUri = Uri.parse('file:///extension_dir');

// act
await BriefcaseCommand.setupBriefcase(extensionUri);

// ensure info message was shown
const message = showInfoMsgStub.args[0][0];
const messageOptions: { [key: string]: any } =
showInfoMsgStub.args[0][1];
const title = messageOptions['title'];
assert.ok(message); // too brittle to check exact message, so just ensure it is not null
assert.equal(title, l10n.t('OK'));

// obtain the command argument passed to window.withProgress() and execute it
const taskArg = windowWithProgressStub.args[0][1];
const progressStub: Progress<{ message?: string; increment?: number }> =
{
report: sinon.stub()
};
const cancellationTokenStub: CancellationToken = {
isCancellationRequested: false,
onCancellationRequested: sinon.stub()
};
await taskArg(progressStub, cancellationTokenStub);
const commandExecuted = cmdStub.args[0][0];
assert.equal(
commandExecuted,
BriefcaseCommand.OPEN_ORG_BRIEFCASE_PAGE_CMD
);

// ensure showDismissableInstructions was called with expected args
const uriArg = showDismissableInstructionsStub.args[0][0];
const titleArg = showDismissableInstructionsStub.args[0][1];
const pathArg = showDismissableInstructionsStub.args[0][2];
assert.equal(uriArg, extensionUri);
assert.equal(titleArg, l10n.t('Briefcase Setup Instruction'));
assert.equal(pathArg, 'src/instructions/briefcase.html');
});
});

0 comments on commit 2d742da

Please sign in to comment.