diff --git a/public/app/plugins/datasource/stackdriver/components/Filter.tsx b/public/app/plugins/datasource/stackdriver/components/Filter.tsx index 67a1ff6c38a..11fda73248d 100644 --- a/public/app/plugins/datasource/stackdriver/components/Filter.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Filter.tsx @@ -52,11 +52,13 @@ export class Filter extends React.Component { hideGroupBys, }; scopeProps.loading = this.loadLabels(scopeProps); - this.component = loader.load(this.element, scopeProps, template); } componentDidUpdate(prevProps: Props) { + if (!this.element) { + return; + } const scope = this.component.getScope(); if (prevProps.metricType !== this.props.metricType) { scope.loading = this.loadLabels(scope); diff --git a/public/app/plugins/datasource/stackdriver/components/QueryEditor.test.tsx b/public/app/plugins/datasource/stackdriver/components/QueryEditor.test.tsx new file mode 100644 index 00000000000..30cfa9fbfd5 --- /dev/null +++ b/public/app/plugins/datasource/stackdriver/components/QueryEditor.test.tsx @@ -0,0 +1,18 @@ +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().toJSON(); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx index c25134b4e70..d639cd821f5 100644 --- a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx @@ -26,7 +26,7 @@ interface State extends Target { [key: string]: any; } -const DefaultTarget: State = { +export const DefaultTarget: State = { defaultProject: 'loading project...', metricType: '', metricKind: '', diff --git a/public/app/plugins/datasource/stackdriver/components/__snapshots__/QueryEditor.test.tsx.snap b/public/app/plugins/datasource/stackdriver/components/__snapshots__/QueryEditor.test.tsx.snap new file mode 100644 index 00000000000..161f35563e5 --- /dev/null +++ b/public/app/plugins/datasource/stackdriver/components/__snapshots__/QueryEditor.test.tsx.snap @@ -0,0 +1,455 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`QueryEditor renders correctly 1`] = ` +Array [ +
+
+ + Service + +
+
+
+
+ Select Services +
+ +
+
+ +
+
+
+
+
+
+
+
, +
+
+ + Metric + +
+
+
+
+ Select Metric +
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+
, +
, +
+
+ +
+
+
+
+ Select Aggregation +
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+ +
, +
+
+ + +
+
+
+
+
, +
+
+ +
+
+
+
+
+ stackdriver auto +
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
, +
+
+ + Project + + +
+
+ +
+ +
+
+
+
, + "", + "", +] +`; diff --git a/public/app/plugins/datasource/stackdriver/functions.test.ts b/public/app/plugins/datasource/stackdriver/functions.test.ts new file mode 100644 index 00000000000..ffc421734fc --- /dev/null +++ b/public/app/plugins/datasource/stackdriver/functions.test.ts @@ -0,0 +1,38 @@ +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', + ]) + ); + }); + }); + }); +});