2021-07-12 08:30:24 -05:00
|
|
|
import React, { ComponentProps } from 'react';
|
|
|
|
import { QueryRow } from './QueryRow';
|
2020-05-13 08:56:22 -05:00
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { ExploreId } from 'app/types/explore';
|
2021-02-11 06:45:25 -06:00
|
|
|
import { DataSourceApi, TimeRange, AbsoluteTimeRange, PanelData, EventBusExtended } from '@grafana/data';
|
2020-05-13 08:56:22 -05:00
|
|
|
|
|
|
|
const setup = (propOverrides?: object) => {
|
2021-07-12 08:30:24 -05:00
|
|
|
const props: ComponentProps<typeof QueryRow> = {
|
2020-05-13 08:56:22 -05:00
|
|
|
exploreId: ExploreId.left,
|
|
|
|
index: 1,
|
2020-11-03 06:08:54 -06:00
|
|
|
exploreEvents: {} as EventBusExtended,
|
2020-05-13 08:56:22 -05:00
|
|
|
changeQuery: jest.fn(),
|
|
|
|
datasourceInstance: {} as DataSourceApi,
|
|
|
|
highlightLogsExpressionAction: jest.fn() as any,
|
|
|
|
history: [],
|
|
|
|
query: {
|
|
|
|
refId: 'A',
|
|
|
|
},
|
|
|
|
modifyQueries: jest.fn(),
|
|
|
|
range: {} as TimeRange,
|
|
|
|
absoluteRange: {} as AbsoluteTimeRange,
|
|
|
|
removeQueryRowAction: jest.fn() as any,
|
|
|
|
runQueries: jest.fn(),
|
|
|
|
queryResponse: {} as PanelData,
|
|
|
|
latency: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
|
|
const wrapper = shallow(<QueryRow {...props} />);
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
const QueryEditor = () => <div />;
|
|
|
|
|
|
|
|
describe('QueryRow', () => {
|
|
|
|
describe('if datasource does not have Explore query fields ', () => {
|
|
|
|
it('it should render QueryEditor if datasource has it', () => {
|
|
|
|
const wrapper = setup({ datasourceInstance: { components: { QueryEditor } } });
|
|
|
|
expect(wrapper.find(QueryEditor)).toHaveLength(1);
|
|
|
|
});
|
|
|
|
it('it should not render QueryEditor if datasource does not have it', () => {
|
|
|
|
const wrapper = setup({ datasourceInstance: { components: {} } });
|
|
|
|
expect(wrapper.find(QueryEditor)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|