query_aggregation_ctrl.test.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. {
  10. $on: () => {},
  11. target: {
  12. valueType: 'DOUBLE',
  13. metricKind: 'GAUGE',
  14. aggregation: { crossSeriesReducer: '', groupBys: [] },
  15. },
  16. },
  17. {
  18. replace: s => s,
  19. variables: [{ name: 'someVariable1' }, { name: 'someVariable2' }],
  20. }
  21. );
  22. });
  23. it('should populate all aggregate options except two', () => {
  24. ctrl.setAggOptions();
  25. const [aggOptionsGroup] = ctrl.aggOptions;
  26. expect(aggOptionsGroup.options.length).toBe(11);
  27. expect(aggOptionsGroup.options.map(o => o.value)).toEqual(
  28. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  29. );
  30. });
  31. it('should populate all alignment options except two', () => {
  32. ctrl.setAlignOptions();
  33. const [aggOptionsGroup] = ctrl.aggOptions;
  34. expect(aggOptionsGroup.options.length).toBe(11);
  35. expect(aggOptionsGroup.options.map(o => o.value)).toEqual(
  36. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  37. );
  38. });
  39. });
  40. describe('and result is double and delta and no group by is used', () => {
  41. beforeEach(async () => {
  42. ctrl = new StackdriverAggregationCtrl(
  43. {
  44. $on: () => {},
  45. target: {
  46. valueType: 'DOUBLE',
  47. metricKind: 'DELTA',
  48. aggregation: { crossSeriesReducer: '', groupBys: [] },
  49. },
  50. },
  51. {
  52. replace: s => s,
  53. variables: [{ name: 'someVariable1' }, { name: 'someVariable2' }],
  54. }
  55. );
  56. });
  57. it('should populate all alignment options except four', () => {
  58. ctrl.setAlignOptions();
  59. const [alignOptionsGroup] = ctrl.alignOptions;
  60. expect(alignOptionsGroup.options.length).toBe(9);
  61. expect(alignOptionsGroup.options.map(o => o.value)).toEqual(
  62. expect['not'].arrayContaining([
  63. 'ALIGN_NEXT_OLDER',
  64. 'ALIGN_INTERPOLATE',
  65. 'ALIGN_COUNT_TRUE',
  66. 'ALIGN_COUNT_FALSE',
  67. 'ALIGN_FRACTION_TRUE',
  68. ])
  69. );
  70. });
  71. });
  72. describe('and result is double and gauge and a group by is used', () => {
  73. beforeEach(async () => {
  74. ctrl = new StackdriverAggregationCtrl(
  75. {
  76. $on: () => {},
  77. target: {
  78. valueType: 'DOUBLE',
  79. metricKind: 'GAUGE',
  80. aggregation: { crossSeriesReducer: 'REDUCE_NONE', groupBys: ['resource.label.projectid'] },
  81. },
  82. },
  83. {
  84. replace: s => s,
  85. variables: [{ name: 'someVariable1' }],
  86. }
  87. );
  88. });
  89. it('should populate all aggregate options except three', () => {
  90. ctrl.setAggOptions();
  91. const [aggOptionsGroup] = ctrl.aggOptions;
  92. expect(aggOptionsGroup.options.length).toBe(10);
  93. expect(aggOptionsGroup.options.map(o => o.value)).toEqual(
  94. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE', 'REDUCE_NONE'])
  95. );
  96. });
  97. it('should select some other reducer than REDUCE_NONE', () => {
  98. ctrl.setAggOptions();
  99. expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('');
  100. expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('REDUCE_NONE');
  101. });
  102. });
  103. });
  104. });
  105. });