grafana/public/app/features/explore/Explore.test.tsx

192 lines
4.8 KiB
TypeScript
Raw Normal View History

import React from 'react';
import {
DataSourceApi,
LoadingState,
ExploreMode,
toUtc,
DataQueryError,
DataQueryRequest,
CoreApp,
MutableDataFrame,
} from '@grafana/data';
import { getFirstNonQueryRowSpecificError } from 'app/core/utils/explore';
import { ExploreId } from 'app/types/explore';
import { shallow } from 'enzyme';
import AutoSizer from 'react-virtualized-auto-sizer';
import { Explore, ExploreProps } from './Explore';
import { scanStopAction } from './state/actionTypes';
import { toggleGraph } from './state/actions';
import { SecondaryActions } from './SecondaryActions';
Tracing: Adds header and minimap (#23315) * Add integration with Jeager Add Jaeger datasource and modify derived fields in loki to allow for opening a trace in Jager in separate split. Modifies build so that this branch docker images are pushed to docker hub Add a traceui dir with docker-compose and provision files for demoing.:wq * Enable docker logger plugin to send logs to loki * Add placeholder zipkin datasource * Fixed rebase issues, added enhanceDataFrame to non-legacy code path * Trace selector for jaeger query field * Fix logs default mode for Loki * Fix loading jaeger query field services on split * Updated grafana image in traceui/compose file * Fix prettier error * Hide behind feature flag, clean up unused code. * Fix tests * Fix tests * Cleanup code and review feedback * Remove traceui directory * Remove circle build changes * Fix feature toggles object * Fix merge issues * Add trace ui in Explore * WIP * WIP * WIP * Make jaeger datasource return trace data instead of link * Allow js in jest tests * Return data from Jaeger datasource * Take yarn.lock from master * Fix missing component * Update yarn lock * Fix some ts and lint errors * Fix merge * Fix type errors * Make tests pass again * Add tests * Fix es5 compatibility * Add header with minimap * Fix sizing issue due to column resizer handle * Fix issues with sizing, search functionality, duplicate react, tests * Refactor TraceView component, fix tests * Fix type errors * Add tests for hooks Co-authored-by: David Kaltschmidt <david.kaltschmidt@gmail.com>
2020-04-08 10:16:22 -05:00
import { TraceView } from './TraceView/TraceView';
import { getTheme } from '@grafana/ui';
const dummyProps: ExploreProps = {
changeSize: jest.fn(),
datasourceInstance: {
meta: {
metrics: true,
logs: true,
},
components: {
ExploreStartPage: {},
},
} as DataSourceApi,
datasourceMissing: false,
exploreId: ExploreId.left,
initializeExplore: jest.fn(),
initialized: true,
modifyQueries: jest.fn(),
update: {
datasource: false,
queries: false,
range: false,
mode: false,
ui: false,
},
refreshExplore: jest.fn(),
scanning: false,
scanRange: {
from: '0',
to: '0',
},
scanStart: jest.fn(),
scanStopAction: scanStopAction,
setQueries: jest.fn(),
split: false,
queryKeys: [],
initialDatasource: 'test',
initialQueries: [],
initialRange: {
from: toUtc('2019-01-01 10:00:00'),
to: toUtc('2019-01-01 16:00:00'),
raw: {
from: 'now-6h',
to: 'now',
},
},
mode: ExploreMode.Metrics,
initialUI: {
showingTable: false,
showingGraph: false,
showingLogs: false,
},
isLive: false,
syncedTimes: false,
updateTimeRange: jest.fn(),
graphResult: [],
loading: false,
absoluteRange: {
from: 0,
to: 0,
},
showingGraph: false,
showingTable: false,
timeZone: 'UTC',
onHiddenSeriesChanged: jest.fn(),
toggleGraph: toggleGraph,
queryResponse: {
state: LoadingState.NotStarted,
series: [],
request: ({
requestId: '1',
dashboardId: 0,
interval: '1s',
panelId: 1,
scopedVars: {
apps: {
value: 'value',
},
},
targets: [
{
refId: 'A',
},
],
timezone: 'UTC',
app: CoreApp.Explore,
startTime: 0,
} as unknown) as DataQueryRequest,
error: {} as DataQueryError,
timeRange: {
from: toUtc('2019-01-01 10:00:00'),
to: toUtc('2019-01-01 16:00:00'),
raw: {
from: 'now-6h',
to: 'now',
},
},
},
originPanelId: 1,
addQueryRow: jest.fn(),
theme: getTheme(),
};
const setupErrors = (hasRefId?: boolean) => {
return [
{
message: 'Error message',
status: '400',
statusText: 'Bad Request',
refId: hasRefId ? 'A' : '',
},
];
};
describe('Explore', () => {
it('should render component', () => {
const wrapper = shallow(<Explore {...dummyProps} />);
expect(wrapper).toMatchSnapshot();
});
it('renders SecondaryActions and add row button', () => {
const wrapper = shallow(<Explore {...dummyProps} />);
expect(wrapper.find(SecondaryActions)).toHaveLength(1);
expect(wrapper.find(SecondaryActions).props().addQueryRowButtonHidden).toBe(false);
});
it('does not show add row button if mode is tracing', () => {
const wrapper = shallow(<Explore {...{ ...dummyProps, mode: ExploreMode.Tracing }} />);
expect(wrapper.find(SecondaryActions).props().addQueryRowButtonHidden).toBe(true);
});
it('renders TraceView if tracing mode', () => {
const wrapper = shallow(
<Explore
{...{
...dummyProps,
mode: ExploreMode.Tracing,
queryResponse: {
...dummyProps.queryResponse,
state: LoadingState.Done,
series: [new MutableDataFrame({ fields: [{ name: 'trace', values: [{}] }] })],
},
}}
/>
);
const autoSizer = shallow(
wrapper
.find(AutoSizer)
.props()
.children({ width: 100, height: 100 }) as React.ReactElement
);
expect(autoSizer.find(TraceView).length).toBe(1);
});
it('should filter out a query-row-specific error when looking for non-query-row-specific errors', async () => {
const queryErrors = setupErrors(true);
const queryError = getFirstNonQueryRowSpecificError(queryErrors);
expect(queryError).toBeUndefined();
});
it('should not filter out a generic error when looking for non-query-row-specific errors', async () => {
const queryErrors = setupErrors();
const queryError = getFirstNonQueryRowSpecificError(queryErrors);
expect(queryError).toEqual({
message: 'Error message',
status: '400',
statusText: 'Bad Request',
refId: '',
});
});
});