graph_ctrl_specs.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 moment from 'moment';
  5. import {GraphCtrl} from '../module';
  6. import helpers from '../../../../../test/specs/helpers';
  7. describe('GraphCtrl', function() {
  8. var ctx = new helpers.ControllerTestContext();
  9. beforeEach(angularMocks.module('grafana.services'));
  10. beforeEach(angularMocks.module('grafana.controllers'));
  11. beforeEach(ctx.providePhase());
  12. beforeEach(ctx.createPanelController(GraphCtrl));
  13. beforeEach(() => {
  14. ctx.ctrl.annotationsPromise = Promise.resolve({});
  15. ctx.ctrl.updateTimeRange();
  16. });
  17. describe('when time series are outside range', function() {
  18. beforeEach(function() {
  19. var data = [
  20. {target: 'test.cpu1', datapoints: [[45, 1234567890], [60, 1234567899]]},
  21. ];
  22. ctx.ctrl.range = {from: moment().valueOf(), to: moment().valueOf()};
  23. ctx.ctrl.onDataReceived(data);
  24. });
  25. it('should set datapointsOutside', function() {
  26. expect(ctx.ctrl.datapointsOutside).to.be(true);
  27. });
  28. });
  29. describe('when time series are inside range', function() {
  30. beforeEach(function() {
  31. var range = {
  32. from: moment().subtract(1, 'days').valueOf(),
  33. to: moment().valueOf()
  34. };
  35. var data = [
  36. {target: 'test.cpu1', datapoints: [[45, range.from + 1000], [60, range.from + 10000]]},
  37. ];
  38. ctx.ctrl.range = range;
  39. ctx.ctrl.onDataReceived(data);
  40. });
  41. it('should set datapointsOutside', function() {
  42. expect(ctx.ctrl.datapointsOutside).to.be(false);
  43. });
  44. });
  45. describe('datapointsCount given 2 series', function() {
  46. beforeEach(function() {
  47. var data = [
  48. {target: 'test.cpu1', datapoints: [[45, 1234567890], [60, 1234567899]]},
  49. {target: 'test.cpu2', datapoints: [[45, 1234567890]]},
  50. ];
  51. ctx.ctrl.onDataReceived(data);
  52. });
  53. it('should set datapointsCount to sum of datapoints', function() {
  54. expect(ctx.ctrl.datapointsCount).to.be(3);
  55. });
  56. });
  57. });