graph_ctrl.test.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { dateTime } from '@grafana/data';
  2. import { GraphCtrl } from '../module';
  3. jest.mock('../graph', () => ({}));
  4. describe.skip('GraphCtrl', () => {
  5. const injector = {
  6. get: () => {
  7. return {
  8. timeRange: () => {
  9. return {
  10. from: '',
  11. to: '',
  12. };
  13. },
  14. };
  15. },
  16. };
  17. GraphCtrl.prototype.panel = {
  18. events: {
  19. on: () => {},
  20. emit: () => {},
  21. },
  22. gridPos: {
  23. w: 100,
  24. },
  25. fieldConfig: {
  26. defaults: {},
  27. },
  28. };
  29. const scope: any = {
  30. $on: () => {},
  31. $parent: {
  32. panel: GraphCtrl.prototype.panel,
  33. dashboard: {},
  34. },
  35. };
  36. const ctx = {} as any;
  37. beforeEach(() => {
  38. ctx.ctrl = new GraphCtrl(scope, injector as any);
  39. ctx.ctrl.events = {
  40. emit: () => {},
  41. };
  42. ctx.ctrl.panelData = {};
  43. ctx.ctrl.updateTimeRange();
  44. });
  45. describe('when time series are outside range', () => {
  46. beforeEach(() => {
  47. const data = [
  48. {
  49. target: 'test.cpu1',
  50. datapoints: [
  51. [45, 1234567890],
  52. [60, 1234567899],
  53. ],
  54. },
  55. ];
  56. ctx.ctrl.range = { from: dateTime().valueOf(), to: dateTime().valueOf() };
  57. ctx.ctrl.onDataSnapshotLoad(data);
  58. });
  59. it('should set datapointsOutside', () => {
  60. expect(ctx.ctrl.dataWarning.title).toBe('Data outside time range');
  61. });
  62. });
  63. describe('when time series are inside range', () => {
  64. beforeEach(() => {
  65. const range = {
  66. from: dateTime().subtract(1, 'days').valueOf(),
  67. to: dateTime().valueOf(),
  68. };
  69. const data = [
  70. {
  71. target: 'test.cpu1',
  72. datapoints: [
  73. [45, range.from + 1000],
  74. [60, range.from + 10000],
  75. ],
  76. },
  77. ];
  78. ctx.ctrl.range = range;
  79. ctx.ctrl.onDataSnapshotLoad(data);
  80. });
  81. it('should set datapointsOutside', () => {
  82. expect(ctx.ctrl.dataWarning).toBeUndefined();
  83. });
  84. });
  85. describe('datapointsCount given 2 series', () => {
  86. beforeEach(() => {
  87. const data: any = [
  88. { target: 'test.cpu1', datapoints: [] },
  89. { target: 'test.cpu2', datapoints: [] },
  90. ];
  91. ctx.ctrl.onDataSnapshotLoad(data);
  92. });
  93. it('should set datapointsCount warning', () => {
  94. expect(ctx.ctrl.dataWarning.title).toBe('No data');
  95. });
  96. });
  97. });