graph-ctrl-specs.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 build legend model', function() {
  26. expect(ctx.scope.legend[0].alias).to.be('test.cpu1');
  27. expect(ctx.scope.legend[1].alias).to.be('test.cpu2');
  28. });
  29. it('should send time series to render', function() {
  30. var data = ctx.scope.render.getCall(0).args[0];
  31. expect(data.length).to.be(2);
  32. });
  33. describe('get_data failure following success', function() {
  34. beforeEach(function() {
  35. ctx.datasource.query = sinon.stub().returns(ctx.$q.reject('Datasource Error'));
  36. ctx.scope.get_data();
  37. ctx.scope.$digest();
  38. });
  39. it('should clear the legend data', function() {
  40. expect(ctx.scope.legend).to.eql([]);
  41. });
  42. });
  43. });
  44. });
  45. });