graph-ctrl-specs.js 1.3 KB

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