import { assert , expect } from 'chai' ; import * as path from 'path' ; import * as vscode from 'vscode' ; describe ( 'Aura Intellisense Test Suite' , function ( ) { let auraDir ; before ( async ( ) => { auraDir = path . join ( vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath , 'force-app' , 'main' , 'default' , 'aura' ) ; await new Promise ( r => setTimeout ( r , 1000 ) ) ; } ) ; afterEach ( async ( ) => { await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ; } ) ; /**
     * Test that aura markup intellisense contains aura, lightning, custom aura, custom lwc tags
     */ it ( 'Aura markup intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( auraDir , 'DemoComponent' , 'DemoComponent.cmp' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = '<c:' ; const startPosition = new vscode . Position ( 1 , 7 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : 'aura:attribute' , kind : vscode . CompletionItemKind . Property } , { label : 'lightning:button' , kind : vscode . CompletionItemKind . Property } , { label : 'c:DemoApp' , kind : vscode . CompletionItemKind . Property } ] } ) ; } catch ( error ) { throw error ; } } ) ; /**
     * Test aura javascript completions
     */ it ( 'Aura global javascript intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( auraDir , 'DemoComponent' , 'DemoComponentController.js' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = '$A.util.get' ; const startPosition = new vscode . Position ( 2 , 3 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : 'getBooleanValue' , kind : vscode . CompletionItemKind . Function } ] } ) ; } catch ( error ) { throw error ; } } ) ; it ( 'Aura property javascript intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( auraDir , 'DemoComponent' , 'DemoComponentController.js' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = 'component.get' ; const startPosition = new vscode . Position ( 2 , 3 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : 'getEvent' , kind : vscode . CompletionItemKind . Function } ] } ) ; } catch ( error ) { throw error ; } } ) ; it ( 'Aura helper javascript intellisense' , async ( ) => { const docUri = vscode . Uri . file ( path . join ( auraDir , 'DemoComponent' , 'DemoComponentController.js' ) ) ; const doc = await vscode . workspace . openTextDocument ( docUri ) ; const editor = await vscode . window . showTextDocument ( doc ) ; const text = 'helper.hel' ; const startPosition = new vscode . Position ( 2 , 3 ) ; const endPosition = new vscode . Position ( startPosition . line , startPosition . character + text . length ) ; const rangeReplace = new vscode . Range ( startPosition , endPosition ) ; await editor . edit ( editBuilder => { editBuilder . replace ( rangeReplace , text ) ; } ) ; try { await testCompletion ( docUri , endPosition , { items : [ { label : 'helperFunction' , kind : vscode . CompletionItemKind . Function } ] } ) ; } catch ( error ) { throw error ; } } ) ; } ) ; async function testCompletion ( docUri , position , expectedCompletionList ) { const actualCompletionList = ( await vscode . commands . executeCommand ( 'vscode.executeCompletionItemProvider' , docUri , position ) ) as vscode . CompletionList ; expectedCompletionList . items . forEach ( function ( expectedItem ) { const actualItem = actualCompletionList . items . find ( function ( obj ) { if ( obj . label ) { return obj . label === expectedItem . label ; } return false ; } ) ; assert . isDefined ( actualItem , "Couldn't find expected completion item '" + expectedItem . label + "'" ) ; assert . equal ( actualItem ! . label , expectedItem . label , 'Expected completion item to have label: ' + expectedItem . label ) ; assert . equal ( actualItem ! . kind , expectedItem . kind , "Expected completion item'" + expectedItem . label + "' to have type: " + expectedItem . kind ) ; if ( actualItem ?. detail === 'Lightning' ) { assert . isDefined ( actualItem ! . documentation , "Expected completion item '" + expectedItem . label + "' to have documentation" ) ; } } ) ; }