Aggregations.test.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React from 'react';
  2. import renderer from 'react-test-renderer';
  3. import { Aggregations, Props } from './Aggregations';
  4. import { shallow } from 'enzyme';
  5. import { ValueTypes, MetricKind } from '../constants';
  6. import { TemplateSrvStub } from 'test/specs/helpers';
  7. const props: Props = {
  8. onChange: () => {},
  9. // @ts-ignore
  10. templateSrv: new TemplateSrvStub(),
  11. metricDescriptor: {
  12. valueType: '',
  13. metricKind: '',
  14. },
  15. crossSeriesReducer: '',
  16. groupBys: [],
  17. children: renderProps => <div />,
  18. };
  19. describe('Aggregations', () => {
  20. let wrapper: any;
  21. it('renders correctly', () => {
  22. const tree = renderer.create(<Aggregations {...props} />).toJSON();
  23. expect(tree).toMatchSnapshot();
  24. });
  25. describe('options', () => {
  26. describe('when DOUBLE and DELTA is passed as props', () => {
  27. beforeEach(() => {
  28. const newProps = { ...props, metricDescriptor: { valueType: ValueTypes.DOUBLE, metricKind: MetricKind.GAUGE } };
  29. wrapper = shallow(<Aggregations {...newProps} />);
  30. });
  31. it('', () => {
  32. const options = wrapper.state().aggOptions[0].options;
  33. expect(options.length).toEqual(11);
  34. expect(options.map((o: any) => o.value)).toEqual(
  35. expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  36. );
  37. });
  38. });
  39. describe('when MONEY and CUMULATIVE is passed as props', () => {
  40. beforeEach(() => {
  41. const newProps = {
  42. ...props,
  43. metricDescriptor: { valueType: ValueTypes.MONEY, metricKind: MetricKind.CUMULATIVE },
  44. };
  45. wrapper = shallow(<Aggregations {...newProps} />);
  46. });
  47. it('', () => {
  48. const options = wrapper.state().aggOptions[0].options;
  49. expect(options.length).toEqual(10);
  50. expect(options.map((o: any) => o.value)).toEqual(expect.arrayContaining(['REDUCE_NONE']));
  51. });
  52. });
  53. });
  54. });