Files
grafana/public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.test.tsx
Hugo Häggmark c7ffc1199c Variables: turns on newVariables as a new default (#23272)
* Variables: turns on newVariables as default

* Chore: adds default templating state

* Some small refactorings to get the template_srv tests to get green when toggle is enabled by default.

* Refactor: adds getVariables dependency to DashboardModel

* Tests: fixes StackDriver tests

* Tests: updates snapshots

* Tests: updates snapshot for DashboardGrid.test.tsx

* Tests: fixes DashboardModel.test.ts

* fixed initDashboard tests.

* renamed variable.

* changed so we use the templating.list when running the migration work.

* changed so we always returns the variables in sorted order.

* Tests: fixed cloudwatch tests

* added so we set the global template variable props.

* Fixed tests and added moved logic to complete templateSrv variables.

* removed unneccesary updateIndex.

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
2020-04-03 09:38:14 +02:00

69 lines
2.4 KiB
TypeScript

import React from 'react';
// @ts-ignore
import renderer from 'react-test-renderer';
import { StackdriverVariableQueryEditor } from './VariableQueryEditor';
import { VariableQueryProps } from 'app/types/plugins';
import { MetricFindQueryTypes } from '../types';
import { VariableModel } from 'app/features/templating/types';
jest.mock('../functions', () => ({
getMetricTypes: (): any => ({ metricTypes: [], selectedMetricType: '' }),
extractServicesFromMetricDescriptors: (): any[] => [],
}));
jest.mock('../../../../core/config', () => {
console.warn('[This test uses old variable system, needs a rewrite]');
const original = jest.requireActual('../../../../core/config');
const config = original.getConfig();
return {
getConfig: () => ({
...config,
featureToggles: {
...config.featureToggles,
newVariables: false,
},
}),
};
});
const props: VariableQueryProps = {
onChange: (query, definition) => {},
query: {},
datasource: {
getDefaultProject: () => '',
getProjects: async () => Promise.resolve([]),
getMetricTypes: async (projectName: string) => Promise.resolve([]),
getSLOServices: async (projectName: string, serviceId: string) => Promise.resolve([]),
getServiceLevelObjectives: (projectName: string, serviceId: string) => Promise.resolve([]),
},
templateSrv: { replace: (s: string) => s, getVariables: () => ([] as unknown) as VariableModel[] },
};
describe('VariableQueryEditor', () => {
it('renders correctly', () => {
const tree = renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
expect(tree).toMatchSnapshot();
});
describe('and a new variable is created', () => {
it('should trigger a query using the first query type in the array', done => {
props.onChange = (query, definition) => {
expect(definition).toBe('Stackdriver - Projects');
done();
};
renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
});
});
describe('and an existing variable is edited', () => {
it('should trigger new query using the saved query type', done => {
props.query = { selectedQueryType: MetricFindQueryTypes.LabelKeys };
props.onChange = (query, definition) => {
expect(definition).toBe('Stackdriver - Label Keys');
done();
};
renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
});
});
});