grafana/public/app/plugins/datasource/stackdriver/components/VariableQueryEditor.test.tsx

51 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-11-08 22:16:11 +08:00
import React from 'react';
// @ts-ignore
2018-11-08 22:16:11 +08:00
import renderer from 'react-test-renderer';
import { StackdriverVariableQueryEditor } from './VariableQueryEditor';
import { VariableQueryProps } from 'app/types/plugins';
2018-11-09 17:52:55 +08:00
import { MetricFindQueryTypes } from '../types';
2018-11-08 22:16:11 +08:00
jest.mock('../functions', () => ({
getMetricTypes: (): any => ({ metricTypes: [], selectedMetricType: '' }),
extractServicesFromMetricDescriptors: (): any[] => [],
}));
const props: VariableQueryProps = {
onChange: (query, definition) => {},
2018-11-09 17:52:55 +08:00
query: {},
datasource: {
Stackdriver: Project selector (#22447) * clean PR #17366 * udpate vendor * [WIP] Implement projects management for stackdriver * [WIP] Implement projects management for stackdriver * [WIP] Implement projects management for stackdriver * Implement projects management for stackdriver * [WIP][Tests] Fix errors * clean anonymous struct * remove await * don't store project list * Add default project on query editor * gofmt * Fix tests * Move test data source to backend * Use segment instead of dropdown. remove ensure default project since it's not being used anymore. * Fix broken annotation editor * Load gceDefaultAccount only once when in the config page * Reset error message on auth type change * Add metric find query for projects * Remove debug code * Fix broken tests * Fix typings * Fix lint error * Slightly different approach - now having a distiction between config page default project, and project that is selectable from the dropdown in the query editor. * Fix broken tests * Attempt to fix strict ts errors * Prevent state from being set multiple times * Remove noOptionsMessage since it seems to be obosolete in react select * One more attempt to solve ts strict error * Interpolate project template variable. Make sure its loaded correctly when opening variable query editor first time * Implicit any fix * fix: typescript strict null check fixes * Return empty array in case project endpoint fails * Rename project to projectName to prevent clashing with legacy query prop * Fix broken test * fix: Stackdriver - template replace on filter label should have a regex format as that escapes the dots in the label name which is not valid. Co-authored-by: Labesse Kévin <kevin@labesse.me> Co-authored-by: Elias Cédric Laouiti <elias@abtasty.com> Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
2020-03-02 22:31:09 +08:00
getDefaultProject: () => '',
getProjects: async (): Promise<any[]> => [],
getMetricTypes: async (p: any): Promise<any[]> => [],
},
templateSrv: { replace: (s: string) => s, variables: [] },
};
2018-11-08 22:16:11 +08:00
describe('VariableQueryEditor', () => {
2018-11-08 22:16:11 +08:00
it('renders correctly', () => {
const tree = renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
2018-11-08 22:16:11 +08:00
expect(tree).toMatchSnapshot();
});
2018-11-09 17:52:55 +08:00
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) => {
Stackdriver: Project selector (#22447) * clean PR #17366 * udpate vendor * [WIP] Implement projects management for stackdriver * [WIP] Implement projects management for stackdriver * [WIP] Implement projects management for stackdriver * Implement projects management for stackdriver * [WIP][Tests] Fix errors * clean anonymous struct * remove await * don't store project list * Add default project on query editor * gofmt * Fix tests * Move test data source to backend * Use segment instead of dropdown. remove ensure default project since it's not being used anymore. * Fix broken annotation editor * Load gceDefaultAccount only once when in the config page * Reset error message on auth type change * Add metric find query for projects * Remove debug code * Fix broken tests * Fix typings * Fix lint error * Slightly different approach - now having a distiction between config page default project, and project that is selectable from the dropdown in the query editor. * Fix broken tests * Attempt to fix strict ts errors * Prevent state from being set multiple times * Remove noOptionsMessage since it seems to be obosolete in react select * One more attempt to solve ts strict error * Interpolate project template variable. Make sure its loaded correctly when opening variable query editor first time * Implicit any fix * fix: typescript strict null check fixes * Return empty array in case project endpoint fails * Rename project to projectName to prevent clashing with legacy query prop * Fix broken test * fix: Stackdriver - template replace on filter label should have a regex format as that escapes the dots in the label name which is not valid. Co-authored-by: Labesse Kévin <kevin@labesse.me> Co-authored-by: Elias Cédric Laouiti <elias@abtasty.com> Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
2020-03-02 22:31:09 +08:00
expect(definition).toBe('Stackdriver - Projects');
2018-11-09 17:52:55 +08:00
done();
};
renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
2018-11-09 17:52:55 +08:00
});
});
describe('and an existing variable is edited', () => {
it('should trigger new query using the saved query type', done => {
props.query = { selectedQueryType: MetricFindQueryTypes.LabelKeys };
2018-11-09 17:52:55 +08:00
props.onChange = (query, definition) => {
2018-11-19 21:51:52 +08:00
expect(definition).toBe('Stackdriver - Label Keys');
2018-11-09 17:52:55 +08:00
done();
};
renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
2018-11-09 17:52:55 +08:00
});
});
2018-11-08 22:16:11 +08:00
});