import { SideBarView , TreeItem , ViewContent , DefaultTreeSection , ViewSection , ViewItem , TitleActionButton , ViewTitlePart , ActivityBar , ViewControl , } from "vscode-extension-tester" ; import { WorkbenchPageObject } from "./workbench-po" ; export class ViewPageObject < T > { private _view : T | SideBarView ; protected workbenchPO : WorkbenchPageObject ; private viewName : string ; protected constructor ( name ) { this . viewName = name . toLowerCase ( ) ; this . workbenchPO = new WorkbenchPageObject ( ) ; this . openView ( ) . then ( ( value ) => { this . _view = value ; } ) ; } get view ( ) : T { return this . _view as T ; } async openView ( ) { const activityBar = new ActivityBar ( ) ; const controls = await activityBar . getViewControls ( ) ; let result = null ; for await ( const control of controls ) { const vc = control ; const title = ( await vc . getTitle ( ) ) . toLowerCase ( ) ; if ( title . startsWith ( this . viewName ) ) { result = ( await vc . openView ( ) ) as unknown as T ; } } this . _view = result ; return result ; } async getTreeItem ( name , sectionName ? ) { const view = this . view as unknown as SideBarView ; const content = view . getContent ( ) ; let tree ; if ( sectionName ) { tree = ( await content . getSection ( sectionName ) ) as DefaultTreeSection ; } else { const sections = await content . getSections ( ) ; tree = sections [ 0 ] as DefaultTreeSection ; } const nodes = name . split ( "/" ) ; let result ; result = await ( nodes . length > 1 ? this . openChild ( nodes , tree ) : tree . findItem ( nodes [ 0 ] ) ) ; return Array . isArray ( result ) ? ( result [ 0 ] as TreeItem ) : result == undefined ? null : result ; } async openChild ( nodes , tree ) { let treeItem = await tree . openItem ( ... nodes ) ; return treeItem [ 0 ] ; } async getAction ( action ) { const view = this . view as unknown as SideBarView ; const titlePart = view . getTitlePart ( ) ; return await titlePart . getAction ( action ) ; } async getVisibleItems ( ) { const view = this . view as unknown as SideBarView ; const content = view . getContent ( ) ; const sections = await content . getSections ( ) ; const elements = await sections [ 0 ] . getVisibleItems ( ) ; return elements ; } }