graph-ctrl-specs.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. define([
  2. './helpers',
  3. 'panels/graph/module'
  4. ], function(helpers) {
  5. 'use strict';
  6. describe('GraphCtrl', function() {
  7. var ctx = new helpers.ControllerTestContext();
  8. beforeEach(module('grafana.services'));
  9. beforeEach(module('grafana.panels.graph'));
  10. beforeEach(ctx.providePhase());
  11. beforeEach(ctx.createControllerPhase('GraphCtrl'));
  12. describe('get_data with 2 series', function() {
  13. beforeEach(function() {
  14. ctx.annotationsSrv.getAnnotations = sinon.stub().returns(ctx.$q.when([]));
  15. ctx.datasource.query = sinon.stub().returns(ctx.$q.when({
  16. data: [
  17. { target: 'test.cpu1', datapoints: [[1, 10]]},
  18. { target: 'test.cpu2', datapoints: [[1, 10]]}
  19. ]
  20. }));
  21. ctx.scope.render = sinon.spy();
  22. ctx.scope.get_data();
  23. ctx.scope.$digest();
  24. });
  25. it('should send time series to render', function() {
  26. var data = ctx.scope.render.getCall(0).args[0];
  27. expect(data.length).to.be(2);
  28. });
  29. describe('get_data failure following success', function() {
  30. beforeEach(function() {
  31. ctx.datasource.query = sinon.stub().returns(ctx.$q.reject('Datasource Error'));
  32. ctx.scope.get_data();
  33. ctx.scope.$digest();
  34. });
  35. });
  36. });
  37. });
  38. });