import { expect } from 'chai' ; import * as path from 'path' ; import { Hover , Position , MarkdownString , commands , window , workspace } from 'vscode' ; describe ( 'Aura Hovers' , function ( ) { this . timeout ( 4000 ) ; let auraDir ; before ( async function ( ) { auraDir = path . join ( workspace . workspaceFolders ! [ 0 ] . uri . fsPath , 'force-app' , 'main' , 'default' , 'aura' ) ; await new Promise ( r => setTimeout ( r , 1000 ) ) ; } ) ; afterEach ( async function ( ) { await commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ; } ) ; it ( 'Should provide additional details when hovering over an aura tag' , async function ( ) { const doc = await workspace . openTextDocument ( path . join ( auraDir , 'auraPubsubSubscriber' , 'auraPubsubSubscriber.cmp' ) ) ; const editor = await window . showTextDocument ( doc ) ; const position = new Position ( 25 , 17 ) ; const hoverInstances = ( await commands . executeCommand ( 'vscode.executeHoverProvider' , editor . document . uri , position ) ) as Hover [ ] ; expect ( hoverInstances ) . to . have . lengthOf . at . least ( 1 ) ; const content = findContentFromInstances ( hoverInstances , 'lightning:card' ) ; expect ( content ) . not . to . be . undefined ; expect ( content ) . not . to . be . null ; expect ( content ! . value ) . to . include ( 'lightning:card' ) ; expect ( content ! . value ) . to . include ( 'View in Component Library' ) ; } ) ; it ( 'Should provide additional details when hovering over an aura attribute' , async function ( ) { const doc = await workspace . openTextDocument ( path . join ( auraDir , 'auraPubsubSubscriber' , 'auraPubsubSubscriber.cmp' ) ) ; const editor = await window . showTextDocument ( doc ) ; const position = new Position ( 25 , 24 ) ; const hoverInstances = ( await commands . executeCommand ( 'vscode.executeHoverProvider' , editor . document . uri , position ) ) as Hover [ ] ; expect ( hoverInstances ) . to . have . lengthOf . at . least ( 1 ) ; const content = findContentFromInstances ( hoverInstances , '**title**' ) ; expect ( content ) . not . to . be . undefined ; expect ( content ) . not . to . be . null ; expect ( content ! . value ) . to . include ( 'title' ) ; expect ( content ! . value ) . to . include ( 'The title can include text or another component, and is displayed in the header.' ) ; } ) ; } ) ; param instances param expectedContent returns function findContentFromInstances ( instances , expectedContent ) { for ( const instance of instances ) { const contents = instance ! . contents as MarkdownString [ ] ; const content = contents . find ( content => content . value . includes ( expectedContent ) ) ; if ( content ) { return content ; } } }