graph_ctrl_specs.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ///<reference path="../../../../headers/common.d.ts" />
  2. import {describe, beforeEach, it, sinon, expect, angularMocks} from '../../../../../test/lib/common';
  3. import angular from 'angular';
  4. import {GraphCtrl} from '../module';
  5. import helpers from '../../../../../test/specs/helpers';
  6. describe('GraphCtrl', function() {
  7. var ctx = new helpers.ControllerTestContext();
  8. beforeEach(angularMocks.module('grafana.services'));
  9. beforeEach(angularMocks.module('grafana.controllers'));
  10. beforeEach(ctx.providePhase());
  11. beforeEach(ctx.createPanelController(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.ctrl.render = sinon.spy();
  22. ctx.ctrl.refreshData(ctx.datasource);
  23. ctx.scope.$digest();
  24. });
  25. it('should send time series to render', function() {
  26. var data = ctx.ctrl.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.ctrl.refreshData(ctx.datasource);
  33. ctx.scope.$digest();
  34. });
  35. });
  36. });
  37. });