query_aggregation_ctrl.test.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  20. );
  21. });
  22. it('should populate all aggregate options except two', () => {
  23. ctrl.setAggOptions();
  24. expect(ctrl.aggOptions.length).toBe(11);
  25. expect(ctrl.aggOptions.map(o => o.value)).toEqual(
  26. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  27. );
  28. });
  29. it('should populate all alignment options except two', () => {
  30. ctrl.setAlignOptions();
  31. expect(ctrl.alignOptions.length).toBe(9);
  32. expect(ctrl.alignOptions.map(o => o.value)).toEqual(
  33. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  34. );
  35. });
  36. });
  37. describe('and result is double and gauge and a group by is used', () => {
  38. beforeEach(async () => {
  39. ctrl = new StackdriverAggregationCtrl(
  40. {
  41. $on: () => {},
  42. target: {
  43. valueType: 'DOUBLE',
  44. metricKind: 'GAUGE',
  45. aggregation: { crossSeriesReducer: 'REDUCE_NONE', groupBys: ['resource.label.projectid'] },
  46. },
  47. },
  48. {
  49. replace: s => s,
  50. }
  51. );
  52. });
  53. it('should populate all aggregate options except three', () => {
  54. ctrl.setAggOptions();
  55. expect(ctrl.aggOptions.length).toBe(10);
  56. expect(ctrl.aggOptions.map(o => o.value)).toEqual(
  57. expect['not'].arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE', 'REDUCE_NONE'])
  58. );
  59. });
  60. it('should select some other reducer than REDUCE_NONE', () => {
  61. ctrl.setAggOptions();
  62. expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('');
  63. expect(ctrl.target.aggregation.crossSeriesReducer).not.toBe('REDUCE_NONE');
  64. });
  65. });
  66. });
  67. });
  68. });