import { expect } from 'chai' ; import * as path from 'path' ; import { CommonActions } from '../src/areas/common' ; import { createWorkspace } from '../src/helpers/workspace' ; import { SpectronApplication , VSCODE_BINARY_PATH } from '../src/spectron/application' ; const TITLE = 'Scaffolding Commands Tests' ; const WORKSPACE_PATH = path . join ( createWorkspace ( path . join ( process . cwd ( ) , 'assets' , 'sfdx-simple' ) ) , 'sfdx-simple' ) ; describe ( 'Scaffolding commands' , ( ) => { let app ; let common ; before ( async ( ) => { app = new SpectronApplication ( VSCODE_BINARY_PATH , TITLE , 2 , [ WORKSPACE_PATH ] ) ; common = new CommonActions ( app ) ; await app . start ( ) ; await app . wait ( ) ; } ) ; after ( async ( ) => { return await app . stop ( ) ; } ) ; it ( 'Should create Apex class' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Apex Class' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `apexClass_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultclasses' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const apexClassTab = await common . getTab ( `${ fileName }.cls` ) ; expect ( apexClassTab ) . to . be . not . undefined ; if ( apexClassTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Apex trigger' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Apex Trigger' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `apexTrigger_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaulttriggers' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const apexTriggerTab = await common . getTab ( `${ fileName }.trigger` ) ; expect ( apexTriggerTab ) . to . be . not . undefined ; if ( apexTriggerTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Visualforce component' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Visualforce Component' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `vfComponent_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultcomponents' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const visualforceComponentTab = await common . getTab ( `${ fileName }.component` ) ; expect ( visualforceComponentTab ) . to . be . not . undefined ; if ( visualforceComponentTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Visualforce page' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Visualforce Page' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `vfPage_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultpages' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const visualforcePageTab = await common . getTab ( `${ fileName }.page` ) ; expect ( visualforcePageTab ) . to . be . not . undefined ; if ( visualforcePageTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Aura app' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Aura App' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `lightningApp_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultaura' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const lightningAppTab = await common . getTab ( `${ fileName }.app` ) ; expect ( lightningAppTab ) . to . be . not . undefined ; if ( lightningAppTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Aura component' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Aura Component' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `lightningCmp_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultaura' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const lightningComponentTab = await common . getTab ( `${ fileName }.cmp` ) ; expect ( lightningComponentTab ) . to . be . not . undefined ; if ( lightningComponentTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Aura event' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Aura Event' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `lightningEvt_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultaura' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const lightningEventTab = await common . getTab ( `${ fileName }.evt` ) ; expect ( lightningEventTab ) . to . be . not . undefined ; if ( lightningEventTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Aura interface' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Aura Interface' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `lightningIntf_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultaura' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const lightningInterfaceTab = await common . getTab ( `${ fileName }.intf` ) ; expect ( lightningInterfaceTab ) . to . be . not . undefined ; if ( lightningInterfaceTab ) { await common . closeTab ( ) ; } } ) ; it ( 'Should create Lightning LWC' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX: Create Lightning Web Component' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const fileName = `lwc_${ new Date ( ) . getTime ( ) }` ; await common . type ( fileName ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; await common . type ( 'force-appmaindefaultlwc' ) ; await app . client . keys ( [ 'NULL' , 'Enter' , 'NULL' ] , false ) ; await app . waitUI ( ) ; const lwcBundleTab = await common . getTab ( `${ fileName }.js` ) ; expect ( lwcBundleTab ) . to . be . not . undefined ; if ( lwcBundleTab ) { await common . closeTab ( ) ; } } ) ; } ) ; describe ( 'Empty VSCode workspace' , ( ) => { let app ; let common ; beforeEach ( async ( ) => { app = new SpectronApplication ( VSCODE_BINARY_PATH , TITLE , 2 ) ; common = new CommonActions ( app ) ; await app . start ( ) ; await app . wait ( ) ; } ) ; afterEach ( async ( ) => { return await app . stop ( ) ; } ) ; it ( 'Should only show create project command for non-SFDX workspace' , async ( ) => { await app . command ( 'workbench.action.quickOpen' ) ; await common . type ( '>SFDX:' ) ; await app . waitUI ( ) ; const quickOpenText = await common . getQuickOpenElementsText ( ) ; expect ( quickOpenText ) . to . contain ( 'SFDX: Create Project' ) ; } ) ; } ) ;