import { Key } from 'selenium-webdriver' ; import { FtrProviderContext } from '../../ftr_provider_context' ; const CREATE_DRILLDOWN_FLYOUT_DATA_TEST_SUBJ = 'createDrilldownFlyout' ; const MANAGE_DRILLDOWNS_FLYOUT_DATA_TEST_SUBJ = 'editDrilldownFlyout' ; const DESTINATION_DASHBOARD_SELECT = 'dashboardDrilldownSelectDashboard' ; const DRILLDOWN_WIZARD_SUBMIT = 'drilldownWizardSubmit' ; export function DashboardDrilldownsManageProvider ( { getService } ) { const log = getService ( 'log' ) ; const testSubjects = getService ( 'testSubjects' ) ; const flyout = getService ( 'flyout' ) ; const comboBox = getService ( 'comboBox' ) ; const esArchiver = getService ( 'esArchiver' ) ; const find = getService ( 'find' ) ; const browser = getService ( 'browser' ) ; return new ( class DashboardDrilldownsManage { readonly DASHBOARD_WITH_PIE_CHART_NAME = 'Dashboard with Pie Chart' ; readonly DASHBOARD_WITH_AREA_CHART_NAME = 'Dashboard With Area Chart' ; async loadData ( ) { log . debug ( 'loadData' ) ; await esArchiver . load ( 'x-pack/test/functional/es_archives/dashboard/drilldowns' ) ; } async unloadData ( ) { log . debug ( 'unloadData' ) ; await esArchiver . unload ( 'x-pack/test/functional/es_archives/dashboard/drilldowns' ) ; } async expectsCreateDrilldownFlyoutOpen ( ) { log . debug ( 'expectsCreateDrilldownFlyoutOpen' ) ; await testSubjects . existOrFail ( CREATE_DRILLDOWN_FLYOUT_DATA_TEST_SUBJ ) ; } async expectsManageDrilldownsFlyoutOpen ( ) { log . debug ( 'expectsManageDrilldownsFlyoutOpen' ) ; await testSubjects . existOrFail ( MANAGE_DRILLDOWNS_FLYOUT_DATA_TEST_SUBJ ) ; } async expectsCreateDrilldownFlyoutClose ( ) { log . debug ( 'expectsCreateDrilldownFlyoutClose' ) ; await testSubjects . missingOrFail ( CREATE_DRILLDOWN_FLYOUT_DATA_TEST_SUBJ ) ; } async expectsManageDrilldownsFlyoutClose ( ) { log . debug ( 'expectsManageDrilldownsFlyoutClose' ) ; await testSubjects . missingOrFail ( MANAGE_DRILLDOWNS_FLYOUT_DATA_TEST_SUBJ ) ; } async fillInDashboardToDashboardDrilldownWizard ( { drilldownName , destinationDashboardTitle , } ) { await this . fillInDrilldownName ( drilldownName ) ; await this . selectDestinationDashboard ( destinationDashboardTitle ) ; } async fillInDashboardToURLDrilldownWizard ( { drilldownName , destinationURLTemplate , trigger , } ) { await this . fillInDrilldownName ( drilldownName ) ; await this . selectTriggerIfNeeded ( trigger ) ; await this . fillInURLTemplate ( destinationURLTemplate ) ; } async fillInDrilldownName ( name ) { await testSubjects . setValue ( 'drilldownNameInput' , name ) ; } async selectDestinationDashboard ( title ) { await comboBox . set ( DESTINATION_DASHBOARD_SELECT , title ) ; } async selectTriggerIfNeeded ( trigger ) { if ( await testSubjects . exists ( `triggerPicker` ) ) { const container = await testSubjects . find ( `triggerPicker-${ trigger }` ) ; const radio = await container . findByCssSelector ( 'input[type=radio]' ) ; await radio . click ( ) ; } } async eraseInput ( maxChars ) { const keys = [ ... Array ( maxChars ) . fill ( Key . ARROW_RIGHT ) , ... Array ( maxChars ) . fill ( Key . BACK_SPACE ) , ] ; await browser . getActions ( ) . sendKeys ( ... keys ) . perform ( ) ; } async fillInURLTemplate ( destinationURLTemplate ) { const monaco = await find . byCssSelector ( '.urlTemplateEditor__container .monaco-editor' ) ; await monaco . clickMouseButton ( ) ; await this . eraseInput ( 300 ) ; await browser . pressKeys ( destinationURLTemplate ) ; } async saveChanges ( ) { await testSubjects . click ( DRILLDOWN_WIZARD_SUBMIT ) ; } async deleteDrilldownsByTitles ( titles ) { const drilldowns = await testSubjects . findAll ( 'listManageDrilldownsItem' ) ; for ( const drilldown of drilldowns ) { const nameColumn = await drilldown . findByTestSubject ( 'drilldownListItemName' ) ; const name = await nameColumn . getVisibleText ( ) ; if ( titles . includes ( name ) ) { const checkbox = await drilldown . findByTagName ( 'input' ) ; await checkbox . click ( ) ; } } const deleteBtn = await testSubjects . find ( 'listManageDeleteDrilldowns' ) ; await deleteBtn . click ( ) ; } async closeFlyout ( ) { await flyout . ensureAllClosed ( ) ; } } ) ( ) ; }