query_def_specs.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ///<amd-dependency path="../query_def" name="QueryDef" />
  2. ///<amd-dependency path="test/specs/helpers" name="helpers" />
  3. import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
  4. declare var helpers: any;
  5. declare var QueryDef: any;
  6. describe('ElasticQueryDef', function() {
  7. describe('getMovingAverageOptions', function() {
  8. describe('with zero targets', function() {
  9. var response = QueryDef.getMovingAverageOptions([]);
  10. it('should return zero', function() {
  11. expect(response.length).to.be(0);
  12. });
  13. });
  14. describe('with count and sum targets', function() {
  15. var targets = {
  16. metrics: [
  17. { type: 'count', field: '@value' },
  18. { type: 'sum', field: '@value' }
  19. ]
  20. };
  21. var response = QueryDef.getMovingAverageOptions(targets);
  22. it('should return zero', function() {
  23. expect(response.length).to.be(2);
  24. });
  25. });
  26. describe('with count and moving average targets', function() {
  27. var targets = {
  28. metrics: [
  29. { type: 'count', field: '@value' },
  30. { type: 'moving_avg', field: '@value' }
  31. ]
  32. };
  33. var response = QueryDef.getMovingAverageOptions(targets);
  34. it('should return zero', function() {
  35. expect(response.length).to.be(1);
  36. });
  37. });
  38. });
  39. describe('isPipelineMetric', function() {
  40. describe('moving_avg', function() {
  41. var result = QueryDef.isPipelineAgg({ type: 'moving_avg' });
  42. it('is pipe line metric', function() {
  43. expect(result).to.be(true);
  44. });
  45. });
  46. describe('count', function() {
  47. var result = QueryDef.isPipelineAgg({ type: 'count' });
  48. it('is not pipe line metric', function() {
  49. expect(result).to.be(false);
  50. });
  51. });
  52. });
  53. });