import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; export function MachineLearningNavigationProvider ( { getService , getPageObjects , } ) { const appsMenu = getService ( 'appsMenu' ) ; const browser = getService ( 'browser' ) ; const retry = getService ( 'retry' ) ; const testSubjects = getService ( 'testSubjects' ) ; const PageObjects = getPageObjects ( [ 'common' ] ) ; return { async navigateToMl ( ) { await retry . tryForTime ( 60 * 1000 , async ( ) => { await PageObjects . common . navigateToApp ( 'ml' ) ; await testSubjects . existOrFail ( 'mlApp' , { timeout : 2000 } ) ; } ) ; } , async navigateToMlViaAppsMenu ( ) { await retry . tryForTime ( 60 * 1000 , async ( ) => { await appsMenu . clickLink ( 'Machine Learning' ) ; await testSubjects . existOrFail ( 'mlApp' , { timeout : 2000 } ) ; } ) ; } , async navigateToStackManagement ( { expectMlLink = true } = { } ) { await retry . tryForTime ( 60 * 1000 , async ( ) => { await PageObjects . common . navigateToApp ( 'management' ) ; if ( expectMlLink ) { await testSubjects . existOrFail ( 'jobsListLink' , { timeout : 2000 } ) ; } else { await testSubjects . missingOrFail ( 'jobsListLink' , { timeout : 2000 } ) ; } } ) ; } , async navigateToStackManagementViaAppsMenu ( ) { await retry . tryForTime ( 60 * 1000 , async ( ) => { await appsMenu . clickLink ( 'Stack Management' ) ; await testSubjects . existOrFail ( 'jobsListLink' , { timeout : 2000 } ) ; } ) ; } , async navigateToAlertsAndAction ( ) { await PageObjects . common . navigateToApp ( 'triggersActions' ) ; await testSubjects . click ( 'rulesTab' ) ; await testSubjects . existOrFail ( 'alertsList' ) ; } , async assertTabsExist ( tabTypeSubject , areaSubjects ) { await retry . tryForTime ( 10000 , async ( ) => { const allTabs = await testSubjects . findAll ( `~${ tabTypeSubject }` , 3 ) ; expect ( allTabs ) . to . have . length ( areaSubjects . length , `Expected number of '${ tabTypeSubject }' to be '${ areaSubjects . length }' (got '${ allTabs . length }')` ) ; for ( const areaSubj of areaSubjects ) { await testSubjects . existOrFail ( `~${ tabTypeSubject }&~${ areaSubj }` , { timeout : 1000 } ) ; } } ) ; } , async navigateToArea ( linkSubject , pageSubject ) { await testSubjects . click ( linkSubject ) ; await retry . tryForTime ( 60 * 1000 , async ( ) => { await testSubjects . existOrFail ( `${ linkSubject } & ~selected` ) ; await testSubjects . existOrFail ( pageSubject ) ; } ) ; } , async assertMainTabsExist ( ) { await this . assertTabsExist ( 'mlMainTab' , [ 'anomalyDetection' , 'dataFrames' , 'dataFrameAnalytics' , 'dataVisualizer' , ] ) ; } , async assertTabEnabled ( tabSubject , expectedValue ) { const isEnabled = await testSubjects . isEnabled ( tabSubject ) ; expect ( isEnabled ) . to . eql ( expectedValue , `Expected ML tab '${ tabSubject }' to be '${ expectedValue ? 'enabled' : 'disabled' }' (got '${ isEnabled ? 'enabled' : 'disabled' }')` ) ; } , async assertOverviewTabEnabled ( expectedValue ) { await this . assertTabEnabled ( '~mlMainTab & ~overview' , expectedValue ) ; } , async assertAnomalyDetectionTabEnabled ( expectedValue ) { await this . assertTabEnabled ( '~mlMainTab & ~anomalyDetection' , expectedValue ) ; } , async assertDataFrameAnalyticsTabEnabled ( expectedValue ) { await this . assertTabEnabled ( '~mlMainTab & ~dataFrameAnalytics' , expectedValue ) ; } , async assertDataVisualizerTabEnabled ( expectedValue ) { await this . assertTabEnabled ( '~mlMainTab & ~dataVisualizer' , expectedValue ) ; } , async assertSettingsTabEnabled ( expectedValue ) { await this . assertTabEnabled ( '~mlMainTab & ~settings' , expectedValue ) ; } , async navigateToOverview ( ) { await this . navigateToArea ( '~mlMainTab & ~overview' , 'mlPageOverview' ) ; } , async navigateToAnomalyDetection ( ) { await this . navigateToArea ( '~mlMainTab & ~anomalyDetection' , 'mlPageJobManagement' ) ; } , async navigateToDataFrameAnalytics ( ) { await this . navigateToArea ( '~mlMainTab & ~dataFrameAnalytics' , 'mlPageDataFrameAnalytics' ) ; } , async navigateToModelManagement ( ) { await this . navigateToArea ( '~mlMainTab & ~modelManagement' , 'mlPageModelManagement' ) ; } , async navigateToTrainedModels ( ) { await this . navigateToMl ( ) ; await this . navigateToModelManagement ( ) ; await testSubjects . click ( 'mlTrainedModelsTab' ) ; await testSubjects . existOrFail ( 'mlModelsTableContainer' ) ; } , async navigateToModelManagementNodeList ( ) { await this . navigateToMl ( ) ; await this . navigateToModelManagement ( ) ; await testSubjects . click ( 'mlNodesOverviewTab' ) ; await testSubjects . existOrFail ( 'mlNodesTableContainer' ) ; } , async navigateToDataVisualizer ( ) { await this . navigateToArea ( '~mlMainTab & ~dataVisualizer' , 'mlPageDataVisualizerSelector' ) ; } , async navigateToJobManagement ( ) { await this . navigateToAnomalyDetection ( ) ; } , async navigateToSettings ( ) { await this . navigateToArea ( '~mlMainTab & ~settings' , 'mlPageSettings' ) ; } , async navigateToStackManagementJobsListPage ( ) { await testSubjects . click ( 'jobsListLink' ) ; await retry . tryForTime ( 60 * 1000 , async ( ) => { await testSubjects . existOrFail ( 'mlPageStackManagementJobsList' ) ; await testSubjects . existOrFail ( 'ml-jobs-list' ) ; } ) ; } , async navigateToStackManagementInsuficientLicensePage ( ) { await testSubjects . click ( 'jobsListLink' ) ; await retry . tryForTime ( 60 * 1000 , async ( ) => { await testSubjects . existOrFail ( 'mlPageInsufficientLicense' ) ; } ) ; } , async navigateToStackManagementJobsListPageAnomalyDetectionTab ( ) { await testSubjects . click ( 'mlStackManagementJobsListAnomalyDetectionTab' ) ; await retry . tryForTime ( 60 * 1000 , async ( ) => { await testSubjects . existOrFail ( 'ml-jobs-list' ) ; } ) ; } , async navigateToStackManagementJobsListPageAnalyticsTab ( ) { await testSubjects . click ( 'mlStackManagementJobsListAnalyticsTab' ) ; await retry . tryForTime ( 60 * 1000 , async ( ) => { await testSubjects . existOrFail ( 'mlAnalyticsJobList' ) ; } ) ; } , async navigateToAnomalyExplorerViaSingleMetricViewer ( ) { await testSubjects . click ( 'mlAnomalyResultsViewSelectorExplorer' ) ; await retry . tryForTime ( 60 * 1000 , async ( ) => { await testSubjects . existOrFail ( 'mlPageAnomalyExplorer' ) ; } ) ; } , async navigateToSingleMetricViewerViaAnomalyExplorer ( ) { await testSubjects . click ( 'mlAnomalyResultsViewSelectorSingleMetricViewer' ) ; await retry . tryForTime ( 60 * 1000 , async ( ) => { await testSubjects . existOrFail ( 'mlPageSingleMetricViewer' ) ; } ) ; } , async openKibanaNav ( ) { if ( ! ( await testSubjects . exists ( 'collapsibleNav' ) ) ) { await testSubjects . click ( 'toggleNavButton' ) ; } await testSubjects . existOrFail ( 'collapsibleNav' ) ; } , async closeKibanaNav ( ) { if ( await testSubjects . exists ( 'collapsibleNav' ) ) { await testSubjects . click ( 'toggleNavButton' ) ; } await testSubjects . missingOrFail ( 'collapsibleNav' ) ; } , async assertKibanaNavMLEntryExists ( ) { const navArea = await testSubjects . find ( 'collapsibleNav' ) ; const mlNavLink = await navArea . findAllByCssSelector ( '[title="Machine Learning"]' ) ; if ( mlNavLink . length === 0 ) { throw new Error ( `expected ML link in nav menu to exist` ) ; } } , async assertKibanaNavMLEntryNotExists ( ) { const navArea = await testSubjects . find ( 'collapsibleNav' ) ; const mlNavLink = await navArea . findAllByCssSelector ( '[title="Machine Learning"]' ) ; if ( mlNavLink . length !== 0 ) { throw new Error ( `expected ML link in nav menu to not exist` ) ; } } , async navigateToKibanaHome ( ) { await retry . tryForTime ( 60 * 1000 , async ( ) => { await PageObjects . common . navigateToApp ( 'home' ) ; await testSubjects . existOrFail ( 'homeApp' , { timeout : 2000 } ) ; } ) ; } , param expectedUrlPart async assertCurrentURLContains ( expectedUrlPart ) { const currentUrl = await browser . getCurrentUrl ( ) ; expect ( currentUrl ) . to . include . string ( expectedUrlPart , `Expected the current URL "${ currentUrl }" to include ${ expectedUrlPart }` ) ; } , async assertCurrentURLNotContain ( expectedUrlPart ) { const currentUrl = await browser . getCurrentUrl ( ) ; expect ( currentUrl ) . to . not . include . string ( expectedUrlPart , `Expected the current URL "${ currentUrl }" to not include ${ expectedUrlPart }` ) ; } , } ; }