graph-ctrl-specs.js 1.4 KB

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