graph_ctrl.jest.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import moment from 'moment';
  2. import { GraphCtrl } from '../module';
  3. jest.mock('../graph', () => ({}));
  4. describe('GraphCtrl', function() {
  5. let injector = {
  6. get: () => {
  7. return {
  8. timeRange: () => {
  9. return {
  10. from: '',
  11. to: '',
  12. };
  13. },
  14. };
  15. },
  16. };
  17. let scope = {
  18. $on: () => {},
  19. };
  20. GraphCtrl.prototype.panel = {
  21. events: {
  22. on: () => {},
  23. },
  24. gridPos: {
  25. w: 100,
  26. },
  27. };
  28. let ctx = <any>{};
  29. beforeEach(() => {
  30. ctx.ctrl = new GraphCtrl(scope, injector, {});
  31. });
  32. beforeEach(() => {
  33. ctx.ctrl.annotationsPromise = Promise.resolve({});
  34. ctx.ctrl.updateTimeRange();
  35. });
  36. describe('when time series are outside range', function() {
  37. beforeEach(function() {
  38. var data = [
  39. {
  40. target: 'test.cpu1',
  41. datapoints: [[45, 1234567890], [60, 1234567899]],
  42. },
  43. ];
  44. ctx.ctrl.range = { from: moment().valueOf(), to: moment().valueOf() };
  45. ctx.ctrl.onDataReceived(data);
  46. });
  47. it('should set datapointsOutside', function() {
  48. expect(ctx.ctrl.dataWarning.title).toBe('Data points outside time range');
  49. });
  50. });
  51. describe('when time series are inside range', function() {
  52. beforeEach(function() {
  53. var range = {
  54. from: moment()
  55. .subtract(1, 'days')
  56. .valueOf(),
  57. to: moment().valueOf(),
  58. };
  59. var data = [
  60. {
  61. target: 'test.cpu1',
  62. datapoints: [[45, range.from + 1000], [60, range.from + 10000]],
  63. },
  64. ];
  65. ctx.ctrl.range = range;
  66. ctx.ctrl.onDataReceived(data);
  67. });
  68. it('should set datapointsOutside', function() {
  69. expect(ctx.ctrl.dataWarning).toBe(null);
  70. });
  71. });
  72. describe('datapointsCount given 2 series', function() {
  73. beforeEach(function() {
  74. var data = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
  75. ctx.ctrl.onDataReceived(data);
  76. });
  77. it('should set datapointsCount warning', function() {
  78. expect(ctx.ctrl.dataWarning.title).toBe('No data points');
  79. });
  80. });
  81. });