diff --git a/resources/instructions/createSObjectLwcQuickActions.html b/resources/instructions/createSObjectLwcQuickActions.html
index 4ac8f5c5..88122b52 100644
--- a/resources/instructions/createSObjectLwcQuickActions.html
+++ b/resources/instructions/createSObjectLwcQuickActions.html
@@ -54,7 +54,7 @@
Create sObject LWC Quick Actions
-
+
diff --git a/src/commands/wizard/lwcGenerationCommand.ts b/src/commands/wizard/lwcGenerationCommand.ts
index 6c2b4678..2033f683 100644
--- a/src/commands/wizard/lwcGenerationCommand.ts
+++ b/src/commands/wizard/lwcGenerationCommand.ts
@@ -52,20 +52,22 @@ export class LwcGenerationCommand {
type: 'generateLwcQuickActions',
action: async (_panel, _data, callback) => {
const quickActionStatus =
- await LwcGenerationCommand.checkForExistingQuickActions().catch(error => {
- if (callback) {
- callback({error: error});
+ await LwcGenerationCommand.checkForExistingQuickActions().catch(
+ (error) => {
+ if (callback) {
+ callback({ error: error });
+ }
+ return;
}
- return;
- });
+ );
const newLwcQuickActionStatus =
await LwcGenerationCommand.generateMissingLwcsAndQuickActions(
extensionUri,
quickActionStatus!
- ).catch(error => {
+ ).catch((error) => {
if (callback) {
- callback({error: error});
+ callback({ error: error });
}
return;
});
@@ -81,10 +83,12 @@ export class LwcGenerationCommand {
action: async (_panel, _data, callback) => {
if (callback) {
const quickActionStatus =
- await LwcGenerationCommand.checkForExistingQuickActions().catch(error => {
- callback({error: error});
- return;
- });
+ await LwcGenerationCommand.checkForExistingQuickActions().catch(
+ (error) => {
+ callback({ error: error });
+ return;
+ }
+ );
callback(quickActionStatus!);
}
}
@@ -123,96 +127,106 @@ export class LwcGenerationCommand {
}
static async checkForExistingQuickActions(): Promise {
- return new Promise(async (resolve, reject) => {
- const results: SObjectQuickActionStatus = { sobjects: {} };
-
- const sObjectsStatus = await this.getSObjectsFromLandingPage().catch(error => {
- return reject(error);
- });
-
- sObjectsStatus!.sobjects.forEach((sobject) => {
- const quickActionStatus: QuickActionStatus = {
- view: false,
- edit: false,
- create: false
- };
- quickActionStatus.view =
- LwcGenerationCommand.checkForExistingQuickAction(
- sobject,
- 'view'
- );
- quickActionStatus.edit =
- LwcGenerationCommand.checkForExistingQuickAction(
- sobject,
- 'edit'
- );
- quickActionStatus.create =
- LwcGenerationCommand.checkForExistingQuickAction(
- sobject,
- 'create'
- );
-
- results.sobjects[sobject] = quickActionStatus;
- });
-
- return resolve(results);
- });
+ return new Promise(
+ async (resolve, reject) => {
+ const results: SObjectQuickActionStatus = { sobjects: {} };
+
+ const sObjectsStatus =
+ await this.getSObjectsFromLandingPage().catch((error) => {
+ return reject(error);
+ });
+
+ sObjectsStatus!.sobjects.forEach((sobject) => {
+ const quickActionStatus: QuickActionStatus = {
+ view: false,
+ edit: false,
+ create: false
+ };
+ quickActionStatus.view =
+ LwcGenerationCommand.checkForExistingQuickAction(
+ sobject,
+ 'view'
+ );
+ quickActionStatus.edit =
+ LwcGenerationCommand.checkForExistingQuickAction(
+ sobject,
+ 'edit'
+ );
+ quickActionStatus.create =
+ LwcGenerationCommand.checkForExistingQuickAction(
+ sobject,
+ 'create'
+ );
+
+ results.sobjects[sobject] = quickActionStatus;
+ });
+
+ return resolve(results);
+ }
+ );
}
static async generateMissingLwcsAndQuickActions(
extensionUri: Uri,
quickActionStatus: SObjectQuickActionStatus
): Promise {
- return new Promise(async (resolve, reject) => {
- for (const sobject in quickActionStatus.sobjects) {
- try {
- const quickActions = quickActionStatus.sobjects[sobject];
-
- if (
- !quickActions.create ||
- !quickActions.edit ||
- !quickActions.view
- ) {
- // at least 1 needs to be created
- const compactLayoutFields =
- await OrgUtils.getCompactLayoutFieldsForSObject(
- sobject
- ).catch(err => {
- reject(`An error occurred while obtaining layout for ${sobject} : ${(err as Error).message}`);
- return;
- });
-
- const codeBuilder = new CodeBuilder(
- extensionUri,
- sobject,
- compactLayoutFields!
- );
+ return new Promise(
+ async (resolve, reject) => {
+ for (const sobject in quickActionStatus.sobjects) {
+ try {
+ const quickActions =
+ quickActionStatus.sobjects[sobject];
+
+ if (
+ !quickActions.create ||
+ !quickActions.edit ||
+ !quickActions.view
+ ) {
+ // at least 1 needs to be created
+ const compactLayoutFields =
+ await OrgUtils.getCompactLayoutFieldsForSObject(
+ sobject
+ ).catch((err) => {
+ reject(
+ `An error occurred while obtaining layout for ${sobject} : ${
+ (err as Error).message
+ }`
+ );
+ return;
+ });
- if (!quickActions.view) {
- await codeBuilder.generateView();
- }
+ const codeBuilder = new CodeBuilder(
+ extensionUri,
+ sobject,
+ compactLayoutFields!
+ );
- if (!quickActions.edit) {
- await codeBuilder.generateEdit();
- }
+ if (!quickActions.view) {
+ await codeBuilder.generateView();
+ }
- if (!quickActions.create) {
- await codeBuilder.generateCreate();
+ if (!quickActions.edit) {
+ await codeBuilder.generateEdit();
+ }
+
+ if (!quickActions.create) {
+ await codeBuilder.generateCreate();
+ }
}
+ } catch (err) {
+ console.error(
+ `Could not generate quick actions for sobject ${sobject}, so skipping`,
+ err
+ );
}
- } catch (err) {
- console.error(
- `Could not generate quick actions for sobject ${sobject}, so skipping`,
- err
- );
}
- }
- // Just double check now that things have been created.
- const newStatus =
- await LwcGenerationCommand.checkForExistingQuickActions();
- resolve(newStatus);
- });
+ // Just double check now that things have been created.
+ const newStatus =
+ await LwcGenerationCommand.checkForExistingQuickActions();
+ resolve(newStatus);
+ }
+ );
}
private static checkForExistingQuickAction(
diff --git a/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts b/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts
index bc4cb926..a49658af 100644
--- a/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts
+++ b/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts
@@ -16,18 +16,26 @@ import {
} from '../../../../commands/wizard/lwcGenerationCommand';
import { WorkspaceUtils } from '../../../../utils/workspaceUtils';
import { TempProjectDirManager } from '../../../TestHelper';
+import { Uri } from 'vscode';
+import { CompactLayoutField, OrgUtils } from '../../../../utils/orgUtils';
+import { CodeBuilder } from '../../../../utils/codeBuilder';
+import { create } from 'domain';
suite('LWC Generation Command Test Suite', () => {
- beforeEach(function () {});
+ let sandbox: sinon.SinonSandbox;
+
+ beforeEach(function () {
+ sandbox = sinon.createSandbox();
+ });
afterEach(function () {
- sinon.restore();
+ sandbox.restore();
});
test('Quick Action directories check', async () => {
const baseDir = 'force-app/main/default/quickActions';
- const statSyncStub = sinon.stub(fs, 'statSync');
- const statsStub = sinon.createStubInstance(fs.Stats);
+ const statSyncStub = sandbox.stub(fs, 'statSync');
+ const statsStub = sandbox.createStubInstance(fs.Stats);
statsStub.isFile.returns(true);
// stub the file system responses - any return value is a positive hit, an exception is a negative hit
@@ -51,7 +59,7 @@ suite('LWC Generation Command Test Suite', () => {
.withArgs(`${baseDir}/sobject2.create.quickAction-meta.xml`)
.throws('error');
- const getSObjectsStub = sinon.stub(
+ const getSObjectsStub = sandbox.stub(
LwcGenerationCommand,
'getSObjectsFromLandingPage'
);
@@ -97,7 +105,7 @@ suite('LWC Generation Command Test Suite', () => {
test('Should return error status for landing page with invalid json', async () => {
const dirManager = await TempProjectDirManager.createTempProjectDir();
- const getWorkspaceDirStub = sinon.stub(
+ const getWorkspaceDirStub = sandbox.stub(
WorkspaceUtils,
'getStaticResourcesDir'
);
@@ -112,13 +120,16 @@ suite('LWC Generation Command Test Suite', () => {
);
const status =
- await LwcGenerationCommand.getSObjectsFromLandingPage().then(results => {
- // an error should have occurred
- assert.fail('Invalid JSON should have caused a rejection of the promise.');
- }).catch(error => {
- assert.ok(error && error.length > 0);
- });
-
+ await LwcGenerationCommand.getSObjectsFromLandingPage()
+ .then((results) => {
+ // an error should have occurred
+ assert.fail(
+ 'Invalid JSON should have caused a rejection of the promise.'
+ );
+ })
+ .catch((error) => {
+ assert.ok(error && error.length > 0);
+ });
} finally {
getWorkspaceDirStub.restore();
await dirManager.removeDir();
@@ -127,7 +138,7 @@ suite('LWC Generation Command Test Suite', () => {
test('Should return 2 sObjects', async () => {
const dirManager = await TempProjectDirManager.createTempProjectDir();
- const getWorkspaceDirStub = sinon.stub(
+ const getWorkspaceDirStub = sandbox.stub(
WorkspaceUtils,
'getStaticResourcesDir'
);
@@ -153,4 +164,51 @@ suite('LWC Generation Command Test Suite', () => {
await dirManager.removeDir();
}
});
+
+ test('Should generate view, create, and edit quick actions', async () => {
+ const extensionUri = Uri.file('whateva');
+ const quickActionStatus: SObjectQuickActionStatus = {
+ sobjects: {
+ account: {
+ view: false,
+ edit: false,
+ create: false
+ }
+ }
+ };
+
+ // stubs for OrgUtils.getCompactLayoutFieldsForSObject()
+ const compactLayoutFields: CompactLayoutField[] = [
+ {
+ editableForNew: true,
+ editableForUpdate: true,
+ label: 'label',
+ layoutComponents: [
+ {
+ value: 'field1'
+ }
+ ]
+ }
+ ];
+ const compactLayoutFieldsStub = sandbox
+ .stub(OrgUtils, 'getCompactLayoutFieldsForSObject')
+ .resolves(compactLayoutFields);
+ const quickActionStatusStub = sandbox.stub(
+ LwcGenerationCommand,
+ 'checkForExistingQuickActions'
+ );
+ quickActionStatusStub.resolves(quickActionStatus);
+ const codeBuilderStub = sandbox.stub(CodeBuilder.prototype);
+
+ // act
+ const abc =
+ await LwcGenerationCommand.generateMissingLwcsAndQuickActions(
+ extensionUri,
+ quickActionStatus
+ );
+
+ sandbox.assert.calledOnce(codeBuilderStub.generateCreate);
+ sandbox.assert.calledOnce(codeBuilderStub.generateEdit);
+ sandbox.assert.calledOnce(codeBuilderStub.generateView);
+ });
});