import { FtrProviderContext } from '../ftr_provider_context' ; import { WebElementWrapper } from '../../../../test/functional/services/lib/web_element_wrapper' ; export function InfraSourceConfigurationFormProvider ( { getService } ) { const retry = getService ( 'retry' ) ; const testSubjects = getService ( 'testSubjects' ) ; const browser = getService ( 'browser' ) ; return { /**
         * Indices and fields
         */ async getNameInput ( ) { return await testSubjects . findDescendant ( '~nameInput' , await this . getForm ( ) ) ; } , async getLogIndicesInput ( ) { return await testSubjects . findDescendant ( '~logIndicesInput' , await this . getForm ( ) ) ; } , async getMetricIndicesInput ( ) { return await testSubjects . findDescendant ( '~metricIndicesInput' , await this . getForm ( ) ) ; } , /**
         * Logs
         */ async getAddLogColumnButton ( ) { return await testSubjects . findDescendant ( '~addLogColumnButton' , await this . getForm ( ) ) ; } , async getAddLogColumnPopover ( ) { return await testSubjects . find ( '~addLogColumnPopover' ) ; } , async addTimestampLogColumn ( ) { const popover = await retry . try ( async ( ) => { await ( await this . getAddLogColumnButton ( ) ) . click ( ) ; return this . getAddLogColumnPopover ( ) ; } ) ; await retry . try ( async ( ) => { await ( await testSubjects . findDescendant ( '~addTimestampLogColumn' , popover ) ) . click ( ) ; } ) ; await testSubjects . findDescendant ( '~systemLogColumnPanel:Timestamp' , await this . getForm ( ) ) ; } , async addFieldLogColumn ( fieldName ) { const popover = await retry . try ( async ( ) => { await ( await this . getAddLogColumnButton ( ) ) . click ( ) ; return this . getAddLogColumnPopover ( ) ; } ) ; await retry . try ( async ( ) => { await ( await testSubjects . findDescendant ( '~fieldSearchInput' , popover ) ) . type ( fieldName ) ; await ( await testSubjects . findDescendant ( `~addFieldLogColumn:${ fieldName }` , popover ) ) . click ( ) ; } ) ; await testSubjects . findDescendant ( `~fieldLogColumnPanel:${ fieldName }` , await this . getForm ( ) ) ; } , async getLogColumnPanels ( ) { return await testSubjects . findAllDescendant ( '~logColumnPanel' , await this . getForm ( ) ) ; } , async removeLogColumn ( columnIndex ) { const logColumnPanel = ( await this . getLogColumnPanels ( ) ) [ columnIndex ] ; await ( await testSubjects . findDescendant ( '~removeLogColumnButton' , logColumnPanel ) ) . click ( ) ; await testSubjects . waitForDeleted ( logColumnPanel ) ; } , async removeAllLogColumns ( ) { for ( const _ of await this . getLogColumnPanels ( ) ) { await this . removeLogColumn ( 0 ) ; } } , async moveLogColumn ( sourceIndex , destinationIndex ) { const KEY_PRESS_DELAY_MS = 500 ; const logColumnPanel = ( await this . getLogColumnPanels ( ) ) [ sourceIndex ] ; const moveLogColumnHandle = await testSubjects . findDescendant ( '~moveLogColumnHandle' , logColumnPanel ) ; await moveLogColumnHandle . focus ( ) ; const movementDifference = destinationIndex - sourceIndex ; await moveLogColumnHandle . pressKeys ( browser . keys . SPACE ) ; for ( let i = 0 ; i < Math . abs ( movementDifference ) ; i ++ ) { await new Promise ( ( res ) => setTimeout ( res , KEY_PRESS_DELAY_MS ) ) ; if ( movementDifference > 0 ) { await moveLogColumnHandle . pressKeys ( browser . keys . ARROW_DOWN ) ; } else { await moveLogColumnHandle . pressKeys ( browser . keys . ARROW_UP ) ; } } await moveLogColumnHandle . pressKeys ( browser . keys . SPACE ) ; await new Promise ( ( res ) => setTimeout ( res , KEY_PRESS_DELAY_MS ) ) ; } , /**
         * Form
         */ async getForm ( ) { return await testSubjects . find ( '~sourceConfigurationContent' ) ; } , async saveConfiguration ( ) { await ( await testSubjects . findDescendant ( '~applySettingsButton' , await this . getForm ( ) ) ) . click ( ) ; await retry . try ( async ( ) => { const element = await testSubjects . findDescendant ( '~applySettingsButton' , await this . getForm ( ) ) ; return ! ( await element . isEnabled ( ) ) ; } ) ; } , } ; }