import { WebElementWrapper } from 'test/functional/services/lib/web_element_wrapper' ; import { FtrProviderContext } from '../ftr_provider_context' ; export function SyntheticsIntegrationPageProvider ( { getService , getPageObjects , } ) { const pageObjects = getPageObjects ( [ 'common' , 'header' ] ) ; const testSubjects = getService ( 'testSubjects' ) ; const comboBox = getService ( 'comboBox' ) ; const fixedFooterHeight = 72 ; return { /**
         * Navigates to the Synthetics Integration page
         *
         */ async navigateToPackagePage ( packageVersion ) { await pageObjects . common . navigateToUrlWithBrowserHistory ( 'fleet' , `/integrations/synthetics-${ packageVersion }/add-integration` ) ; await pageObjects . header . waitUntilLoadingHasFinished ( ) ; } , async navigateToPackageEditPage ( packageId , agentId ) { await pageObjects . common . navigateToUrlWithBrowserHistory ( 'fleet' , `/policies/${ agentId }/edit-integration/${ packageId }` ) ; await pageObjects . header . waitUntilLoadingHasFinished ( ) ; } , /**
         * Finds and returns the Policy Details Page Save button
         */ async findSaveButton ( isEditPage ? ) { await this . ensureIsOnPackagePage ( ) ; return await testSubjects . find ( isEditPage ? 'saveIntegration' : 'createPackagePolicySaveButton' ) ; } , /**
         * Finds and returns the Policy Details Page Cancel Button
         */ async findCancelButton ( ) { await this . ensureIsOnPackagePage ( ) ; return await testSubjects . find ( 'policyDetailsCancelButton' ) ; } , /**
         * Determines if the policy was created successfully by looking for the creation success toast
         */ async isPolicyCreatedSuccessfully ( ) { await testSubjects . existOrFail ( 'postInstallAddAgentModal' ) ; } , params async selectMonitorType ( monitorType ) { await testSubjects . selectValue ( 'syntheticsMonitorTypeField' , monitorType ) ; } , params params async fillTextInputByTestSubj ( testSubj , value ) { const field = await testSubjects . find ( testSubj ) ; await field . scrollIntoViewIfNecessary ( { bottomOffset : fixedFooterHeight } ) ; await field . click ( ) ; await field . clearValue ( ) ; await field . type ( value ) ; } , params params async fillTextInput ( field , value ) { await field . scrollIntoViewIfNecessary ( { bottomOffset : fixedFooterHeight } ) ; await field . click ( ) ; await field . clearValue ( ) ; await field . type ( value ) ; } , params async setComboBox ( testSubj , value ) { await comboBox . setCustom ( `${ testSubj } > comboBoxInput` , value ) ; } , /**
         * Finds and returns the HTTP advanced options accordion trigger
         */ async findHTTPAdvancedOptionsAccordion ( ) { await this . ensureIsOnPackagePage ( ) ; const accordion = await testSubjects . find ( 'syntheticsHTTPAdvancedFieldsAccordion' ) ; return accordion ; } , /**
         * Finds and returns the enable throttling checkbox
         */ async findThrottleSwitch ( ) { await this . ensureIsOnPackagePage ( ) ; return await testSubjects . find ( 'syntheticsBrowserIsThrottlingEnabled' ) ; } , /**
         * Finds and returns the enable TLS checkbox
         */ async findEnableTLSSwitch ( ) { await this . ensureIsOnPackagePage ( ) ; return await testSubjects . find ( 'syntheticsIsTLSEnabled' ) ; } , /**
         * ensures that the package page is the currently display view
         */ async ensureIsOnPackagePage ( ) { await testSubjects . existOrFail ( 'monitorSettingsSection' ) ; } , /**
         * Clicks save button and confirms update on the Policy Details page
         */ async confirmAndSave ( isEditPage ? ) { await this . ensureIsOnPackagePage ( ) ; const saveButton = await this . findSaveButton ( isEditPage ) ; saveButton . click ( ) ; } , params params async configureUsernameAndPassword ( { username , password } ) { await this . fillTextInputByTestSubj ( 'syntheticsUsername' , username ) ; await this . fillTextInputByTestSubj ( 'syntheticsPassword' , password ) ; } , params async configureRequestHeaders ( headers ) { await this . configureHeaders ( 'syntheticsRequestHeaders' , headers ) ; } , params async configureResponseHeaders ( headers ) { await this . configureHeaders ( 'syntheticsResponseHeaders' , headers ) ; } , params params async configureHeaders ( testSubj , headers ) { const headersContainer = await testSubjects . find ( testSubj ) ; const addHeaderButton = await testSubjects . find ( `${ testSubj }__button` ) ; const keys = Object . keys ( headers ) ; await Promise . all ( keys . map ( async ( key , index ) => { await addHeaderButton . click ( ) ; const keyField = await headersContainer . findByCssSelector ( `[data-test-subj="keyValuePairsKey${ index }"]` ) ; const valueField = await headersContainer . findByCssSelector ( `[data-test-subj="keyValuePairsValue${ index }"]` ) ; await this . fillTextInput ( keyField , key ) ; await this . fillTextInput ( valueField , headers [ key ] ) ; } ) ) ; } , params params async configureRequestBody ( testSubj , value ) { await testSubjects . click ( `syntheticsRequestBodyTab__${ testSubj }` ) ; await this . fillCodeEditor ( value ) ; } , params async fillCodeEditor ( value ) { const codeEditorContainer = await testSubjects . find ( 'codeEditorContainer' ) ; const textArea = await codeEditorContainer . findByCssSelector ( 'textarea' ) ; await textArea . clearValue ( ) ; await textArea . type ( value ) ; } , params params async createBasicMonitorDetails ( { name , apmServiceName , tags } ) { await this . fillTextInputByTestSubj ( 'packagePolicyNameInput' , name ) ; await this . fillTextInputByTestSubj ( 'syntheticsAPMServiceName' , apmServiceName ) ; await this . setComboBox ( 'syntheticsTags' , tags ) ; } , params params async createBasicHTTPMonitorDetails ( { name , url , apmServiceName , tags , } ) { await this . createBasicMonitorDetails ( { name , apmServiceName , tags } ) ; await this . fillTextInputByTestSubj ( 'syntheticsUrlField' , url ) ; } , params params async createBasicTCPMonitorDetails ( { name , host , apmServiceName , tags , } ) { await this . selectMonitorType ( 'tcp' ) ; await this . createBasicMonitorDetails ( { name , apmServiceName , tags } ) ; await this . fillTextInputByTestSubj ( 'syntheticsTCPHostField' , host ) ; } , params params async createBasicICMPMonitorDetails ( { name , host , apmServiceName , tags , } ) { await this . selectMonitorType ( 'icmp' ) ; await this . fillTextInputByTestSubj ( 'packagePolicyNameInput' , name ) ; await this . createBasicMonitorDetails ( { name , apmServiceName , tags } ) ; await this . fillTextInputByTestSubj ( 'syntheticsICMPHostField' , host ) ; } , params params async createBasicBrowserMonitorDetails ( { name , inlineScript , zipUrl , folder , params , username , password , apmServiceName , tags , } , isInline = false ) { await this . selectMonitorType ( 'browser' ) ; await this . fillTextInputByTestSubj ( 'packagePolicyNameInput' , name ) ; await this . createBasicMonitorDetails ( { name , apmServiceName , tags } ) ; if ( isInline ) { await testSubjects . click ( 'syntheticsSourceTab__inline' ) ; await this . fillCodeEditor ( inlineScript ) ; return ; } await this . fillTextInputByTestSubj ( 'syntheticsBrowserZipUrl' , zipUrl ) ; await this . fillTextInputByTestSubj ( 'syntheticsBrowserZipUrlFolder' , folder ) ; await this . fillTextInputByTestSubj ( 'syntheticsBrowserZipUrlUsername' , username ) ; await this . fillTextInputByTestSubj ( 'syntheticsBrowserZipUrlPassword' , password ) ; await this . fillCodeEditor ( params ) ; } , /**
         * Enables TLS
         */ async enableTLS ( ) { const tlsSwitch = await this . findEnableTLSSwitch ( ) ; await tlsSwitch . click ( ) ; } , params async configureTLSOptions ( { verificationMode , ca , cert , certKey , certKeyPassphrase , } ) { await this . enableTLS ( ) ; await testSubjects . selectValue ( 'syntheticsTLSVerificationMode' , verificationMode ) ; await this . fillTextInputByTestSubj ( 'syntheticsTLSCA' , ca ) ; await this . fillTextInputByTestSubj ( 'syntheticsTLSCert' , cert ) ; await this . fillTextInputByTestSubj ( 'syntheticsTLSCertKey' , certKey ) ; await this . fillTextInputByTestSubj ( 'syntheticsTLSCertKeyPassphrase' , certKeyPassphrase ) ; } , /**
         * Configure http advanced settings
         */ async configureHTTPAdvancedOptions ( { username , password , proxyUrl , requestMethod , requestHeaders , responseStatusCheck , responseBodyCheckPositive , responseBodyCheckNegative , requestBody , responseHeaders , indexResponseBody , indexResponseHeaders , } ) { await testSubjects . click ( 'syntheticsHTTPAdvancedFieldsAccordion' ) ; await this . configureResponseHeaders ( responseHeaders ) ; await this . configureRequestHeaders ( requestHeaders ) ; await this . configureRequestBody ( requestBody . type , requestBody . value ) ; await this . configureUsernameAndPassword ( { username , password } ) ; await this . setComboBox ( 'syntheticsResponseStatusCheck' , responseStatusCheck ) ; await this . setComboBox ( 'syntheticsResponseBodyCheckPositive' , responseBodyCheckPositive ) ; await this . setComboBox ( 'syntheticsResponseBodyCheckNegative' , responseBodyCheckNegative ) ; await this . fillTextInputByTestSubj ( 'syntheticsProxyUrl' , proxyUrl ) ; await testSubjects . selectValue ( 'syntheticsRequestMethod' , requestMethod ) ; if ( ! indexResponseBody ) { const field = await testSubjects . find ( 'syntheticsIndexResponseBody' ) ; const label = await field . findByCssSelector ( 'label' ) ; await label . click ( ) ; } if ( ! indexResponseHeaders ) { const field = await testSubjects . find ( 'syntheticsIndexResponseHeaders' ) ; const label = await field . findByCssSelector ( 'label' ) ; await label . click ( ) ; } } , /**
         * Configure tcp advanced settings
         */ async configureTCPAdvancedOptions ( { proxyUrl , requestSendCheck , responseReceiveCheck , proxyUseLocalResolver , } ) { await testSubjects . click ( 'syntheticsTCPAdvancedFieldsAccordion' ) ; await this . fillTextInputByTestSubj ( 'syntheticsProxyUrl' , proxyUrl ) ; await this . fillTextInputByTestSubj ( 'syntheticsTCPRequestSendCheck' , requestSendCheck ) ; await this . fillTextInputByTestSubj ( 'syntheticsTCPResponseReceiveCheck' , responseReceiveCheck ) ; if ( proxyUseLocalResolver ) { const field = await testSubjects . find ( 'syntheticsUseLocalResolver' ) ; const label = await field . findByCssSelector ( 'label' ) ; await label . click ( ) ; } } , params params async configureBrowserAdvancedOptions ( { screenshots , syntheticsArgs , isThrottlingEnabled , downloadSpeed , uploadSpeed , latency , } ) { await testSubjects . click ( 'syntheticsBrowserAdvancedFieldsAccordion' ) ; const throttleSwitch = await this . findThrottleSwitch ( ) ; if ( ( await throttleSwitch . isSelected ( ) ) !== isThrottlingEnabled ) { await throttleSwitch . click ( ) ; } await testSubjects . selectValue ( 'syntheticsBrowserScreenshots' , screenshots ) ; await this . setComboBox ( 'syntheticsBrowserSyntheticsArgs' , syntheticsArgs ) ; if ( isThrottlingEnabled ) { await this . fillTextInputByTestSubj ( 'syntheticsBrowserDownloadSpeed' , downloadSpeed ) ; await this . fillTextInputByTestSubj ( 'syntheticsBrowserUploadSpeed' , uploadSpeed ) ; await this . fillTextInputByTestSubj ( 'syntheticsBrowserLatency' , latency ) ; } } , } ; }