2018-11-08 22:16:11 +08:00
|
|
|
import React from 'react';
|
2019-06-27 21:56:02 +08:00
|
|
|
// @ts-ignore
|
2018-11-08 22:16:11 +08:00
|
|
|
import renderer from 'react-test-renderer';
|
2018-11-13 17:57:10 +08:00
|
|
|
import { StackdriverVariableQueryEditor } from './VariableQueryEditor';
|
|
|
|
import { VariableQueryProps } from 'app/types/plugins';
|
2018-11-09 17:52:55 +08:00
|
|
|
import { MetricFindQueryTypes } from '../types';
|
2018-11-08 22:16:11 +08:00
|
|
|
|
2018-11-09 17:20:45 +08:00
|
|
|
jest.mock('../functions', () => ({
|
2019-06-27 21:56:02 +08:00
|
|
|
getMetricTypes: (): any => ({ metricTypes: [], selectedMetricType: '' }),
|
|
|
|
extractServicesFromMetricDescriptors: (): any[] => [],
|
2018-11-09 17:20:45 +08:00
|
|
|
}));
|
|
|
|
|
2018-11-13 17:57:10 +08:00
|
|
|
const props: VariableQueryProps = {
|
2018-11-09 17:20:45 +08:00
|
|
|
onChange: (query, definition) => {},
|
2018-11-09 17:52:55 +08:00
|
|
|
query: {},
|
2018-11-09 17:20:45 +08:00
|
|
|
datasource: {
|
2020-03-02 22:31:09 +08:00
|
|
|
getDefaultProject: () => '',
|
|
|
|
getProjects: async (): Promise<any[]> => [],
|
2019-06-27 21:56:02 +08:00
|
|
|
getMetricTypes: async (p: any): Promise<any[]> => [],
|
2018-11-09 17:20:45 +08:00
|
|
|
},
|
2019-06-27 21:56:02 +08:00
|
|
|
templateSrv: { replace: (s: string) => s, variables: [] },
|
2018-11-09 17:20:45 +08:00
|
|
|
};
|
2018-11-08 22:16:11 +08:00
|
|
|
|
2018-11-13 17:57:10 +08:00
|
|
|
describe('VariableQueryEditor', () => {
|
2018-11-08 22:16:11 +08:00
|
|
|
it('renders correctly', () => {
|
2018-11-13 17:57:10 +08:00
|
|
|
const tree = renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
|
2018-11-08 22:16:11 +08:00
|
|
|
expect(tree).toMatchSnapshot();
|
|
|
|
});
|
2018-11-09 17:20:45 +08:00
|
|
|
|
2018-11-09 17:52:55 +08:00
|
|
|
describe('and a new variable is created', () => {
|
|
|
|
it('should trigger a query using the first query type in the array', done => {
|
|
|
|
props.onChange = (query, definition) => {
|
2020-03-02 22:31:09 +08:00
|
|
|
expect(definition).toBe('Stackdriver - Projects');
|
2018-11-09 17:52:55 +08:00
|
|
|
done();
|
|
|
|
};
|
2018-11-13 17:57:10 +08:00
|
|
|
renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
|
2018-11-09 17:52:55 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and an existing variable is edited', () => {
|
|
|
|
it('should trigger new query using the saved query type', done => {
|
2018-11-19 18:34:40 +08:00
|
|
|
props.query = { selectedQueryType: MetricFindQueryTypes.LabelKeys };
|
2018-11-09 17:52:55 +08:00
|
|
|
props.onChange = (query, definition) => {
|
2018-11-19 21:51:52 +08:00
|
|
|
expect(definition).toBe('Stackdriver - Label Keys');
|
2018-11-09 17:52:55 +08:00
|
|
|
done();
|
|
|
|
};
|
2018-11-13 17:57:10 +08:00
|
|
|
renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
|
2018-11-09 17:52:55 +08:00
|
|
|
});
|
2018-11-09 17:20:45 +08:00
|
|
|
});
|
2018-11-08 22:16:11 +08:00
|
|
|
});
|