import { FtrProviderContext } from '../../../ftr_provider_context' ; export default function ( { getService } ) { const esArchiver = getService ( 'esArchiver' ) ; const ml = getService ( 'ml' ) ; const adJobId1 = 'fq_single_1' ; const adJobId2 = 'fq_single_2' ; const adJobId3 = 'fq_single_3' ; const adJobIdES = 'fq_single_es' ; const dfaJobId1 = 'ihp_od_1' ; const dfaJobIdES = 'ihp_od_es' ; describe ( 'synchronize' , function ( ) { this . tags ( [ 'mlqa' ] ) ; before ( async ( ) => { await esArchiver . loadIfNeeded ( 'x-pack/test/functional/es_archives/ml/farequote' ) ; await esArchiver . loadIfNeeded ( 'x-pack/test/functional/es_archives/ml/ihp_outlier' ) ; await ml . testResources . createIndexPatternIfNeeded ( 'ft_farequote' , '@timestamp' ) ; await ml . testResources . setKibanaTimeZoneToUTC ( ) ; await ml . securityUI . loginAsMlPowerUser ( ) ; await ml . testResources . cleanMLSavedObjects ( ) ; } ) ; after ( async ( ) => { for ( const adJobId of [ adJobId1 , adJobId2 , adJobId3 , adJobIdES ] ) { await ml . api . deleteAnomalyDetectionJobES ( adJobId ) ; } for ( const dfaJobId of [ dfaJobId1 , dfaJobIdES ] ) { await ml . api . deleteDataFrameAnalyticsJobES ( dfaJobId ) ; } await ml . testResources . cleanMLSavedObjects ( ) ; await ml . testResources . deleteIndexPatternByTitle ( 'ft_farequote' ) ; } ) ; it ( 'should have nothing to sync initially' , async ( ) => { await ml . navigation . navigateToMl ( ) ; await ml . overviewPage . assertJobSyncRequiredWarningNotExists ( ) ; await ml . navigation . navigateToStackManagement ( ) ; await ml . navigation . navigateToStackManagementJobsListPage ( ) ; await ml . stackManagementJobs . openSyncFlyout ( ) ; await ml . stackManagementJobs . assertSyncFlyoutObjectCounts ( new Map ( [ [ 'MissingObjects' , 0 ] , [ 'UnmatchedObjects' , 0 ] , [ 'ObjectsMissingDatafeed' , 0 ] , [ 'ObjectsUnmatchedDatafeed' , 0 ] , ] ) ) ; await ml . stackManagementJobs . assertSyncFlyoutSyncButtonEnabled ( false ) ; } ) ; it ( 'should prepare test data' , async ( ) => { for ( const jobId of [ adJobId1 , adJobId2 , adJobId3 ] ) { await ml . api . createAnomalyDetectionJob ( ml . commonConfig . getADFqSingleMetricJobConfig ( jobId ) ) ; } await ml . api . createDataFrameAnalyticsJob ( ml . commonConfig . getDFAIhpOutlierDetectionJobConfig ( dfaJobId1 ) ) ; await ml . api . createAnomalyDetectionJobES ( ml . commonConfig . getADFqSingleMetricJobConfig ( adJobIdES ) ) ; await ml . api . createDataFrameAnalyticsJobES ( ml . commonConfig . getDFAIhpOutlierDetectionJobConfig ( dfaJobIdES ) ) ; const datafeedConfig2 = ml . commonConfig . getADFqDatafeedConfig ( adJobId2 ) ; await ml . api . createDatafeedES ( datafeedConfig2 ) ; const datafeedConfig3 = ml . commonConfig . getADFqDatafeedConfig ( adJobId3 ) ; await ml . api . createDatafeed ( datafeedConfig3 ) ; await ml . api . deleteDatafeedES ( datafeedConfig3 . datafeed_id ) ; await ml . api . assertJobSpaces ( adJobIdES , 'anomaly-detector' , [ ] ) ; await ml . api . deleteAnomalyDetectionJobES ( adJobId1 ) ; await ml . api . deleteDataFrameAnalyticsJobES ( dfaJobId1 ) ; } ) ; it ( 'should have objects to sync' , async ( ) => { await ml . navigation . navigateToMl ( ) ; await ml . overviewPage . assertJobSyncRequiredWarningExists ( ) ; await ml . navigation . navigateToStackManagement ( ) ; await ml . navigation . navigateToStackManagementJobsListPage ( ) ; await ml . stackManagementJobs . openSyncFlyout ( ) ; await ml . stackManagementJobs . assertSyncFlyoutObjectCounts ( new Map ( [ [ 'MissingObjects' , 2 ] , [ 'UnmatchedObjects' , 2 ] , [ 'ObjectsMissingDatafeed' , 1 ] , [ 'ObjectsUnmatchedDatafeed' , 1 ] , ] ) ) ; await ml . stackManagementJobs . assertSyncFlyoutSyncButtonEnabled ( true ) ; } ) ; it ( 'should synchronize datafeeds and saved objects' , async ( ) => { await ml . stackManagementJobs . executeSync ( ) ; await ml . stackManagementJobs . closeSyncFlyout ( ) ; } ) ; it ( 'should have nothing to sync anymore' , async ( ) => { await ml . stackManagementJobs . openSyncFlyout ( ) ; await ml . stackManagementJobs . assertSyncFlyoutObjectCounts ( new Map ( [ [ 'MissingObjects' , 0 ] , [ 'UnmatchedObjects' , 0 ] , [ 'ObjectsMissingDatafeed' , 0 ] , [ 'ObjectsUnmatchedDatafeed' , 0 ] , ] ) ) ; await ml . stackManagementJobs . assertSyncFlyoutSyncButtonEnabled ( false ) ; await ml . stackManagementJobs . closeSyncFlyout ( ) ; await ml . navigation . navigateToMl ( ) ; await ml . overviewPage . assertJobSyncRequiredWarningNotExists ( ) ; } ) ; } ) ; }