query_aggregation_ctrl.test.ts 4.4 KB

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