/*********************************************************************
 * Copyright (c) 2019 Red Hat, Inc.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 **********************************************************************/ import 'reflect-metadata' ; import { injectable , inject } from 'inversify' ; import { CLASSES } from '../../../inversify.types' ; import { DriverHelper } from '../../../utils/DriverHelper' ; import { Logger } from '../../../utils/Logger' ; import { By } from 'selenium-webdriver' ; import { TimeoutConstants } from '../../../TimeoutConstants' ; import { LeftToolBar } from '../LeftToolBar' ; @ injectable ( ) export class KubernetesPlugin { constructor ( @ inject ( CLASSES . DriverHelper ) private readonly driverHelper , @ inject ( CLASSES . LeftToolBar ) private readonly leftToolbar ) { } async openView ( timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.openView` ) ; await this . leftToolbar . selectView ( 'Kubernetes' , timeout ) ; } async clickToSection ( sectionTitle , timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.clickToSection  ${ sectionTitle }` ) ; const sectionLocator = By . xpath ( this . getSectionLocator ( sectionTitle ) ) ; await this . driverHelper . waitAndClick ( sectionLocator , timeout ) ; } async isSectionExpanded ( sectionTitle ) { Logger . debug ( `KubernetesPlugin.isSectionExpanded  ${ sectionTitle }` ) ; const expandedsectionLocator = this . getExpandedSectionLocator ( sectionTitle ) ; return await this . driverHelper . isVisible ( expandedsectionLocator ) ; } async waitSectionExpanded ( sectionTitle , timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.waitSectionExpanded  ${ sectionTitle }` ) ; await this . driverHelper . waitVisibility ( this . getExpandedSectionLocator ( sectionTitle ) , timeout ) ; } async waitSectionCollapsed ( sectionTitle , timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.waitSectionCollapsed  ${ sectionTitle }` ) ; await this . driverHelper . waitVisibility ( this . getCollapsedSectionLocator ( sectionTitle ) , timeout ) ; } async expandSection ( sectionTitle , timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.expandSection  ${ sectionTitle }` ) ; if ( await this . isSectionExpanded ( sectionTitle ) ) { return ; } await this . clickToSection ( sectionTitle , timeout ) ; await this . waitSectionExpanded ( sectionTitle , timeout ) ; } async clickToRefreshButton ( sectionTitle , timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.clickToRefreshButton` ) ; const refreshButtonLocator = By . xpath ( `//div[contains(@class, 'theia-header')]//div[contains(@class, 'theia-view-container-part-title')]//div[@title='Refresh']` ) ; const sectionTitleLocator = By . xpath ( this . getSectionLocator ( sectionTitle ) ) ; await this . driverHelper . scrollTo ( sectionTitleLocator , timeout ) ; await this . driverHelper . waitAndClick ( refreshButtonLocator , timeout ) ; } async waitListItemContains ( partialText , timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.waitListItemContains  ${ partialText }` ) ; await this . driverHelper . waitVisibility ( this . getListItemPartialTextLocator ( partialText ) , timeout ) ; } async waitListItem ( expectedText , timeout = TimeoutConstants . TS_PROJECT_TREE_TIMEOUT ) { Logger . debug ( `KubernetesPlugin.waitListItem  ${ expectedText }` ) ; await this . driverHelper . waitVisibility ( this . getListItemTextLocator ( expectedText ) , timeout ) ; } private getSectionLocator ( sectionTitle ) { return `//div[contains(@class, 'theia-header')]//span[@title='${ sectionTitle }']` ; } private getExpandedSectionLocator ( sectionTitle ) { return By . xpath ( `${ this . getSectionLocator ( sectionTitle ) }/parent::div/span[contains(@class, 'theia-ExpansionToggle') and not(contains(@class, 'theia-mod-collapsed'))]` ) ; } private getCollapsedSectionLocator ( sectionTitle ) { return By . xpath ( `${ this . getSectionLocator ( sectionTitle ) }/parent::div/span[contains(@class, 'theia-ExpansionToggle') and contains(@class, 'theia-mod-collapsed')]` ) ; } private getListItemPartialTextLocator ( partialText ) { return By . xpath ( `//div[@id='extension.vsKubernetesExplorer']//div[contains(text(), "${ partialText }")]` ) ; } private getListItemTextLocator ( expectedText ) { return By . xpath ( `//div[contains(@class, 'body')]//div[@class='theia-TreeContainer']//div[@class='theia-TreeNodeContent']//span[text()='${ expectedText }']` ) ; } }