Files
grafana/public/app/plugins/datasource/loki/components/LokiQueryEditor.test.tsx
Ivana Huckova a54e0ff79d Loki: Add query type and line limit to query editor in dashboard (#29356)
* WIP Add line limit and query type switch toLoki dashboard editor

* Refactor, reuse code for both - Explore and Dashboard

* Üpdate snapshot tests

* Refactor and unify

* Rename test file

* Update test
2020-12-01 20:43:35 +01:00

63 lines
1.4 KiB
TypeScript

import React from 'react';
import { shallow } from 'enzyme';
import { toUtc } from '@grafana/data';
import { LokiQueryEditor } from './LokiQueryEditor';
import { LokiDatasource } from '../datasource';
import { LokiQuery } from '../types';
const createMockRequestRange = (from: string, to: string) => {
return {
from: toUtc(from, 'YYYY-MM-DD'),
to: toUtc(to, 'YYYY-MM-DD'),
};
};
const setup = (propOverrides?: object) => {
const datasourceMock: unknown = {};
const datasource: LokiDatasource = datasourceMock as LokiDatasource;
const onRunQuery = jest.fn();
const onChange = jest.fn();
const query: LokiQuery = {
expr: '',
refId: 'A',
legendFormat: 'My Legend',
};
const range = createMockRequestRange('2020-01-01', '2020-01-02');
const props: any = {
datasource,
onChange,
onRunQuery,
query,
range,
};
Object.assign(props, propOverrides);
const wrapper = shallow(<LokiQueryEditor {...props} />);
const instance = wrapper.instance();
return {
instance,
wrapper,
};
};
describe('Render LokiQueryEditor with legend', () => {
it('should render', () => {
const { wrapper } = setup();
expect(wrapper).toMatchSnapshot();
});
it('should update timerange', () => {
const { wrapper } = setup();
wrapper.setProps({
range: createMockRequestRange('2019-01-01', '2020-01-02'),
});
expect(wrapper).toMatchSnapshot();
});
});