1import React from 'react';
2import {
3  DataSourceApi,
4  LoadingState,
5  toUtc,
6  DataQueryError,
7  DataQueryRequest,
8  CoreApp,
9  createTheme,
10} from '@grafana/data';
11import { ExploreId } from 'app/types/explore';
12import { shallow } from 'enzyme';
13import { Explore, Props } from './Explore';
14import { scanStopAction } from './state/query';
15import { SecondaryActions } from './SecondaryActions';
16
17const dummyProps: Props = {
18  logsResult: undefined,
19  changeSize: jest.fn(),
20  datasourceInstance: {
21    meta: {
22      metrics: true,
23      logs: true,
24    },
25    components: {
26      QueryEditorHelp: {},
27    },
28  } as DataSourceApi,
29  datasourceMissing: false,
30  exploreId: ExploreId.left,
31  loading: false,
32  modifyQueries: jest.fn(),
33  scanStart: jest.fn(),
34  scanStopAction: scanStopAction,
35  setQueries: jest.fn(),
36  queryKeys: [],
37  isLive: false,
38  syncedTimes: false,
39  updateTimeRange: jest.fn(),
40  graphResult: [],
41  absoluteRange: {
42    from: 0,
43    to: 0,
44  },
45  timeZone: 'UTC',
46  queryResponse: {
47    state: LoadingState.NotStarted,
48    series: [],
49    request: ({
50      requestId: '1',
51      dashboardId: 0,
52      interval: '1s',
53      panelId: 1,
54      scopedVars: {
55        apps: {
56          value: 'value',
57        },
58      },
59      targets: [
60        {
61          refId: 'A',
62        },
63      ],
64      timezone: 'UTC',
65      app: CoreApp.Explore,
66      startTime: 0,
67    } as unknown) as DataQueryRequest,
68    error: {} as DataQueryError,
69    timeRange: {
70      from: toUtc('2019-01-01 10:00:00'),
71      to: toUtc('2019-01-01 16:00:00'),
72      raw: {
73        from: 'now-6h',
74        to: 'now',
75      },
76    },
77  },
78  addQueryRow: jest.fn(),
79  theme: createTheme(),
80  showMetrics: true,
81  showLogs: true,
82  showTable: true,
83  showTrace: true,
84  showNodeGraph: true,
85  splitOpen: (() => {}) as any,
86  logsVolumeData: undefined,
87  loadLogsVolumeData: () => {},
88  changeGraphStyle: () => {},
89  graphStyle: 'lines',
90};
91
92describe('Explore', () => {
93  it('should render component', () => {
94    const wrapper = shallow(<Explore {...dummyProps} />);
95    expect(wrapper).toMatchSnapshot();
96  });
97
98  it('renders SecondaryActions and add row button', () => {
99    const wrapper = shallow(<Explore {...dummyProps} />);
100    expect(wrapper.find(SecondaryActions)).toHaveLength(1);
101    expect(wrapper.find(SecondaryActions).props().addQueryRowButtonHidden).toBe(false);
102  });
103});
104