import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; import { MlApi } from './api' ; import { JOB_STATE , DATAFEED_STATE } from '../../../../plugins/ml/common/constants/states' ; export function MachineLearningJobManagementProvider ( { getService } , mlApi ) { const testSubjects = getService ( 'testSubjects' ) ; return { async navigateToNewJobSourceSelection ( ) { await testSubjects . clickWhenNotDisabled ( 'mlCreateNewJobButton' ) ; await testSubjects . existOrFail ( 'mlPageSourceSelection' ) ; } , async assertJobTableExists ( ) { await testSubjects . existOrFail ( '~mlJobListTable' ) ; } , async assertCreateNewJobButtonExists ( ) { await testSubjects . existOrFail ( 'mlCreateNewJobButton' ) ; } , async assertCreateNewJobButtonEnabled ( expectedValue ) { const isEnabled = await testSubjects . isEnabled ( 'mlCreateNewJobButton' ) ; expect ( isEnabled ) . to . eql ( expectedValue , `Expected AD "Create job" button to be '${ expectedValue ? 'enabled' : 'disabled' }' (got '${ isEnabled ? 'enabled' : 'disabled' }')` ) ; } , async assertJobStatsBarExists ( ) { await testSubjects . existOrFail ( '~mlJobStatsBar' ) ; } , async assertStartDatafeedModalExists ( ) { await testSubjects . existOrFail ( 'mlStartDatafeedModal' , { timeout : 5000 } ) ; } , async confirmStartDatafeedModal ( ) { await testSubjects . click ( 'mlStartDatafeedModalStartButton' ) ; await testSubjects . missingOrFail ( 'mlStartDatafeedModal' ) ; } , async waitForJobCompletion ( jobId ) { await mlApi . waitForADJobRecordCountToBePositive ( jobId ) ; await mlApi . waitForDatafeedState ( `datafeed-${ jobId }` , DATAFEED_STATE . STOPPED ) ; await mlApi . waitForJobState ( jobId , JOB_STATE . CLOSED ) ; } , } ; }