graph_ctrl_specs.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { describe, beforeEach, it, expect, angularMocks } from '../../../../../test/lib/common';
  2. import moment from 'moment';
  3. import { GraphCtrl } from '../module';
  4. import helpers from '../../../../../test/specs/helpers';
  5. describe('GraphCtrl', function() {
  6. var ctx = new helpers.ControllerTestContext();
  7. beforeEach(angularMocks.module('grafana.services'));
  8. beforeEach(angularMocks.module('grafana.controllers'));
  9. beforeEach(
  10. angularMocks.module(function($compileProvider) {
  11. $compileProvider.preAssignBindingsEnabled(true);
  12. })
  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. {
  24. target: 'test.cpu1',
  25. datapoints: [[45, 1234567890], [60, 1234567899]],
  26. },
  27. ];
  28. ctx.ctrl.range = { from: moment().valueOf(), to: moment().valueOf() };
  29. ctx.ctrl.onDataReceived(data);
  30. });
  31. it('should set datapointsOutside', function() {
  32. expect(ctx.ctrl.dataWarning.title).to.be('Data points outside time range');
  33. });
  34. });
  35. describe('when time series are inside range', function() {
  36. beforeEach(function() {
  37. var range = {
  38. from: moment()
  39. .subtract(1, 'days')
  40. .valueOf(),
  41. to: moment().valueOf(),
  42. };
  43. var data = [
  44. {
  45. target: 'test.cpu1',
  46. datapoints: [[45, range.from + 1000], [60, range.from + 10000]],
  47. },
  48. ];
  49. ctx.ctrl.range = range;
  50. ctx.ctrl.onDataReceived(data);
  51. });
  52. it('should set datapointsOutside', function() {
  53. expect(ctx.ctrl.dataWarning).to.be(null);
  54. });
  55. });
  56. describe('datapointsCount given 2 series', function() {
  57. beforeEach(function() {
  58. var data = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
  59. ctx.ctrl.onDataReceived(data);
  60. });
  61. it('should set datapointsCount warning', function() {
  62. expect(ctx.ctrl.dataWarning.title).to.be('No data points');
  63. });
  64. });
  65. });