/*********************************************************************
 * 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 { injectable , inject } from 'inversify' ; import { CLASSES } from '../../inversify.types' ; import { DriverHelper } from '../../utils/DriverHelper' ; import { By } from 'selenium-webdriver' ; import { Logger } from '../../utils/Logger' ; import { TimeoutConstants } from '../../TimeoutConstants' ; @ injectable ( ) export class OpenWorkspaceWidget { constructor ( @ inject ( CLASSES . DriverHelper ) private readonly driverHelper ) { } async selectItemInTree ( pathToItem , timeout = TimeoutConstants . TS_SELENIUM_CLICK_ON_VISIBLE_ITEM ) { Logger . debug ( `OpenWorkspaceWidget.selectItemInTree "${ pathToItem }"` ) ; await this . driverHelper . waitAndClick ( By . id ( pathToItem ) , timeout ) ; } async expandTreeToPath ( path , timeout = TimeoutConstants . TS_SELENIUM_CLICK_ON_VISIBLE_ITEM ) { Logger . debug ( `OpenWorkspaceWidget.expandTreeToPath "${ path }"` ) ; const pathNodes = path . split ( '/' ) ; let buildPath = '' ; const promises = pathNodes . map ( async ( currentPath , index ) => { buildPath += `/${ currentPath }` ; if ( index === 0 ) { await this . driverHelper . waitAndClick ( By . id ( buildPath ) , timeout ) ; } else { await this . driverHelper . waitAndClick ( By . xpath ( `(//div[@id='${ buildPath }'])[position()=2]` ) , timeout ) ; } } ) ; return Promise . all ( promises ) ; } }