import { expect } from 'chai' ; import * as path from 'path' ; import { By , EditorView , InputBox , TextEditor , VSBrowser , WebDriver , WebView , Workbench } from 'vscode-extension-tester' ; describe ( 'In project folder, SOQL files should' , function ( ) { this . timeout ( 55000 ) ; let browser ; let driver ; const folderPath = path . resolve ( __dirname , '..' , '..' , '..' , 'test' , 'ui-test' , 'resources' , 'sfdx-test-project' ) + path . sep ; const filename = 'example.soql' ; const openFolder = async ( folder ) => { const workbench = new Workbench ( ) ; const cmdTitle = 'Extest: Open Folder' ; await workbench . executeCommand ( cmdTitle ) ; const input = await InputBox . create ( ) ; await input . setText ( folder ) ; await input . confirm ( ) ; await pause ( 3000 ) ; } ; const openSoqlFile = async ( folder , fileName ) => { const workbench = new Workbench ( ) ; const openEditors = await new EditorView ( ) . getOpenEditorTitles ( ) ; if ( ! openEditors . find ( title => title === fileName ) ) { await workbench . executeCommand ( 'File > Open File...' ) ; const input = await InputBox . create ( ) ; await input . setText ( path . resolve ( folder , fileName ) ) ; await input . confirm ( ) ; await pause ( 2000 ) ; } } ; const toggleEditor = async ( editorTitle ) => { const editorView = new EditorView ( ) ; await editorView . openEditor ( editorTitle ) ; const actionToolbar = await editorView . findElement ( By . className ( 'editor-actions' ) ) ; const actions = await actionToolbar . findElements ( By . className ( 'codicon' ) ) ; let toggle ; for ( const action of actions ) { if ( ( await action . getAttribute ( 'title' ) ) === 'Switch Between SOQL Builder and Text Editor' ) { toggle = action ; break ; } } expect ( toggle ) . is . not . undefined ; await toggle ?. click ( ) ; await pause ( 10000 ) ; } ; const pause = async ( msec ) => { await new Promise ( res => setTimeout ( res , msec ) ) ; } ; before ( async ( ) => { browser = VSBrowser . instance ; driver = browser . driver ; await browser . waitForWorkbench ( ) ; await openFolder ( folderPath ) ; } ) ; after ( async ( ) => { } ) ; beforeEach ( async ( ) => { const editorView = new EditorView ( ) ; await editorView . closeAllEditors ( ) ; await pause ( 500 ) ; } ) ; it ( 'pass end to end SOQL Builder test' , async ( ) => { await openSoqlFile ( folderPath , filename ) ; const textEditor = await new EditorView ( ) . openEditor ( filename ) ; expect ( textEditor . constructor === TextEditor ) . to . be . true ; await toggleEditor ( filename ) ; const webviewEditor = await new EditorView ( ) . openEditor ( filename ) ; expect ( webviewEditor . constructor === WebView ) . to . be . true ; const webview = webviewEditor as WebView ; await webview . switchToFrame ( ) ; const qbApp = await webview . findWebElement ( By . css ( 'querybuilder-app' ) ) ; expect ( qbApp ) . is . not . undefined ; await webview . switchBack ( ) ; return Promise . resolve ( ) ; } ) ; } ) ;