query_aggregation_ctrl.test.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { StackdriverAggregationCtrl } from '../query_aggregation_ctrl';
  2. describe('StackdriverAggregationCtrl', () => {
  3. let ctrl;
  4. describe('aggregation and alignment options', () => {
  5. beforeEach(() => {
  6. ctrl = createCtrlWithFakes();
  7. });
  8. describe('when new query result is returned from the server', () => {
  9. describe('and result is double and gauge', () => {
  10. beforeEach(async () => {
  11. ctrl.target.valueType = 'DOUBLE';
  12. ctrl.target.metricKind = 'GAUGE';
  13. });
  14. it('should populate all aggregate options except two', () => {
  15. const result = ctrl.getAggOptions();
  16. expect(result.length).toBe(11);
  17. expect(result.map(o => o.value)).toEqual(
  18. expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  19. );
  20. });
  21. it('should populate all alignment options except two', () => {
  22. const result = ctrl.getAlignOptions();
  23. expect(result.length).toBe(10);
  24. expect(result.map(o => o.value)).toEqual(
  25. expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  26. );
  27. });
  28. });
  29. });
  30. describe('when a user a user select ALIGN_NONE and a reducer is selected', () => {
  31. beforeEach(async () => {
  32. ctrl.target.aggregation.crossSeriesReducer = 'RANDOM_REDUCER';
  33. ctrl.onAlignmentChange('ALIGN_NONE');
  34. });
  35. it('should set REDUCE_NONE as selected aggregation', () => {
  36. expect(ctrl.target.aggregation.crossSeriesReducer).toBe('REDUCE_NONE');
  37. });
  38. });
  39. describe('when a user a user select a reducer and no alignment is selected', () => {
  40. beforeEach(async () => {
  41. ctrl.target.aggregation.crossSeriesReducer = 'REDUCE_NONE';
  42. ctrl.target.aggregation.perSeriesAligner = 'ALIGN_NONE';
  43. ctrl.onAggregationChange('ALIGN_NONE');
  44. });
  45. it('should set an alignment', () => {
  46. expect(ctrl.target.aggregation.perSeriesAligner).not.toBe('ALIGN_NONE');
  47. });
  48. });
  49. });
  50. });
  51. function createCtrlWithFakes() {
  52. StackdriverAggregationCtrl.prototype.target = createTarget();
  53. return new StackdriverAggregationCtrl({ refresh: () => {} });
  54. }
  55. function createTarget(existingFilters?: string[]) {
  56. return {
  57. project: {
  58. id: '',
  59. name: '',
  60. },
  61. metricType: 'ametric',
  62. refId: 'A',
  63. aggregation: {
  64. crossSeriesReducer: '',
  65. alignmentPeriod: '',
  66. perSeriesAligner: '',
  67. groupBys: [],
  68. },
  69. filters: existingFilters || [],
  70. aliasBy: '',
  71. };
  72. }