2021-03-24 13:01:23 -05:00
import React , { ComponentProps } from 'react' ;
2022-02-15 05:33:10 -06:00
import { DataFrame , FieldType } from '@grafana/data' ;
2021-03-24 13:01:23 -05:00
import { render , screen } from '@testing-library/react' ;
import userEvent from '@testing-library/user-event' ;
import { InspectDataTab } from './InspectDataTab' ;
2022-02-15 05:33:10 -06:00
// the mock below gets rid of this warning from recompose:
// Warning: React.createFactory() is deprecated and will be removed in a future major release. Consider using JSX or use React.createElement() directly instead.
jest . mock ( '@jaegertracing/jaeger-ui-components' , ( ) = > ( { } ) ) ;
2021-03-24 13:01:23 -05:00
const createProps = ( propsOverride? : Partial < ComponentProps < typeof InspectDataTab > > ) = > {
const defaultProps = {
isLoading : false ,
options : {
withTransforms : false ,
withFieldConfig : false ,
} ,
data : [
{
name : 'First data frame' ,
fields : [
{ name : 'time' , type : FieldType . time , values : [ 100 , 200 , 300 ] } ,
{ name : 'name' , type : FieldType . string , values : [ 'uniqueA' , 'b' , 'c' ] } ,
{ name : 'value' , type : FieldType . number , values : [ 1 , 2 , 3 ] } ,
] ,
length : 3 ,
} ,
{
name : 'Second data frame' ,
fields : [
{ name : 'time' , type : FieldType . time , values : [ 400 , 500 , 600 ] } ,
{ name : 'name' , type : FieldType . string , values : [ 'd' , 'e' , 'g' ] } ,
{ name : 'value' , type : FieldType . number , values : [ 4 , 5 , 6 ] } ,
] ,
length : 3 ,
} ,
] ,
} ;
return Object . assign ( defaultProps , propsOverride ) as ComponentProps < typeof InspectDataTab > ;
} ;
describe ( 'InspectDataTab' , ( ) = > {
describe ( 'when panel is not passed as prop (Explore)' , ( ) = > {
it ( 'should render InspectDataTab' , ( ) = > {
render ( < InspectDataTab { ...createProps ( ) } / > ) ;
expect ( screen . getByLabelText ( /Panel inspector Data content/i ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should render Data Option row' , ( ) = > {
render ( < InspectDataTab { ...createProps ( ) } / > ) ;
expect ( screen . getByText ( /Data options/i ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should show available options' , ( ) = > {
render ( < InspectDataTab { ...createProps ( ) } / > ) ;
const dataOptions = screen . getByText ( /Data options/i ) ;
userEvent . click ( dataOptions ) ;
expect ( screen . getByText ( /Show data frame/i ) ) . toBeInTheDocument ( ) ;
expect ( screen . getByText ( /Download for Excel/i ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should show available dataFrame options' , ( ) = > {
render ( < InspectDataTab { ...createProps ( ) } / > ) ;
const dataOptions = screen . getByText ( /Data options/i ) ;
userEvent . click ( dataOptions ) ;
2021-11-23 06:11:26 -06:00
const dataFrameInput = screen . getByRole ( 'combobox' , { name : /Select dataframe/i } ) ;
2021-03-24 13:01:23 -05:00
userEvent . click ( dataFrameInput ) ;
expect ( screen . getByText ( /Second data frame/i ) ) . toBeInTheDocument ( ) ;
} ) ;
2021-04-12 11:21:05 -05:00
it ( 'should show download logs button if logs data' , ( ) = > {
2022-02-02 06:02:32 -06:00
const dataWithLogs = [
2021-04-12 11:21:05 -05:00
{
name : 'Data frame with logs' ,
fields : [
{ name : 'time' , type : FieldType . time , values : [ 100 , 200 , 300 ] } ,
{ name : 'name' , type : FieldType . string , values : [ 'uniqueA' , 'b' , 'c' ] } ,
{ name : 'value' , type : FieldType . number , values : [ 1 , 2 , 3 ] } ,
] ,
length : 3 ,
meta : {
preferredVisualisationType : 'logs' ,
} ,
} ,
2022-02-02 06:02:32 -06:00
] as unknown as DataFrame [ ] ;
2021-04-12 11:21:05 -05:00
render ( < InspectDataTab { ...createProps ( { data : dataWithLogs } ) } / > ) ;
expect ( screen . getByText ( /Download logs/i ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should not show download logs button if no logs data' , ( ) = > {
render ( < InspectDataTab { ...createProps ( ) } / > ) ;
expect ( screen . queryByText ( /Download logs/i ) ) . not . toBeInTheDocument ( ) ;
} ) ;
2021-09-08 08:04:27 -05:00
it ( 'should show download traces button if traces data' , ( ) = > {
2022-02-02 06:02:32 -06:00
const dataWithtraces = [
2021-09-08 08:04:27 -05:00
{
name : 'Data frame with traces' ,
fields : [
{ name : 'traceID' , values : [ '3fa414edcef6ad90' , '3fa414edcef6ad90' ] } ,
{ name : 'spanID' , values : [ '3fa414edcef6ad90' , '0f5c1808567e4403' ] } ,
{ name : 'parentSpanID' , values : [ undefined , '3fa414edcef6ad90' ] } ,
{ name : 'operationName' , values : [ 'HTTP GET - api_traces_traceid' , '/tempopb.Querier/FindTraceByID' ] } ,
{ name : 'serviceName' , values : [ 'tempo-querier' , 'tempo-querier' ] } ,
{
name : 'serviceTags' ,
values : [
[
{ key : 'cluster' , type : 'string' , value : 'ops-tools1' } ,
{ key : 'container' , type : 'string' , value : 'tempo-query' } ,
] ,
[
{ key : 'cluster' , type : 'string' , value : 'ops-tools1' } ,
{ key : 'container' , type : 'string' , value : 'tempo-query' } ,
] ,
] ,
} ,
{ name : 'startTime' , values : [ 1605873894680.409 , 1605873894680.587 ] } ,
{ name : 'duration' , values : [ 1049.141 , 1.847 ] } ,
{ name : 'logs' , values : [ [ ] , [ ] ] } ,
{
name : 'tags' ,
values : [
[
{ key : 'sampler.type' , type : 'string' , value : 'probabilistic' } ,
{ key : 'sampler.param' , type : 'float64' , value : 1 } ,
] ,
[
{ key : 'component' , type : 'string' , value : 'gRPC' } ,
{ key : 'span.kind' , type : 'string' , value : 'client' } ,
] ,
] ,
} ,
{ name : 'warnings' , values : [ undefined , undefined ] } ,
{ name : 'stackTraces' , values : [ undefined , undefined ] } ,
] ,
length : 2 ,
meta : {
preferredVisualisationType : 'trace' ,
custom : {
traceFormat : 'jaeger' ,
} ,
} ,
} ,
2022-02-02 06:02:32 -06:00
] as unknown as DataFrame [ ] ;
2021-09-08 08:04:27 -05:00
render ( < InspectDataTab { ...createProps ( { data : dataWithtraces } ) } / > ) ;
expect ( screen . getByText ( /Download traces/i ) ) . toBeInTheDocument ( ) ;
} ) ;
it ( 'should not show download traces button if no traces data' , ( ) = > {
render ( < InspectDataTab { ...createProps ( ) } / > ) ;
expect ( screen . queryByText ( /Download traces/i ) ) . not . toBeInTheDocument ( ) ;
} ) ;
2021-03-24 13:01:23 -05:00
} ) ;
} ) ;