Aggregations.test.tsx 1.8 KB

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