2018-11-08 22:16:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import React from 'react';
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-27 21:56:02 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// @ts-ignore
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-08 22:16:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import renderer from 'react-test-renderer';
							 | 
						
					
						
							
								
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { VariableModel } from '@grafana/data';
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-08 22:16:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import CloudMonitoringDatasource from '../datasource';
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-23 00:19:54 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { MetricFindQueryTypes } from '../types/query';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { CloudMonitoringVariableQuery } from '../types/types';
							 | 
						
					
						
							
								
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { CloudMonitoringVariableQueryEditor, Props } from './VariableQueryEditor';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:20:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								jest.mock('../functions', () => ({
							 | 
						
					
						
							
								
									
										
										
										
											2023-02-23 18:07:44 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  getMetricTypes: () => ({ metricTypes: [], selectedMetricType: '' }),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  extractServicesFromMetricDescriptors: () => [],
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:20:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								jest.mock('@grafana/runtime', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  const original = jest.requireActual('@grafana/runtime');
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-03 15:38:14 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  return {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ...original,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    getTemplateSrv: () => ({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      replace: (s: string) => s,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-02 20:02:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      getVariables: () => [] as unknown as VariableModel[],
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-03 15:38:14 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const props: Props = {
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-20 14:59:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  onChange: (query) => {},
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-02 20:02:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  query: {} as unknown as CloudMonitoringVariableQuery,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  datasource: {
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-02 22:31:09 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    getDefaultProject: () => '',
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-27 19:01:16 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    getProjects: async () => Promise.resolve([]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    getMetricTypes: async (projectName: string) => Promise.resolve([]),
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    getSLOServices: async (projectName: string) => Promise.resolve([]),
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-27 19:01:16 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    getServiceLevelObjectives: (projectName: string, serviceId: string) => Promise.resolve([]),
							 | 
						
					
						
							
								
									
										
										
										
											2022-08-12 21:54:19 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ensureGCEDefaultProject: async () => Promise.resolve(''),
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-02 20:02:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  } as unknown as CloudMonitoringDatasource,
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  onRunQuery: () => {},
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:20:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-08 22:16:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-13 17:57:10 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								describe('VariableQueryEditor', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-08 22:16:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  it('renders correctly', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-30 23:47:13 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const tree = renderer.create(<CloudMonitoringVariableQueryEditor {...props} />).toJSON();
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-08 22:16:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    expect(tree).toMatchSnapshot();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:20:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:52:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  describe('and a new variable is created', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-20 14:59:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it('should trigger a query using the first query type in the array', (done) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      props.onChange = (query) => {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(query.selectedQueryType).toBe('projects');
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:52:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      };
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-30 23:47:13 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      renderer.create(<CloudMonitoringVariableQueryEditor {...props} />).toJSON();
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:52:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  describe('and an existing variable is edited', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-20 14:59:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    it('should trigger new query using the saved query type', (done) => {
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-02 20:02:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      props.query = { selectedQueryType: MetricFindQueryTypes.LabelKeys } as unknown as CloudMonitoringVariableQuery;
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-20 14:59:48 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      props.onChange = (query) => {
							 | 
						
					
						
							
								
									
										
										
										
											2020-11-18 22:10:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(query.selectedQueryType).toBe('labelKeys');
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:52:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      };
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-30 23:47:13 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      renderer.create(<CloudMonitoringVariableQueryEditor {...props} />).toJSON();
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:52:55 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-09 17:20:45 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-08 22:16:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 |