query_aggregation_ctrl.test.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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', () => {
  7. beforeEach(async () => {
  8. ctrl = new StackdriverAggregationCtrl({
  9. $on: () => {},
  10. target: { valueType: 'DOUBLE', metricKind: 'GAUGE', aggregation: { crossSeriesReducer: '' } },
  11. });
  12. });
  13. it('should populate all aggregate options except two', () => {
  14. ctrl.setAggOptions();
  15. expect(ctrl.$scope.aggOptions.length).toBe(11);
  16. expect(ctrl.$scope.aggOptions.map(o => o.value)).toEqual(
  17. expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  18. );
  19. });
  20. it('should populate all alignment options except two', () => {
  21. ctrl.setAlignOptions();
  22. expect(ctrl.$scope.alignOptions.length).toBe(10);
  23. expect(ctrl.$scope.alignOptions.map(o => o.value)).toEqual(
  24. expect.not.arrayContaining(['REDUCE_COUNT_TRUE', 'REDUCE_COUNT_FALSE'])
  25. );
  26. });
  27. });
  28. });
  29. describe('when a user selects ALIGN_NONE and a reducer is selected', () => {
  30. beforeEach(async () => {
  31. ctrl = new StackdriverAggregationCtrl({
  32. $on: () => {},
  33. refresh: () => {},
  34. target: { aggregation: { crossSeriesReducer: 'RANDOM_REDUCER' } },
  35. });
  36. ctrl.onAlignmentChange('ALIGN_NONE');
  37. });
  38. it('should set REDUCE_NONE as selected aggregation', () => {
  39. expect(ctrl.$scope.target.aggregation.crossSeriesReducer).toBe('REDUCE_NONE');
  40. });
  41. });
  42. describe('when a user a user select a reducer and no alignment is selected', () => {
  43. beforeEach(async () => {
  44. ctrl = new StackdriverAggregationCtrl({
  45. $on: () => {},
  46. refresh: () => {},
  47. target: { aggregation: { crossSeriesReducer: 'REDUCE_NONE', perSeriesAligner: 'ALIGN_NONE' } },
  48. });
  49. ctrl.onAggregationChange('ALIGN_NONE');
  50. });
  51. it('should set an alignment', () => {
  52. expect(ctrl.$scope.target.aggregation.perSeriesAligner).not.toBe('ALIGN_NONE');
  53. });
  54. });
  55. });
  56. });