elasticsearch-queryctrl-specs.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. define([
  2. 'helpers',
  3. 'plugins/datasource/elasticsearch/queryCtrl',
  4. 'services/uiSegmentSrv'
  5. ], function(helpers) {
  6. 'use strict';
  7. describe('ElasticQueryCtrl', function() {
  8. var ctx = new helpers.ControllerTestContext();
  9. beforeEach(module('grafana.controllers'));
  10. beforeEach(module('grafana.services'));
  11. beforeEach(ctx.providePhase());
  12. beforeEach(ctx.createControllerPhase('ElasticQueryCtrl'));
  13. beforeEach(function() {
  14. ctx.scope.target = {};
  15. ctx.scope.$parent = { get_data: sinon.spy() };
  16. ctx.scope.datasource = ctx.datasource;
  17. ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
  18. });
  19. describe('init', function() {
  20. beforeEach(function() {
  21. ctx.scope.init();
  22. });
  23. it('should init selectSegments', function() {
  24. expect(ctx.scope.selectSegments.length).to.be(2);
  25. });
  26. describe('initSelectSegments with 2 selects', function() {
  27. it('init selectSegments', function() {
  28. ctx.scope.target.metrics = [
  29. {agg: 'count'},
  30. {agg: 'avg', field: 'value'},
  31. ];
  32. ctx.scope.initSelectSegments();
  33. expect(ctx.scope.selectSegments.length).to.be(5);
  34. expect(ctx.scope.selectSegments[0].value).to.be('count');
  35. expect(ctx.scope.selectSegments[1].value).to.be(' and ');
  36. expect(ctx.scope.selectSegments[2].value).to.be('avg');
  37. expect(ctx.scope.selectSegments[3].value).to.be('value');
  38. });
  39. });
  40. });
  41. });
  42. });