query_def_specs.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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('getPipelineAggOptions', function() {
  8. describe('with zero targets', function() {
  9. var response = QueryDef.getPipelineAggOptions([]);
  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.getPipelineAggOptions(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.getPipelineAggOptions(targets);
  34. it('should return one', function() {
  35. expect(response.length).to.be(1);
  36. });
  37. });
  38. describe('with derivatives targets', function() {
  39. var targets = {
  40. metrics: [
  41. { type: 'derivative', field: '@value' }
  42. ]
  43. };
  44. var response = QueryDef.getPipelineAggOptions(targets);
  45. it('should return zero', function() {
  46. expect(response.length).to.be(0);
  47. });
  48. });
  49. });
  50. describe('isPipelineMetric', function() {
  51. describe('moving_avg', function() {
  52. var result = QueryDef.isPipelineAgg('moving_avg');
  53. it('is pipe line metric', function() {
  54. expect(result).to.be(true);
  55. });
  56. });
  57. describe('count', function() {
  58. var result = QueryDef.isPipelineAgg('count');
  59. it('is not pipe line metric', function() {
  60. expect(result).to.be(false);
  61. });
  62. });
  63. });
  64. describe('pipeline aggs depending on esverison', function() {
  65. describe('using esversion undefined', function() {
  66. it('should not get pipeline aggs', function() {
  67. expect(QueryDef.getMetricAggTypes(undefined).length).to.be(9);
  68. });
  69. });
  70. describe('using esversion 1', function() {
  71. it('should not get pipeline aggs', function() {
  72. expect(QueryDef.getMetricAggTypes(1).length).to.be(9);
  73. });
  74. });
  75. describe('using esversion 2', function() {
  76. it('should get pipeline aggs', function() {
  77. expect(QueryDef.getMetricAggTypes(2).length).to.be(11);
  78. });
  79. });
  80. });
  81. });