graph_ctrl.jest.ts 2.2 KB

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