mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: test saved variable
This commit is contained in:
parent
b262be73e0
commit
9c85793dbb
@ -2,14 +2,15 @@ import React from 'react';
|
|||||||
import renderer from 'react-test-renderer';
|
import renderer from 'react-test-renderer';
|
||||||
import { StackdriverTemplateQueryComponent } from './TemplateQueryComponent';
|
import { StackdriverTemplateQueryComponent } from './TemplateQueryComponent';
|
||||||
import { TemplateQueryProps } from 'app/types/plugins';
|
import { TemplateQueryProps } from 'app/types/plugins';
|
||||||
|
import { MetricFindQueryTypes } from '../types';
|
||||||
|
|
||||||
jest.mock('../functions', () => ({
|
jest.mock('../functions', () => ({
|
||||||
getMetricTypes: async () => ({ metricTypes: [], selectedMetricType: '' }),
|
getMetricTypes: () => ({ metricTypes: [], selectedMetricType: '' }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const props: TemplateQueryProps = {
|
const props: TemplateQueryProps = {
|
||||||
onChange: (query, definition) => {},
|
onChange: (query, definition) => {},
|
||||||
query: '',
|
query: {},
|
||||||
datasource: {
|
datasource: {
|
||||||
getMetricTypes: async p => [],
|
getMetricTypes: async p => [],
|
||||||
},
|
},
|
||||||
@ -21,7 +22,8 @@ describe('StackdriverTemplateQueryComponent', () => {
|
|||||||
expect(tree).toMatchSnapshot();
|
expect(tree).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use the first query type in the array if no query type was saved before', done => {
|
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) => {
|
props.onChange = (query, definition) => {
|
||||||
expect(definition).toBe('Stackdriver - Metric Types');
|
expect(definition).toBe('Stackdriver - Metric Types');
|
||||||
done();
|
done();
|
||||||
@ -29,3 +31,15 @@ describe('StackdriverTemplateQueryComponent', () => {
|
|||||||
renderer.create(<StackdriverTemplateQueryComponent {...props} />).toJSON();
|
renderer.create(<StackdriverTemplateQueryComponent {...props} />).toJSON();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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(<StackdriverTemplateQueryComponent {...props} />).toJSON();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -33,7 +33,9 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
|
|||||||
this.onServiceChange = this.onServiceChange.bind(this);
|
this.onServiceChange = this.onServiceChange.bind(this);
|
||||||
this.onMetricTypeChange = this.onMetricTypeChange.bind(this);
|
this.onMetricTypeChange = this.onMetricTypeChange.bind(this);
|
||||||
this.onLabelKeyChange = this.onLabelKeyChange.bind(this);
|
this.onLabelKeyChange = this.onLabelKeyChange.bind(this);
|
||||||
|
console.log(this.props.query);
|
||||||
this.state = Object.assign(this.defaults, this.props.query);
|
this.state = Object.assign(this.defaults, this.props.query);
|
||||||
|
console.log(Object.assign(this.defaults, this.props.query));
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
@ -63,6 +65,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
|
|||||||
metricDescriptors,
|
metricDescriptors,
|
||||||
...await this.getLabels(selectedMetricType),
|
...await this.getLabels(selectedMetricType),
|
||||||
};
|
};
|
||||||
|
console.log(state);
|
||||||
this.setState(state);
|
this.setState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user