graph_ctrl_specs.ts 1.6 KB

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