heatmap_ctrl.test.ts 1.9 KB

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