graph_ctrl_specs.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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(angularMocks.module(function($compileProvider) {
  12. $compileProvider.preAssignBindingsEnabled(true);
  13. }));
  14. beforeEach(ctx.providePhase());
  15. beforeEach(ctx.createPanelController(GraphCtrl));
  16. beforeEach(() => {
  17. ctx.ctrl.annotationsPromise = Promise.resolve({});
  18. ctx.ctrl.updateTimeRange();
  19. });
  20. describe('when time series are outside range', function() {
  21. beforeEach(function() {
  22. var data = [
  23. {target: 'test.cpu1', datapoints: [[45, 1234567890], [60, 1234567899]]},
  24. ];
  25. ctx.ctrl.range = {from: moment().valueOf(), to: moment().valueOf()};
  26. ctx.ctrl.onDataReceived(data);
  27. });
  28. it('should set datapointsOutside', function() {
  29. expect(ctx.ctrl.dataWarning.title).to.be('Data points outside time range');
  30. });
  31. });
  32. describe('when time series are inside range', function() {
  33. beforeEach(function() {
  34. var range = {
  35. from: moment().subtract(1, 'days').valueOf(),
  36. to: moment().valueOf()
  37. };
  38. var data = [
  39. {target: 'test.cpu1', datapoints: [[45, range.from + 1000], [60, range.from + 10000]]},
  40. ];
  41. ctx.ctrl.range = range;
  42. ctx.ctrl.onDataReceived(data);
  43. });
  44. it('should set datapointsOutside', function() {
  45. expect(ctx.ctrl.dataWarning).to.be(null);
  46. });
  47. });
  48. describe('datapointsCount given 2 series', function() {
  49. beforeEach(function() {
  50. var data = [
  51. {target: 'test.cpu1', datapoints: []},
  52. {target: 'test.cpu2', datapoints: []},
  53. ];
  54. ctx.ctrl.onDataReceived(data);
  55. });
  56. it('should set datapointsCount warning', function() {
  57. expect(ctx.ctrl.dataWarning.title).to.be('No data points');
  58. });
  59. });
  60. });