import expect from '@kbn/expect' ; import { FtrService } from '../ftr_provider_context' ; export class UptimePageObject extends FtrService { private readonly timePicker = this . ctx . getPageObject ( 'timePicker' ) ; private readonly header = this . ctx . getPageObject ( 'header' ) ; private readonly commonService = this . ctx . getService ( 'uptime' ) . common ; private readonly monitor = this . ctx . getService ( 'uptime' ) . monitor ; private readonly navigation = this . ctx . getService ( 'uptime' ) . navigation ; private readonly retry = this . ctx . getService ( 'retry' ) ; public async goToRoot ( refresh ? ) { await this . navigation . goToUptime ( ) ; if ( refresh ) { await this . navigation . refreshApp ( ) ; } } public async setDateRange ( start , end ) { const { start : prevStart , end : prevEnd } = await this . timePicker . getTimeConfig ( ) ; if ( start !== prevStart || prevEnd !== end ) { await this . timePicker . setAbsoluteRange ( start , end ) ; } else { await this . navigation . refreshApp ( ) ; } } public async goToUptimeOverviewAndLoadData ( dateStart , dateEnd , monitorIdToCheck ? ) { await this . navigation . goToUptime ( ) ; await this . setDateRange ( dateStart , dateEnd ) ; if ( monitorIdToCheck ) { await this . commonService . monitorIdExists ( monitorIdToCheck ) ; } await this . header . waitUntilLoadingHasFinished ( ) ; } public async loadDataAndGoToMonitorPage ( dateStart , dateEnd , monitorId ) { await this . header . waitUntilLoadingHasFinished ( ) ; await this . setDateRange ( dateStart , dateEnd ) ; await this . navigation . goToMonitor ( monitorId ) ; } public async inputFilterQuery ( filterQuery ) { await this . commonService . setFilterText ( filterQuery ) ; } public async pageHasDataMissing ( ) { return await this . commonService . pageHasDataMissing ( ) ; } public async pageHasExpectedIds ( monitorIdsToCheck ) { return this . retry . tryForTime ( 15000 , async ( ) => { await Promise . all ( monitorIdsToCheck . map ( ( id ) => this . commonService . monitorPageLinkExists ( id ) ) ) ; } ) ; } public async pageUrlContains ( value , expected = true ) { return this . retry . tryForTime ( 12000 , async ( ) => { expect ( await this . commonService . urlContains ( value ) ) . to . eql ( expected ) ; } ) ; } public async changePage ( direction ) { if ( direction === 'next' ) { await this . commonService . goToNextPage ( ) ; } else if ( direction === 'prev' ) { await this . commonService . goToPreviousPage ( ) ; } } public async setStatusFilter ( value ) { if ( value === 'up' ) { await this . commonService . setStatusFilterUp ( ) ; } else if ( value === 'down' ) { await this . commonService . setStatusFilterDown ( ) ; } } public async selectFilterItems ( filters ) { for ( const key in filters ) { if ( filters . hasOwnProperty ( key ) ) { const values = filters [ key ] ; for ( let i = 0 ; i < values . length ; i ++ ) { await this . commonService . selectFilterItem ( key , values [ i ] ) ; } } } } public async getSnapshotCount ( ) { return await this . commonService . getSnapshotCount ( ) ; } public async setAlertKueryBarText ( filters ) { const { setKueryBarText } = this . commonService ; await setKueryBarText ( 'xpack.uptime.alerts.monitorStatus.filterBar' , filters ) ; } public async setMonitorListPageSize ( size ) { await this . commonService . openPageSizeSelectPopover ( ) ; return this . commonService . clickPageSizeSelectPopoverItem ( size ) ; } public async checkPingListInteractions ( timestamps ) { return this . monitor . checkForPingListTimestamps ( timestamps ) ; } public async resetFilters ( ) { await this . inputFilterQuery ( '' ) ; await this . commonService . resetStatusFilter ( ) ; } }