From 0280179d357195bf04770f6f691aa3b206698f72 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 9 Nov 2018 10:20:45 +0100 Subject: [PATCH] stackdriver: add tests for render snapshop and default query type --- .../TemplateQueryComponent.test.tsx | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.test.tsx b/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.test.tsx index acbff44bd4a..05519c2e17d 100644 --- a/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.test.tsx +++ b/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.test.tsx @@ -3,15 +3,30 @@ import renderer from 'react-test-renderer'; import { StackdriverTemplateQueryComponent } from './TemplateQueryComponent'; import { TemplateQueryProps } from 'app/types/plugins'; -describe('StackdriverTemplateQueryComponent', () => { - const props: TemplateQueryProps = { - onChange: (query, definition) => {}, - query: '', - datasource: {}, - }; +jest.mock('../functions', () => ({ + getMetricTypes: () => Promise.resolve({ metricTypes: [], selectedMetricType: '' }), + extractServicesFromMetricDescriptors: m => m, +})); +const props: TemplateQueryProps = { + onChange: (query, definition) => {}, + query: '', + datasource: { + getMetricTypes: async p => [], + }, +}; + +describe('StackdriverTemplateQueryComponent', () => { it('renders correctly', () => { const tree = renderer.create().toJSON(); expect(tree).toMatchSnapshot(); }); + + it('should use the first query type in the array if no query type was saved before', done => { + props.onChange = (query, definition) => { + expect(definition).toBe('Stackdriver - Services'); + done(); + }; + renderer.create().toJSON(); + }); });