import expect from '@kbn/expect' ; import { FtrProviderContext } from '../ftr_provider_context' ; export function RuleDetailsPageProvider ( { getService } ) { const testSubjects = getService ( 'testSubjects' ) ; const find = getService ( 'find' ) ; const log = getService ( 'log' ) ; const retry = getService ( 'retry' ) ; return { async getHeadingText ( ) { return await testSubjects . getVisibleText ( 'alertDetailsTitle' ) ; } , async getRuleType ( ) { return await testSubjects . getVisibleText ( 'alertTypeLabel' ) ; } , async getActionsLabels ( ) { return { connectorType : await testSubjects . getVisibleText ( 'actionTypeLabel' ) , } ; } , async getAlertsList ( ) { const table = await find . byCssSelector ( '.euiBasicTable[data-test-subj="alertsList"]:not(.euiBasicTable-loading)' ) ; const $ = await table . parseDomContent ( ) ; return $ . findTestSubjects ( 'alert-row' ) . toArray ( ) . map ( ( row ) => { return { alert : $ ( row ) . findTestSubject ( 'alertsTableCell-alert' ) . find ( '.euiTableCellContent' ) . text ( ) , status : $ ( row ) . findTestSubject ( 'alertsTableCell-status' ) . find ( '.euiTableCellContent' ) . text ( ) , start : $ ( row ) . findTestSubject ( 'alertsTableCell-start' ) . find ( '.euiTableCellContent' ) . text ( ) , duration : $ ( row ) . findTestSubject ( 'alertsTableCell-duration' ) . find ( '.euiTableCellContent' ) . text ( ) , } ; } ) ; } , async getAlertDurationEpoch ( ) { const alertDurationEpoch = await find . byCssSelector ( 'input[data-test-subj="alertsDurationEpoch"]' ) ; return parseInt ( await alertDurationEpoch . getAttribute ( 'value' ) , 10 ) ; } , async clickAlertMuteButton ( alert ) { const muteAlertButton = await testSubjects . find ( `muteAlertButton_${ alert }` ) ; await muteAlertButton . click ( ) ; } , async ensureAlertMuteState ( alert , isMuted ) { await retry . try ( async ( ) => { const muteAlertButton = await testSubjects . find ( `muteAlertButton_${ alert }` ) ; log . debug ( `checked:${ await muteAlertButton . getAttribute ( 'aria-checked' ) }` ) ; expect ( await muteAlertButton . getAttribute ( 'aria-checked' ) ) . to . eql ( isMuted ? 'true' : 'false' ) ; } ) ; } , async ensureAlertExistence ( alert , shouldExist ) { await retry . try ( async ( ) => { const table = await find . byCssSelector ( '.euiBasicTable[data-test-subj="alertsList"]:not(.euiBasicTable-loading)' ) ; const $ = await table . parseDomContent ( ) ; expect ( $ . findTestSubjects ( 'alert-row' ) . toArray ( ) . filter ( ( row ) => $ ( row ) . findTestSubject ( 'alertsTableCell-alert' ) . find ( '.euiTableCellContent' ) . text ( ) === alert ) ) . to . eql ( shouldExist ? 1 : 0 ) ; } ) ; } , async clickPaginationNextPage ( ) { const nextButton = await testSubjects . find ( `pagination-button-next` ) ; nextButton . click ( ) ; } , async isViewInAppDisabled ( ) { await retry . try ( async ( ) => { const viewInAppButton = await testSubjects . find ( `alertDetails-viewInApp` ) ; expect ( await viewInAppButton . getAttribute ( 'disabled' ) ) . to . eql ( 'true' ) ; } ) ; return true ; } , async isViewInAppEnabled ( ) { await retry . try ( async ( ) => { const viewInAppButton = await testSubjects . find ( `alertDetails-viewInApp` ) ; expect ( await viewInAppButton . getAttribute ( 'disabled' ) ) . to . not . eql ( 'true' ) ; } ) ; return true ; } , async clickViewInApp ( ) { return await testSubjects . click ( 'alertDetails-viewInApp' ) ; } , async getNoOpAppTitle ( ) { await retry . try ( async ( ) => { const title = await testSubjects . find ( 'noop-title' ) ; expect ( title . isDisplayed ( ) ) . to . eql ( true ) ; } ) ; return await testSubjects . getVisibleText ( 'noop-title' ) ; } , } ; }