grafana/public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.test.tsx

46 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-11-08 22:16:11 +08:00
import React from 'react';
import renderer from 'react-test-renderer';
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
jest.mock('../functions', () => ({
2018-11-09 17:52:55 +08:00
getMetricTypes: () => ({ metricTypes: [], selectedMetricType: '' }),
}));
const props: VariableQueryProps = {
onChange: (query, definition) => {},
2018-11-09 17:52:55 +08:00
query: {},
datasource: {
getMetricTypes: async p => [],
},
};
2018-11-08 22:16:11 +08:00
describe('VariableQueryEditor', () => {
2018-11-08 22:16:11 +08:00
it('renders correctly', () => {
const tree = renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
2018-11-08 22:16:11 +08:00
expect(tree).toMatchSnapshot();
});
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) => {
expect(definition).toBe('Stackdriver - Metric Types');
done();
};
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 => {
props.query = { selectedQueryType: MetricFindQueryTypes.MetricLabels };
props.onChange = (query, definition) => {
expect(definition).toBe('Stackdriver - Metric Labels');
done();
};
renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
2018-11-09 17:52:55 +08:00
});
});
2018-11-08 22:16:11 +08:00
});