import { Workbench , Notification , NotificationType , ActivityBar , SideBarView , ViewControl , DebugView , EditorView , } from "vscode-extension-tester" ; import { delay } from "../helper" ; import { NotificationPageObject } from "./notification-po" ; import { StatusPageObject } from "./status-po" ; import { expect } from "chai" ; import { ExplorerPageObject } from "./explorer-view-po" ; import { ServerViewPageObject } from "./server-view-po" ; import { DebugPageObject } from "./debug-view-po" ; const PROCESS_TIMEOUT = 10 * 1000 ; const WAIT_PROCESS_TIMEOUT = 3 * 60 * 1000 ; export class WorkbenchPageObject { private workbench : Workbench ; private statusBar : StatusPageObject ; private notification : NotificationPageObject ; constructor ( ) { this . workbench = new Workbench ( ) ; this . statusBar = new StatusPageObject ( this . workbench ) ; this . notification = new NotificationPageObject ( this . workbench ) ; } async wait ( ) { await delay ( 500 ) ; await this . workbench . getStatusBar ( ) . wait ( 2000 ) ; } async isConnected ( LOCALHOST_NAME , LOCALHOST_ENVIRONMENT ) { return ( ( await this . statusBar . statusBarWithText ( `${ LOCALHOST_NAME } / ${ LOCALHOST_ENVIRONMENT }` , 10000 ) ) !== null ) ; } async isNeedSelectServer ( ) { return ( ( await this . statusBar . statusBarWithText ( /Select server\/environment/ ) ) !== null ) ; } private async testNotification ( targetText ) { const notification = await this . getNotification ( targetText ) ; const result = notification ? true : false ; await notification ?. dismiss ( ) ; return result ; } async isRpoIntegrity ( ) { return await this . testNotification ( /RPO [intact|incomplete]/ ) ; } async isSaveServer ( ) { return await this . testNotification ( /Serve saved/ ) ; } async isLauncherSaved ( ) { return await this . testNotification ( /Launcher Configuration saved/ ) ; } async isAuthenticationFailed ( ) { let result = false ; await this . getNotification ( /Authentication failed:/ ) . then ( async ( notification ) => { await notification ?. dismiss ( ) ; result = notification ? true : false ; } ) ; return result ; } async isApplyTemplateNotSuported ( ) { return Promise . resolve ( true ) ; } async isDAInitialing ( ) { return await this . testNotification ( /TDS\-DA being initialized/ ) ; } async isDAReady ( ) { return await this . testNotification ( /TDS\-DA ready/ ) ; } async isDACheckingSources ( ) { return await this . testNotification ( /Checking the.*source/ ) ; } async isDASourceListRecording ( ) { return await this . testNotification ( /Source List in this/ ) ; } async isDAReadingAllTimelines ( ) { return await this . testNotification ( /Reading all TimeLines from the database\. Please wait.*time/ ) ; } async isDAReadingAllTimelinesDone ( ) { return await this . testNotification ( /Read all TimeLines from the database/ ) ; } async isDAStoppingFistLineDone ( ) { return await this . testNotification ( /Stopped in the first timeline./ ) ; } async isDABeingFinalized ( ) { return await this . testNotification ( /TDS\-DA being finalized/ ) ; } async isDAFinished ( ) { return await this . testNotification ( /TDS\-DA finished/ ) ; } async isPatchValidateNotBeExecuted ( ) { return await this . testNotification ( /Patch validate could not be executed/ ) ; } async isPatchApplied ( ) { return await this . testNotification ( /Patch applied/ ) ; } async isTemplateApplied ( ) { return await this . testNotification ( /Template applied/ ) ; } async isHaveKey ( ) { return ( await this . statusBar . statusBarWithText ( /HAVE key/ ) ) !== null ; } async isNotHaveKey ( ) { return ( await this . statusBar . statusBarWithText ( /NOT key/ ) ) !== null ; } private async processInProgress ( targetText ) { let notification = await this . getNotification ( targetText ) ; return await notification ?. hasProgress ( ) ; } private async waitProcessFinish ( targetText , _wait = PROCESS_TIMEOUT ) { let steps = _wait / 500 ; let notification = await this . getNotification ( targetText ) ; if ( notification ) { try { while ( ( await notification . hasProgress ( ) ) && steps > 0 ) { await delay ( 500 ) ; steps -- ; } expect ( notification . hasProgress ( ) , `Timeout process (${ _wait }ms): ${ targetText }` ) . is . false ; } catch ( error ) { } } return notification ; } async waitConnection ( wait = PROCESS_TIMEOUT ) { await this . waitProcessFinish ( /Authenticating user/ ) ; } async waitReconnection ( wait = PROCESS_TIMEOUT ) { await this . waitProcessFinish ( /Reconnecting to the server/ ) ; } async waitCheckIntegrity ( wait = PROCESS_TIMEOUT ) { await this . waitProcessFinish ( /Checking RPO integrity/ ) ; } async waitRevalidate ( wait = PROCESS_TIMEOUT ) { await this . waitProcessFinish ( /Revalidating RPO/ ) ; } async waitRpoLoaded ( wait = PROCESS_TIMEOUT ) { await this . waitProcessFinish ( /Loading RPO content/ ) ; } async waitValidatingServer ( ) { await this . processInProgress ( /Validating server/ ) ; } async applyTemplateInProgress ( ) { return await this . processInProgress ( /Applying template/ ) ; } async waitApplyTemplate ( ) { await this . waitProcessFinish ( /Applying template/ , WAIT_PROCESS_TIMEOUT ) ; } async applyPatchInProgress ( ) { return await this . processInProgress ( /Applying patch/ ) ; } async waitApplyPatch ( ) { await this . waitProcessFinish ( /Applying patch/ , WAIT_PROCESS_TIMEOUT ) ; } async waitImportReplay ( delay = WAIT_PROCESS_TIMEOUT ) { await this . waitProcessFinish ( /Importing TDS Replay/ , delay ) ; } async getNotification ( targetText , _wait = 5000 ) { const notification = await this . notification . getNotification ( targetText , NotificationType . Any , _wait ) ; return notification ; } async executeCommand ( command ) { await this . workbench . executeCommand ( command ) ; } async openDebugView ( ) { const po = new DebugPageObject ( ) ; await po . openView ( ) ; return po ; } async openExplorerView ( ) { const po = new ExplorerPageObject ( ) ; await po . openView ( ) ; return po ; } async openTotvsView ( ) { const po = new ServerViewPageObject ( ) ; await po . openView ( ) ; return po ; } async closeAllEditors ( ) { const view = new EditorView ( ) ; view . closeAllEditors ( ) ; await delay ( ) ; } }