Commit d23c3d2b by Erik Sundell

add tests

parent 3ce4287e
...@@ -52,11 +52,13 @@ export class Filter extends React.Component<Props, State> { ...@@ -52,11 +52,13 @@ export class Filter extends React.Component<Props, State> {
hideGroupBys, hideGroupBys,
}; };
scopeProps.loading = this.loadLabels(scopeProps); scopeProps.loading = this.loadLabels(scopeProps);
this.component = loader.load(this.element, scopeProps, template); this.component = loader.load(this.element, scopeProps, template);
} }
componentDidUpdate(prevProps: Props) { componentDidUpdate(prevProps: Props) {
if (!this.element) {
return;
}
const scope = this.component.getScope(); const scope = this.component.getScope();
if (prevProps.metricType !== this.props.metricType) { if (prevProps.metricType !== this.props.metricType) {
scope.loading = this.loadLabels(scope); scope.loading = this.loadLabels(scope);
......
import React from 'react';
import renderer from 'react-test-renderer';
import { QueryEditor, Props, DefaultTarget } from './QueryEditor';
const props: Props = {
onQueryChange: target => {},
onExecuteQuery: () => {},
target: DefaultTarget,
events: { on: () => {} },
datasource: { templateSrv: { variables: [] } },
};
describe('QueryEditor', () => {
it('renders correctly', () => {
const tree = renderer.create(<QueryEditor {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
});
...@@ -26,7 +26,7 @@ interface State extends Target { ...@@ -26,7 +26,7 @@ interface State extends Target {
[key: string]: any; [key: string]: any;
} }
const DefaultTarget: State = { export const DefaultTarget: State = {
defaultProject: 'loading project...', defaultProject: 'loading project...',
metricType: '', metricType: '',
metricKind: '', metricKind: '',
......
import { getAlignmentOptionsByMetric } from './functions';
import { ValueTypes, MetricKind } from './constants';
describe('functions', () => {
let result;
describe('getAlignmentOptionsByMetric', () => {
describe('when double and gauge is passed', () => {
beforeEach(() => {
result = getAlignmentOptionsByMetric(ValueTypes.DOUBLE, MetricKind.GAUGE);
});
it('should return all alignment options except two', () => {
expect(result.length).toBe(9);
expect(result.map(o => o.value)).toEqual(
expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
);
});
});
describe('when double and delta is passed', () => {
beforeEach(() => {
result = getAlignmentOptionsByMetric(ValueTypes.DOUBLE, MetricKind.DELTA);
});
it('should return all alignment options except four', () => {
expect(result.length).toBe(9);
expect(result.map(o => o.value)).toEqual(
expect.not.arrayContaining([
'ALIGN_COUNT_TRUE',
'ALIGN_COUNT_FALSE',
'ALIGN_FRACTION_TRUE',
'ALIGN_INTERPOLATE',
])
);
});
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment