heatmap_ctrl.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { HeatmapCtrl } from '../heatmap_ctrl';
  2. import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
  3. describe('HeatmapCtrl', () => {
  4. const ctx = {} as any;
  5. const $injector = {
  6. get: () => {},
  7. };
  8. const $scope = {
  9. $on: () => {},
  10. };
  11. HeatmapCtrl.prototype.panel = {
  12. events: {
  13. on: () => {},
  14. emit: () => {},
  15. },
  16. };
  17. beforeEach(() => {
  18. ctx.ctrl = new HeatmapCtrl($scope, $injector, {});
  19. });
  20. describe('when time series are outside range', () => {
  21. beforeEach(() => {
  22. const data = [
  23. {
  24. target: 'test.cpu1',
  25. datapoints: [[45, 1234567890], [60, 1234567899]],
  26. },
  27. ];
  28. ctx.ctrl.range = { from: dateTime().valueOf(), to: dateTime().valueOf() };
  29. ctx.ctrl.onDataReceived(data);
  30. });
  31. it('should set datapointsOutside', () => {
  32. expect(ctx.ctrl.dataWarning.title).toBe('Data points outside time range');
  33. });
  34. });
  35. describe('when time series are inside range', () => {
  36. beforeEach(() => {
  37. const range = {
  38. from: dateTime()
  39. .subtract(1, 'days')
  40. .valueOf(),
  41. to: dateTime().valueOf(),
  42. };
  43. const data = [
  44. {
  45. target: 'test.cpu1',
  46. datapoints: [[45, range.from + 1000], [60, range.from + 10000]],
  47. },
  48. ];
  49. ctx.ctrl.range = range;
  50. ctx.ctrl.onDataReceived(data);
  51. });
  52. it('should set datapointsOutside', () => {
  53. expect(ctx.ctrl.dataWarning).toBe(null);
  54. });
  55. });
  56. describe('datapointsCount given 2 series', () => {
  57. beforeEach(() => {
  58. const data = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
  59. ctx.ctrl.onDataReceived(data);
  60. });
  61. it('should set datapointsCount warning', () => {
  62. expect(ctx.ctrl.dataWarning.title).toBe('No data points');
  63. });
  64. });
  65. });