graph_ctrl_specs.ts 2.1 KB

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