import React from 'react' ; import { screen } from '@testing-library/react' ; import userEvent from '@testing-library/user-event' ; import { mockAppIndexPattern , mockIndexPattern , mockUxSeries , render } from '../rtl_helpers' ; import { getDefaultConfigs } from '../configurations/default_configs' ; import { PERCENTILE } from '../configurations/constants' ; import { ReportMetricOptions } from './report_metric_options' ; import { obsvReportConfigMap } from '../obsv_exploratory_view' ; describe ( 'ReportMetricOptions' , function ( ) { const dataViewSeries = getDefaultConfigs ( { dataType : 'ux' , reportType : 'kpi-over-time' , indexPattern : mockIndexPattern , reportConfigMap : obsvReportConfigMap , } ) ; it ( 'should render properly' , async function ( ) { render ( < ReportMetricOptions seriesId = { 0 } seriesConfig = { dataViewSeries } series = { mockUxSeries } / > ) ; expect ( await screen . findByText ( 'No data available' ) ) . toBeInTheDocument ( ) ; } ) ; it ( 'should display loading if index pattern is not available and is loading' , async function ( ) { mockAppIndexPattern ( { loading : true , indexPatterns : undefined } ) ; const { container } = render ( < ReportMetricOptions seriesId = { 0 } seriesConfig = { { ... dataViewSeries , hasOperationType : true } } series = { { ... mockUxSeries , breakdown : PERCENTILE } } / > ) ; expect ( container . getElementsByClassName ( 'euiLoadingSpinner' ) . length ) . toBe ( 1 ) ; } ) ; it ( 'should not display loading if index pattern is already loaded' , async function ( ) { mockAppIndexPattern ( { loading : true } ) ; render ( < ReportMetricOptions seriesId = { 0 } seriesConfig = { { ... dataViewSeries , hasOperationType : true } } series = { { ... mockUxSeries , breakdown : PERCENTILE } } />); expect ( await screen . findByText ( 'Page load time' ) ) . toBeInTheDocument ( ) ; } ) ; it ( 'should include a tooltip for the report metric' , async function ( ) { mockAppIndexPattern ( { loading : false } ) ; const { getByText , findByText } = render ( < ReportMetricOptions seriesId = { 0 } seriesConfig = { { ... dataViewSeries } } series = { { ... mockUxSeries } } />); userEvent . hover ( getByText ( 'Page load time' ) ) ; expect ( await findByText ( 'Report metric' ) ) . toBeInTheDocument ( ) ; } ) ; } ) ;