/*********************************************************************
 * 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 CreateWorkspace { constructor ( @ inject ( CLASSES . DriverHelper ) private readonly driverHelper ) { } async waitTitleContains ( expectedText , timeout = TimeoutConstants . TS_COMMON_DASHBOARD_WAIT_TIMEOUT ) { Logger . debug ( `CreateWorkspace.waitTitleContains text: "${ expectedText }"` ) ; const pageTitleLocator = By . xpath ( `//h1[contains(text(), '${ expectedText }')]` ) ; await this . driverHelper . waitVisibility ( pageTitleLocator , timeout ) ; } async waitPage ( timeout = TimeoutConstants . TS_SELENIUM_LOAD_PAGE_TIMEOUT ) { Logger . debug ( 'CreateWorkspace.waitPage' ) ; await this . waitTitleContains ( 'Create Workspace' , timeout ) ; } async waitSample ( sampleName , timeout = TimeoutConstants . TS_COMMON_DASHBOARD_WAIT_TIMEOUT ) { Logger . debug ( `CreateWorkspace.waitSample sampleName: "${ sampleName }"` ) ; const sampleLocator = this . getSampleLocator ( sampleName ) ; await this . driverHelper . waitVisibility ( sampleLocator , timeout ) ; } async clickOnSample ( sampleName , timeout = TimeoutConstants . TS_CLICK_DASHBOARD_ITEM_TIMEOUT ) { Logger . debug ( `CreateWorkspace.clickOnSample sampleName: "${ sampleName }"` ) ; const sampleLocator = this . getSampleLocator ( sampleName ) ; await this . driverHelper . waitAndClick ( sampleLocator , timeout ) ; } private getSampleLocator ( sampleName ) { Logger . trace ( `CreateWorkspace.getSampleLocator sampleName: ${ sampleName }` ) ; return By . xpath ( `//article[contains(@class, 'sample-card')]//div[text()='${ sampleName }']` ) ; } }