query_aggregation_ctrl.test.ts 4.4 KB

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