From bf1178762fa89dca92e457845505765e8deef4a7 Mon Sep 17 00:00:00 2001 From: Dustin Breese Date: Mon, 6 Nov 2023 19:00:32 -0700 Subject: [PATCH] Prettier. Renamed interface. --- src/commands/wizard/lwcGenerationCommand.ts | 37 ++++++--- .../wizard/lwcGenerationCommand.test.ts | 80 ++++++++++++++----- 2 files changed, 88 insertions(+), 29 deletions(-) diff --git a/src/commands/wizard/lwcGenerationCommand.ts b/src/commands/wizard/lwcGenerationCommand.ts index 58050241..a6a9f116 100644 --- a/src/commands/wizard/lwcGenerationCommand.ts +++ b/src/commands/wizard/lwcGenerationCommand.ts @@ -2,7 +2,7 @@ import { Uri, l10n } from 'vscode'; import { InstructionsWebviewProvider } from '../../webviews/instructions'; import * as fs from 'fs'; -export interface QuickActionFlags { +export interface SObjectQuickActions { [name: string]: { view: boolean; edit: boolean; @@ -37,27 +37,46 @@ export class LwcGenerationCommand { }); } - static checkForExistingQuickActions(sobjects: string[]): QuickActionFlags { - const results: QuickActionFlags = {}; + static checkForExistingQuickActions( + sobjects: string[] + ): SObjectQuickActions { + const results: SObjectQuickActions = {}; sobjects.forEach((sobject) => { results[sobject] = { view: false, edit: false, - create: false, + create: false }; - results[sobject].view = LwcGenerationCommand.checkForExistingQuickAction(sobject, "view"); - results[sobject].edit = LwcGenerationCommand.checkForExistingQuickAction(sobject, "edit"); - results[sobject].create = LwcGenerationCommand.checkForExistingQuickAction(sobject, "create"); + results[sobject].view = + LwcGenerationCommand.checkForExistingQuickAction( + sobject, + 'view' + ); + results[sobject].edit = + LwcGenerationCommand.checkForExistingQuickAction( + sobject, + 'edit' + ); + results[sobject].create = + LwcGenerationCommand.checkForExistingQuickAction( + sobject, + 'create' + ); }); return results; } - private static checkForExistingQuickAction(sobject: string, qaName: string): boolean { + private static checkForExistingQuickAction( + sobject: string, + qaName: string + ): boolean { const expectedDirName = `${sobject}.${qaName}.quickAction-meta.xml`; try { // Check if the qa directory exists - const stats = fs.statSync(`force-app/main/default/quickActions/${expectedDirName}`); + const stats = fs.statSync( + `force-app/main/default/quickActions/${expectedDirName}` + ); return stats.isDirectory(); } catch (error) { // If an error occurs, the directory does not exist diff --git a/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts b/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts index 6ed1f203..98391554 100644 --- a/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts +++ b/src/test/suite/commands/wizard/lwcGenerationCommand.test.ts @@ -9,8 +9,10 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import * as fs from 'fs'; import { afterEach, beforeEach } from 'mocha'; -import { LwcGenerationCommand, QuickActionFlags } from '../../../../commands/wizard/lwcGenerationCommand'; - +import { + LwcGenerationCommand, + SObjectQuickActions +} from '../../../../commands/wizard/lwcGenerationCommand'; export interface DoSomething { [name: string]: { @@ -19,37 +21,75 @@ export interface DoSomething { } suite('LWC Generation Command Test Suite', () => { - beforeEach(function () { - }); + beforeEach(function () {}); afterEach(function () { sinon.restore(); }); test('Quick Action directories check', async () => { - const baseDir = "force-app/main/default/quickActions"; + const baseDir = 'force-app/main/default/quickActions'; const statSyncStub = sinon.stub(fs, 'statSync'); const statsStub = sinon.createStubInstance(fs.Stats); statsStub.isDirectory.returns(true); // stub the file system responses - any return value is a positive hit, an exception is a negative hit - statSyncStub.withArgs(`${baseDir}/sobject1.view.quickAction-meta.xml`).returns(statsStub); - statSyncStub.withArgs(`${baseDir}/sobject1.edit.quickAction-meta.xml`).returns(statsStub); - statSyncStub.withArgs(`${baseDir}/sobject1.create.quickAction-meta.xml`).returns(statsStub); - - statSyncStub.withArgs(`${baseDir}/sobject2.view.quickAction-meta.xml`).throws("error"); - statSyncStub.withArgs(`${baseDir}/sobject2.edit.quickAction-meta.xml`).throws("error"); - statSyncStub.withArgs(`${baseDir}/sobject2.create.quickAction-meta.xml`).throws("error"); + statSyncStub + .withArgs(`${baseDir}/sobject1.view.quickAction-meta.xml`) + .returns(statsStub); + statSyncStub + .withArgs(`${baseDir}/sobject1.edit.quickAction-meta.xml`) + .returns(statsStub); + statSyncStub + .withArgs(`${baseDir}/sobject1.create.quickAction-meta.xml`) + .returns(statsStub); - const result = LwcGenerationCommand.checkForExistingQuickActions(["sobject1", "sobject2"]); + statSyncStub + .withArgs(`${baseDir}/sobject2.view.quickAction-meta.xml`) + .throws('error'); + statSyncStub + .withArgs(`${baseDir}/sobject2.edit.quickAction-meta.xml`) + .throws('error'); + statSyncStub + .withArgs(`${baseDir}/sobject2.create.quickAction-meta.xml`) + .throws('error'); - assert.equal(result["sobject1"].view, true, "sobject1.view should exist"); - assert.equal(result["sobject1"].edit, true, "sobject1.edit should exist"); - assert.equal(result["sobject1"].create, true, "sobject1.create should exist"); + const result: SObjectQuickActions = + LwcGenerationCommand.checkForExistingQuickActions([ + 'sobject1', + 'sobject2' + ]); - assert.equal(result["sobject2"].view, false, "sobject2.view should NOT exist"); - assert.equal(result["sobject2"].edit, false, "sobject2.edit should NOT exist"); - assert.equal(result["sobject2"].create, false, "sobject2.create should NOT exist"); + assert.equal( + result['sobject1'].view, + true, + 'sobject1.view should exist' + ); + assert.equal( + result['sobject1'].edit, + true, + 'sobject1.edit should exist' + ); + assert.equal( + result['sobject1'].create, + true, + 'sobject1.create should exist' + ); + assert.equal( + result['sobject2'].view, + false, + 'sobject2.view should NOT exist' + ); + assert.equal( + result['sobject2'].edit, + false, + 'sobject2.edit should NOT exist' + ); + assert.equal( + result['sobject2'].create, + false, + 'sobject2.create should NOT exist' + ); }); -}); \ No newline at end of file +});