graph-ctrl-specs.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. });
  34. });
  35. });