mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00

* Rewrite angular segments for filter and group by in react * wip: refactoring * Update metric find queries * Remove old maps used to create labels - use one map for all types instead * Use value as label (again) for filters ang groupby * Remove old filter * Remove not used code * Fixes after pr feedback * Fix broken tests and add new metadata tests * Add index file to make imports cleaner * Cleanup. Remove old angular filter code * Fix broken tests * Use type switching instead of if statements * Use globals for regex * Updates after pr feedback * Make sure it's possible to filter using the same key multiple times * Replace metric select with segment component * Pass template vars as props * Refactor meta labels code * Reorder template variables * Fix broken tests * Reset metric value when changing service * Fix lint issue. * Make tests independant of element order * Include kubernetes.io in regex * Add instruction in help section
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import React from 'react';
|
|
import renderer from 'react-test-renderer';
|
|
import { Aggregations, Props } from './Aggregations';
|
|
import { shallow } from 'enzyme';
|
|
import { ValueTypes, MetricKind } from '../constants';
|
|
import { TemplateSrvStub } from 'test/specs/helpers';
|
|
|
|
const props: Props = {
|
|
onChange: () => {},
|
|
// @ts-ignore
|
|
templateSrv: new TemplateSrvStub(),
|
|
metricDescriptor: {
|
|
valueType: '',
|
|
metricKind: '',
|
|
},
|
|
crossSeriesReducer: '',
|
|
groupBys: [],
|
|
children: renderProps => <div />,
|
|
templateVariableOptions: [],
|
|
};
|
|
|
|
describe('Aggregations', () => {
|
|
let wrapper: any;
|
|
it('renders correctly', () => {
|
|
const tree = renderer.create(<Aggregations {...props} />).toJSON();
|
|
expect(tree).toMatchSnapshot();
|
|
});
|
|
|
|
describe('options', () => {
|
|
describe('when DOUBLE and DELTA is passed as props', () => {
|
|
beforeEach(() => {
|
|
const newProps = { ...props, metricDescriptor: { valueType: ValueTypes.DOUBLE, metricKind: MetricKind.GAUGE } };
|
|
wrapper = shallow(<Aggregations {...newProps} />);
|
|
});
|
|
it('', () => {
|
|
const options = wrapper.state().aggOptions;
|
|
expect(options.length).toEqual(11);
|
|
expect(options.map((o: any) => o.value)).toEqual(
|
|
expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('when MONEY and CUMULATIVE is passed as props', () => {
|
|
beforeEach(() => {
|
|
const newProps = {
|
|
...props,
|
|
metricDescriptor: { valueType: ValueTypes.MONEY, metricKind: MetricKind.CUMULATIVE },
|
|
};
|
|
wrapper = shallow(<Aggregations {...newProps} />);
|
|
});
|
|
it('', () => {
|
|
const options = wrapper.state().aggOptions;
|
|
expect(options.length).toEqual(10);
|
|
expect(options.map((o: any) => o.value)).toEqual(expect.arrayContaining(['REDUCE_NONE']));
|
|
});
|
|
});
|
|
});
|
|
});
|