import { FtrProviderContext } from '../ftr_provider_context' ; import { WebElementWrapper } from '../../../../test/functional/services/lib/web_element_wrapper' ; export function IngestManagerCreatePackagePolicy ( { getService , getPageObjects , } ) { const testSubjects = getService ( 'testSubjects' ) ; const find = getService ( 'find' ) ; const pageObjects = getPageObjects ( [ 'common' ] ) ; const browser = getService ( 'browser' ) ; return { /**
         * Validates that the page shown is the Package Policy Create Page
         */ async ensureOnCreatePageOrFail ( ) { await testSubjects . existOrFail ( 'createPackagePolicy_header' ) ; } , /**
         * Finds and returns the Cancel button on the sticky bottom bar
         */ async findCancelButton ( ) { return await testSubjects . find ( 'createPackagePolicyCancelButton' ) ; } , /**
         * Finds and returns the Cancel back link at the top of the create page
         */ async findBackLink ( ) { return await testSubjects . find ( 'createPackagePolicy_cancelBackLink' ) ; } , /**
         * Finds and returns the save button on the sticky bottom bar
         */ async findSaveButton ( forEditPage = false ) { return await testSubjects . find ( forEditPage ? 'saveIntegration' : 'createPackagePolicySaveButton' ) ; } , param name async selectAgentPolicy ( name ? ) { if ( name ) { await find . clickByCssSelector ( `[data-test-subj="agentPolicyItem"][title="${ name }"]` ) ; } else { await testSubjects . click ( 'agentPolicyItem' ) ; } } , /**
         * Returns the package Policy name currently populated on the input field
         */ async getPackagePolicyName ( ) { return testSubjects . getAttribute ( 'packagePolicyNameInput' , 'value' ) ; } , param name async setPackagePolicyName ( name ) { await testSubjects . scrollIntoView ( 'dataCollectionSetupStep' ) ; await testSubjects . setValue ( 'packagePolicyNameInput' , name ) ; } , async getPackagePolicyDescriptionValue ( ) { return await testSubjects . getAttribute ( 'packagePolicyDescriptionInput' , 'value' ) ; } , async setPackagePolicyDescription ( desc ) { await this . scrollToCenterOfWindow ( 'packagePolicyDescriptionInput' ) ; const packagePolicyDescriptionInput = await testSubjects . find ( 'packagePolicyDescriptionInput' ) ; await packagePolicyDescriptionInput . clearValueWithKeyboard ( ) ; await packagePolicyDescriptionInput . type ( desc ) ; } , /**
         * Waits for the save Notification toast to be visible
         */ async waitForSaveSuccessNotification ( forEditPage = false ) { await testSubjects . existOrFail ( forEditPage ? 'policyUpdateSuccessToast' : 'packagePolicyCreateSuccessToast' ) ; } , /**
         * Validates that the page shown is the Package Policy Edit Page
         */ async ensureOnEditPageOrFail ( ) { await testSubjects . existOrFail ( 'editPackagePolicy_header' ) ; } , /**
         * Navigates to the Ingest Agent configuration Edit Package Policy page
         */ async navigateToAgentPolicyEditPackagePolicy ( agentPolicyId , packagePolicyId ) { await pageObjects . common . navigateToApp ( 'fleet' , { hash : `/policies/${ agentPolicyId }/edit-integration/${ packagePolicyId }` , } ) ; await this . ensureOnEditPageOrFail ( ) ; } , /**
         * Returns the Endpoint Callout that is displayed on the Integration Policy create/edit pages
         */ async findEndpointActionsButton ( ) { const button = await testSubjects . find ( 'endpointActions' ) ; await this . scrollToCenterOfWindow ( button ) ; return button ; } , param element async scrollToCenterOfWindow ( element ) { const ele = typeof element === 'string' ? await testSubjects . find ( element ) : element ; const [ elementPosition , windowSize ] = await Promise . all ( [ ele . getPosition ( ) , browser . getWindowSize ( ) , ] ) ; await browser . execute ( `document.scrollingElement.scrollTop = ${ elementPosition . y - windowSize . height / 2 }` ) ; } , param action async selectEndpointAction ( action ) { await ( await this . findEndpointActionsButton ( ) ) . click ( ) ; const testSubjId = action === 'policy' ? 'securityPolicy' : 'trustedAppsAction' ; await ( await testSubjects . find ( testSubjId ) ) . click ( ) ; } , } ; }