graph_ctrl_specs.ts 2.2 KB

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