query_aggregation_ctrl.test.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. console.log(result.map(o => o.value));
  24. expect(result.length).toBe(10);
  25. expect(result.map(o => o.value)).toEqual(
  26. expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  27. );
  28. });
  29. });
  30. });
  31. describe('when a user a user select ALIGN_NONE and a reducer is selected', () => {
  32. beforeEach(async () => {
  33. ctrl.target.aggregation.crossSeriesReducer = 'RANDOM_REDUCER';
  34. ctrl.onAlignmentChange('ALIGN_NONE');
  35. });
  36. it('should set REDUCE_NONE as selected aggregation', () => {
  37. expect(ctrl.target.aggregation.crossSeriesReducer).toBe('REDUCE_NONE');
  38. });
  39. });
  40. describe('when a user a user select a reducer and no alignment is selected', () => {
  41. beforeEach(async () => {
  42. ctrl.target.aggregation.crossSeriesReducer = 'REDUCE_NONE';
  43. ctrl.target.aggregation.perSeriesAligner = 'ALIGN_NONE';
  44. ctrl.onAggregationChange('ALIGN_NONE');
  45. });
  46. it('should set an alignment', () => {
  47. expect(ctrl.target.aggregation.perSeriesAligner).not.toBe('ALIGN_NONE');
  48. });
  49. });
  50. });
  51. });
  52. function createCtrlWithFakes() {
  53. StackdriverAggregationCtrl.prototype.target = createTarget();
  54. return new StackdriverAggregationCtrl({ refresh: () => {} });
  55. }
  56. function createTarget(existingFilters?: string[]) {
  57. return {
  58. project: {
  59. id: '',
  60. name: '',
  61. },
  62. metricType: 'ametric',
  63. refId: 'A',
  64. aggregation: {
  65. crossSeriesReducer: '',
  66. alignmentPeriod: '',
  67. perSeriesAligner: '',
  68. groupBys: [],
  69. },
  70. filters: existingFilters || [],
  71. aliasBy: '',
  72. };
  73. }