import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; import { MlCommonUI } from './common_ui' ; export function MachineLearningSingleMetricViewerProvider ( { getService } , mlCommonUI ) { const comboBox = getService ( 'comboBox' ) ; const testSubjects = getService ( 'testSubjects' ) ; return { async assertSingleMetricViewerEmptyListMessageExsist ( ) { await testSubjects . existOrFail ( 'mlNoSingleMetricJobsFound' ) ; } , async assertDetectorInputExist ( ) { await testSubjects . existOrFail ( 'mlSingleMetricViewerSeriesControls > mlSingleMetricViewerDetectorSelect' ) ; } , async assertDetectorInputValue ( expectedDetectorOptionValue ) { const actualDetectorValue = await testSubjects . getAttribute ( 'mlSingleMetricViewerSeriesControls > mlSingleMetricViewerDetectorSelect' , 'value' ) ; expect ( actualDetectorValue ) . to . eql ( expectedDetectorOptionValue , `Detector input option value should be '${ expectedDetectorOptionValue }' (got '${ actualDetectorValue }')` ) ; } , async setDetectorInputValue ( detectorOptionValue ) { await testSubjects . selectValue ( 'mlSingleMetricViewerSeriesControls > mlSingleMetricViewerDetectorSelect' , detectorOptionValue ) ; await this . assertDetectorInputValue ( detectorOptionValue ) ; } , async assertEntityInputExist ( entityFieldName ) { await testSubjects . existOrFail ( `mlSingleMetricViewerEntitySelection ${ entityFieldName }` ) ; } , async assertEntityInputSelection ( entityFieldName , expectedIdentifier ) { const comboBoxSelectedOptions = await comboBox . getComboBoxSelectedOptions ( `mlSingleMetricViewerEntitySelection ${ entityFieldName }  > comboBoxInput` ) ; expect ( comboBoxSelectedOptions ) . to . eql ( expectedIdentifier , `Expected entity field selection for '${ entityFieldName }' to be '${ expectedIdentifier }' (got '${ comboBoxSelectedOptions }')` ) ; } , async selectEntityValue ( entityFieldName , entityFieldValue ) { await comboBox . set ( `mlSingleMetricViewerEntitySelection ${ entityFieldName }  > comboBoxInput` , entityFieldValue ) ; await this . assertEntityInputSelection ( entityFieldName , [ entityFieldValue ] ) ; } , async assertChartExist ( ) { await testSubjects . existOrFail ( 'mlSingleMetricViewerChart' ) ; } , async assertAnnotationsExists ( state ) { await testSubjects . existOrFail ( `mlAnomalyExplorerAnnotations ${ state }` , { timeout : 30 * 1000 , } ) ; } , async openAnomalyExplorer ( ) { await testSubjects . click ( 'mlAnomalyResultsViewSelectorExplorer' ) ; await testSubjects . existOrFail ( 'mlPageAnomalyExplorer' ) ; } , async openConfigForControl ( entityFieldName ) { const isPopoverOpened = await testSubjects . exists ( `mlSingleMetricViewerEntitySelectionConfigPopover_${ entityFieldName }` ) ; if ( isPopoverOpened ) { return ; } await testSubjects . click ( `mlSingleMetricViewerEntitySelectionConfigButton_${ entityFieldName }` ) ; await testSubjects . existOrFail ( `mlSingleMetricViewerEntitySelectionConfigPopover_${ entityFieldName }` ) ; } , async assertEntityConfig ( entityFieldName , anomalousOnly , sortBy , order ) { await this . openConfigForControl ( entityFieldName ) ; expect ( await testSubjects . isEuiSwitchChecked ( `mlSingleMetricViewerEntitySelectionConfigAnomalousOnly_${ entityFieldName }` ) ) . to . eql ( anomalousOnly , `Expected the "Anomalous only" control for "${ entityFieldName }" to be ${ anomalousOnly ? 'enabled' : 'disabled' }` ) ; await mlCommonUI . assertRadioGroupValue ( `mlSingleMetricViewerEntitySelectionConfigSortBy_${ entityFieldName }` , sortBy ) ; await mlCommonUI . assertRadioGroupValue ( `mlSingleMetricViewerEntitySelectionConfigOrder_${ entityFieldName }` , order ) ; } , async setEntityConfig ( entityFieldName , anomalousOnly , sortBy , order ) { await this . openConfigForControl ( entityFieldName ) ; await testSubjects . setEuiSwitch ( `mlSingleMetricViewerEntitySelectionConfigAnomalousOnly_${ entityFieldName }` , anomalousOnly ? 'check' : 'uncheck' ) ; await mlCommonUI . selectRadioGroupValue ( `mlSingleMetricViewerEntitySelectionConfigSortBy_${ entityFieldName }` , sortBy ) ; await mlCommonUI . selectRadioGroupValue ( `mlSingleMetricViewerEntitySelectionConfigOrder_${ entityFieldName }` , order ) ; await this . assertEntityConfig ( entityFieldName , anomalousOnly , sortBy , order ) ; } , async assertToastMessageExists ( dataTestSubj ) { const toast = await testSubjects . find ( dataTestSubj ) ; expect ( toast ) . not . to . be ( undefined ) ; } , async assertDisabledJobReasonWarningToastExist ( ) { await this . assertToastMessageExists ( 'mlTimeSeriesExplorerDisabledJobReasonWarningToast' ) ; } , } ; }