VariableQueryEditor.test.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. // @ts-ignore
  3. import renderer from 'react-test-renderer';
  4. import { StackdriverVariableQueryEditor } from './VariableQueryEditor';
  5. import { VariableQueryProps } from 'app/types/plugins';
  6. import { MetricFindQueryTypes } from '../types';
  7. jest.mock('../functions', () => ({
  8. getMetricTypes: (): any => ({ metricTypes: [], selectedMetricType: '' }),
  9. extractServicesFromMetricDescriptors: (): any[] => [],
  10. }));
  11. const props: VariableQueryProps = {
  12. onChange: (query, definition) => {},
  13. query: {},
  14. datasource: {
  15. getMetricTypes: async (p: any): Promise<any[]> => [],
  16. },
  17. templateSrv: { replace: (s: string) => s, variables: [] },
  18. };
  19. describe('VariableQueryEditor', () => {
  20. it('renders correctly', () => {
  21. const tree = renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
  22. expect(tree).toMatchSnapshot();
  23. });
  24. describe('and a new variable is created', () => {
  25. it('should trigger a query using the first query type in the array', done => {
  26. props.onChange = (query, definition) => {
  27. expect(definition).toBe('Stackdriver - Services');
  28. done();
  29. };
  30. renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
  31. });
  32. });
  33. describe('and an existing variable is edited', () => {
  34. it('should trigger new query using the saved query type', done => {
  35. props.query = { selectedQueryType: MetricFindQueryTypes.LabelKeys };
  36. props.onChange = (query, definition) => {
  37. expect(definition).toBe('Stackdriver - Label Keys');
  38. done();
  39. };
  40. renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
  41. });
  42. });
  43. });