import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../../ftr_provider_context' ; const DRILLDOWN_TO_PIE_CHART_NAME = 'Go to pie chart dashboard' ; const DRILLDOWN_TO_AREA_CHART_NAME = 'Go to area chart dashboard' ; export default function ( { getService , getPageObjects } ) { const testSubjects = getService ( 'testSubjects' ) ; const dashboardPanelActions = getService ( 'dashboardPanelActions' ) ; const dashboardDrilldownPanelActions = getService ( 'dashboardDrilldownPanelActions' ) ; const dashboardDrilldownsManage = getService ( 'dashboardDrilldownsManage' ) ; const PageObjects = getPageObjects ( [ 'dashboard' , 'common' , 'header' , 'timePicker' , 'settings' , 'copySavedObjectsToSpace' , ] ) ; const queryBar = getService ( 'queryBar' ) ; const pieChart = getService ( 'pieChart' ) ; const log = getService ( 'log' ) ; const browser = getService ( 'browser' ) ; const retry = getService ( 'retry' ) ; const filterBar = getService ( 'filterBar' ) ; const security = getService ( 'security' ) ; const spaces = getService ( 'spaces' ) ; const elasticChart = getService ( 'elasticChart' ) ; describe ( 'Dashboard to dashboard drilldown' , function ( ) { describe ( 'Create & use drilldowns' , ( ) => { before ( async ( ) => { log . debug ( 'Dashboard Drilldowns:initTests' ) ; await security . testUser . setRoles ( [ 'test_logstash_reader' , 'global_dashboard_all' ] ) ; await PageObjects . common . navigateToApp ( 'dashboard' ) ; await PageObjects . dashboard . preserveCrossAppState ( ) ; } ) ; after ( async ( ) => { await security . testUser . restoreDefaults ( ) ; } ) ; it ( 'should create dashboard to dashboard drilldown, use it, and then delete it' , async ( ) => { await PageObjects . dashboard . gotoDashboardEditMode ( dashboardDrilldownsManage . DASHBOARD_WITH_PIE_CHART_NAME ) ; await dashboardPanelActions . openContextMenu ( ) ; await dashboardDrilldownPanelActions . expectExistsCreateDrilldownAction ( ) ; await dashboardDrilldownPanelActions . clickCreateDrilldown ( ) ; await dashboardDrilldownsManage . expectsCreateDrilldownFlyoutOpen ( ) ; await testSubjects . click ( 'actionFactoryItem-DASHBOARD_TO_DASHBOARD_DRILLDOWN' ) ; await dashboardDrilldownsManage . fillInDashboardToDashboardDrilldownWizard ( { drilldownName : DRILLDOWN_TO_AREA_CHART_NAME , destinationDashboardTitle : dashboardDrilldownsManage . DASHBOARD_WITH_AREA_CHART_NAME , } ) ; await dashboardDrilldownsManage . saveChanges ( ) ; await dashboardDrilldownsManage . closeFlyout ( ) ; expect ( await PageObjects . dashboard . getPanelDrilldownCount ( ) ) . to . be ( 1 ) ; await PageObjects . dashboard . saveDashboard ( dashboardDrilldownsManage . DASHBOARD_WITH_PIE_CHART_NAME , { saveAsNew : false , waitDialogIsClosed : true , exitFromEditMode : true , } ) ; await pieChart . clickOnPieSlice ( '40,000' ) ; await dashboardDrilldownPanelActions . expectMultipleActionsMenuOpened ( ) ; const href = await dashboardDrilldownPanelActions . getActionHrefByText ( DRILLDOWN_TO_AREA_CHART_NAME ) ; expect ( typeof href ) . to . be ( 'string' ) ; const dashboardIdFromHref = PageObjects . dashboard . getDashboardIdFromUrl ( href ) ; await navigateWithinDashboard ( async ( ) => { await dashboardDrilldownPanelActions . clickActionByText ( DRILLDOWN_TO_AREA_CHART_NAME ) ; } ) ; expect ( dashboardIdFromHref ) . to . be ( await PageObjects . dashboard . getDashboardIdFromCurrentUrl ( ) ) ; expect ( await filterBar . getFilterCount ( ) ) . to . be ( 1 ) ; const originalTimeRangeDurationHours = await PageObjects . timePicker . getTimeDurationInHours ( ) ; await brushAreaChart ( ) ; await dashboardDrilldownPanelActions . expectMultipleActionsMenuOpened ( ) ; await navigateWithinDashboard ( async ( ) => { await dashboardDrilldownPanelActions . clickActionByText ( DRILLDOWN_TO_PIE_CHART_NAME ) ; } ) ; expect ( await filterBar . getFilterCount ( ) ) . to . be ( 1 ) ; await pieChart . expectPieSliceCount ( 1 ) ; const newTimeRangeDurationHours = await PageObjects . timePicker . getTimeDurationInHours ( ) ; expect ( newTimeRangeDurationHours ) . to . be . lessThan ( originalTimeRangeDurationHours ) ; await PageObjects . dashboard . switchToEditMode ( ) ; await dashboardPanelActions . openContextMenu ( ) ; await dashboardDrilldownPanelActions . expectExistsManageDrilldownsAction ( ) ; await dashboardDrilldownPanelActions . clickManageDrilldowns ( ) ; await dashboardDrilldownsManage . expectsManageDrilldownsFlyoutOpen ( ) ; await dashboardDrilldownsManage . deleteDrilldownsByTitles ( [ DRILLDOWN_TO_AREA_CHART_NAME ] ) ; await dashboardDrilldownsManage . closeFlyout ( ) ; expect ( await PageObjects . dashboard . getPanelDrilldownCount ( ) ) . to . be ( 0 ) ; } ) ; it ( 'browser back/forward navigation works after drilldown navigation' , async ( ) => { await PageObjects . dashboard . loadSavedDashboard ( dashboardDrilldownsManage . DASHBOARD_WITH_AREA_CHART_NAME ) ; const originalTimeRangeDurationHours = await PageObjects . timePicker . getTimeDurationInHours ( ) ; await brushAreaChart ( ) ; await dashboardDrilldownPanelActions . expectMultipleActionsMenuOpened ( ) ; await navigateWithinDashboard ( async ( ) => { await dashboardDrilldownPanelActions . clickActionByText ( DRILLDOWN_TO_PIE_CHART_NAME ) ; } ) ; const newTimeRangeDurationHours = await PageObjects . timePicker . getTimeDurationInHours ( ) ; expect ( newTimeRangeDurationHours ) . to . be . lessThan ( originalTimeRangeDurationHours ) ; await navigateWithinDashboard ( async ( ) => { await browser . goBack ( ) ; } ) ; expect ( await PageObjects . timePicker . getTimeDurationInHours ( ) ) . to . be ( originalTimeRangeDurationHours ) ; } ) ; } ) ; describe ( 'Copy to space' , ( ) => { const destinationSpaceId = 'custom_space' ; before ( async ( ) => { await spaces . create ( { id : destinationSpaceId , name : 'custom_space' , disabledFeatures : [ ] , } ) ; await PageObjects . settings . navigateTo ( ) ; await PageObjects . settings . clickKibanaSavedObjects ( ) ; } ) ; after ( async ( ) => { await spaces . delete ( destinationSpaceId ) ; } ) ; it ( 'Dashboards linked by a drilldown are both copied to a space' , async ( ) => { await PageObjects . copySavedObjectsToSpace . openCopyToSpaceFlyoutForObject ( dashboardDrilldownsManage . DASHBOARD_WITH_AREA_CHART_NAME ) ; await PageObjects . copySavedObjectsToSpace . setupForm ( { destinationSpaceId , } ) ; await PageObjects . copySavedObjectsToSpace . startCopy ( ) ; await testSubjects . waitForDeleted ( `cts-summary-indicator-loading-${ destinationSpaceId }` ) ; await testSubjects . existOrFail ( `cts-summary-indicator-success-${ destinationSpaceId }` ) ; const summaryCounts = await PageObjects . copySavedObjectsToSpace . getSummaryCounts ( ) ; expect ( summaryCounts ) . to . eql ( { success : 5 , pending : 0 , skipped : 0 , errors : 0 , } ) ; await PageObjects . copySavedObjectsToSpace . finishCopy ( ) ; await PageObjects . common . navigateToApp ( 'dashboard' , { basePath : `/s/${ destinationSpaceId }` , } ) ; await PageObjects . dashboard . preserveCrossAppState ( ) ; await PageObjects . dashboard . loadSavedDashboard ( dashboardDrilldownsManage . DASHBOARD_WITH_AREA_CHART_NAME ) ; await PageObjects . header . waitUntilLoadingHasFinished ( ) ; await PageObjects . dashboard . waitForRenderComplete ( ) ; await brushAreaChart ( ) ; await dashboardDrilldownPanelActions . expectMultipleActionsMenuOpened ( ) ; await navigateWithinDashboard ( async ( ) => { await dashboardDrilldownPanelActions . clickActionByText ( DRILLDOWN_TO_PIE_CHART_NAME ) ; } ) ; await elasticChart . setNewChartUiDebugFlag ( ) ; await queryBar . submitQuery ( ) ; await pieChart . expectPieSliceCountEsCharts ( 10 ) ; } ) ; } ) ; } ) ; async function brushAreaChart ( ) { const areaChart = await testSubjects . find ( 'visualizationLoader' ) ; expect ( await areaChart . getAttribute ( 'data-title' ) ) . to . be ( 'Visualization漢字 AreaChart' ) ; await browser . dragAndDrop ( { location : areaChart , offset : { x : - 100 , y : 0 , } , } , { location : areaChart , offset : { x : 100 , y : 0 , } , } ) ; } async function navigateWithinDashboard ( navigationTrigger ) { const oldDashboardId = await PageObjects . dashboard . getDashboardIdFromCurrentUrl ( ) ; await navigationTrigger ( ) ; await retry . waitFor ( 'navigate to different dashboard' , async ( ) => { const newDashboardId = await PageObjects . dashboard . getDashboardIdFromCurrentUrl ( ) ; return typeof newDashboardId === 'string' && oldDashboardId !== newDashboardId ; } ) ; await PageObjects . header . waitUntilLoadingHasFinished ( ) ; await PageObjects . dashboard . waitForRenderComplete ( ) ; } }