Aggregations.test.tsx 1.7 KB

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