import expect from '@kbn/expect' ; import { FtrProviderContext } from '../ftr_provider_context' ; export function EndpointPolicyPageProvider ( { getService , getPageObjects } ) { const pageObjects = getPageObjects ( [ 'common' , 'header' ] ) ; const testSubjects = getService ( 'testSubjects' ) ; const retryService = getService ( 'retry' ) ; return { param policyId async navigateToPolicyDetails ( policyId ) { await pageObjects . common . navigateToUrlWithBrowserHistory ( 'securitySolutionManagement' , `/policy/${ policyId }` ) ; await pageObjects . header . waitUntilLoadingHasFinished ( ) ; } , /**
         * Finds and returns the Policy Details Page Save button
         */ async findSaveButton ( ) { await this . ensureIsOnDetailsPage ( ) ; return await testSubjects . find ( 'policyDetailsSaveButton' ) ; } , /**
         * Finds and returns the Policy Details Page Cancel Button
         */ async findCancelButton ( ) { await this . ensureIsOnDetailsPage ( ) ; return await testSubjects . find ( 'policyDetailsCancelButton' ) ; } , /**
         * Finds and returns the Advanced Policy Show/Hide Button
         */ async findAdvancedPolicyButton ( ) { await this . ensureIsOnDetailsPage ( ) ; return await testSubjects . find ( 'advancedPolicyButton' ) ; } , async isAdvancedSettingsExpanded ( ) { return await testSubjects . exists ( 'advancedPolicyPanel' ) ; } , /**
         * shows the advanced settings section and scrolls it into view
         */ async showAdvancedSettingsSection ( ) { if ( ! ( await this . isAdvancedSettingsExpanded ( ) ) ) { const expandButton = await this . findAdvancedPolicyButton ( ) ; await expandButton . click ( ) ; } await testSubjects . existOrFail ( 'advancedPolicyPanel' ) ; await testSubjects . scrollIntoView ( 'advancedPolicyPanel' ) ; } , /**
         * Hides the advanced settings section
         */ async hideAdvancedSettingsSection ( ) { if ( await this . isAdvancedSettingsExpanded ( ) ) { const expandButton = await this . findAdvancedPolicyButton ( ) ; await expandButton . click ( ) ; } await testSubjects . missingOrFail ( 'advancedPolicyPanel' ) ; } , /**
         * Finds and returns the linux connection_delay Advanced Policy field
         */ async findAdvancedPolicyField ( ) { await this . ensureIsOnDetailsPage ( ) ; return await testSubjects . find ( 'linux.advanced.agent.connection_delay' ) ; } , /**
         * ensures that the Details Page is the currently display view
         */ async ensureIsOnDetailsPage ( ) { await testSubjects . existOrFail ( 'policyDetailsPage' ) ; } , /**
         * Clicks Save button and confirms update on the Policy Details page
         */ async confirmAndSave ( ) { await this . ensureIsOnDetailsPage ( ) ; const saveButton = await this . findSaveButton ( ) ; await pageObjects . common . clearAllToasts ( ) ; await saveButton . click ( ) ; await testSubjects . existOrFail ( 'policyDetailsConfirmModal' ) ; await pageObjects . common . clickConfirmOnModal ( ) ; } , /**
         * Finds and returns the Create New policy Policy button displayed on the List page
         */ async findHeaderCreateNewButton ( ) { await testSubjects . waitForEnabled ( 'headerCreateNewPolicyButton' ) ; return await testSubjects . find ( 'headerCreateNewPolicyButton' ) ; } , param onEditPage async findPackagePolicyEndpointCustomConfiguration ( onEditPage = false ) { return await testSubjects . find ( `endpointPackagePolicy_${ onEditPage ? 'edit' : 'create' }` ) ; } , param selector param expectedSelectedValue async waitForCheckboxSelectionChange ( selector , expectedSelectedValue ) { await retryService . try ( async ( ) => { expect ( await testSubjects . isSelected ( selector ) ) . to . be ( expectedSelectedValue ) ; } ) ; } , } ; }