query_aggregation_ctrl.test.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { StackdriverAggregationCtrl } from '../query_aggregation_ctrl';
  2. describe('StackdriverAggregationCtrl', () => {
  3. let ctrl;
  4. describe('aggregation and alignment options', () => {
  5. describe('when new query result is returned from the server', () => {
  6. describe('and result is double and gauge and no group by is used', () => {
  7. beforeEach(async () => {
  8. ctrl = new StackdriverAggregationCtrl({
  9. $on: () => {},
  10. target: { valueType: 'DOUBLE', metricKind: 'GAUGE', aggregation: { crossSeriesReducer: '', groupBys: [] } },
  11. });
  12. });
  13. it('should populate all aggregate options except two', () => {
  14. ctrl.setAggOptions();
  15. expect(ctrl.aggOptions.length).toBe(11);
  16. expect(ctrl.aggOptions.map(o => o.value)).toEqual(
  17. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  18. );
  19. });
  20. it('should populate all alignment options except two', () => {
  21. ctrl.setAlignOptions();
  22. expect(ctrl.alignOptions.length).toBe(9);
  23. expect(ctrl.alignOptions.map(o => o.value)).toEqual(
  24. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  25. );
  26. });
  27. });
  28. describe('and result is double and gauge and a group by is used', () => {
  29. beforeEach(async () => {
  30. ctrl = new StackdriverAggregationCtrl({
  31. $on: () => {},
  32. target: {
  33. valueType: 'DOUBLE',
  34. metricKind: 'GAUGE',
  35. aggregation: { crossSeriesReducer: 'REDUCE_NONE', groupBys: ['resource.label.projectid'] },
  36. },
  37. });
  38. });
  39. it('should populate all aggregate options except three', () => {
  40. ctrl.setAggOptions();
  41. expect(ctrl.aggOptions.length).toBe(10);
  42. expect(ctrl.aggOptions.map(o => o.value)).toEqual(
  43. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE', 'REDUCE_NONE'])
  44. );
  45. });
  46. it('should select some other reducer than REDUCE_NONE', () => {
  47. ctrl.setAggOptions();
  48. expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('');
  49. expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('REDUCE_NONE');
  50. });
  51. });
  52. });
  53. });
  54. });