utils.spec.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {getFormat} from 'sentry/utils/dates';
  2. import {getConfigFromTimeRange} from 'sentry/views/monitors/components/overviewTimeline/utils';
  3. describe('Crons Timeline Utils', function () {
  4. describe('getConfigFromTimeRange', function () {
  5. const timelineWidth = 800;
  6. it('divides into minutes for small intervals', function () {
  7. const start = new Date('2023-06-15T11:00:00Z');
  8. const end = new Date('2023-06-15T11:05:00Z');
  9. const config = getConfigFromTimeRange(start, end, timelineWidth);
  10. expect(config).toEqual({
  11. start,
  12. end,
  13. dateLabelFormat: getFormat({timeOnly: true, seconds: true}),
  14. elapsedMinutes: 5,
  15. markerInterval: 1,
  16. minimumMarkerInterval: 0.625,
  17. dateTimeProps: {timeOnly: true},
  18. });
  19. });
  20. it('displays dates when more than 1 day window size', function () {
  21. const start = new Date('2023-06-15T11:00:00Z');
  22. const end = new Date('2023-06-16T11:05:00Z');
  23. const config = getConfigFromTimeRange(start, end, timelineWidth);
  24. expect(config).toEqual({
  25. start,
  26. end,
  27. dateLabelFormat: getFormat(),
  28. elapsedMinutes: 1445,
  29. markerInterval: 240,
  30. minimumMarkerInterval: 198.6875,
  31. dateTimeProps: {timeOnly: false},
  32. });
  33. });
  34. it('divides into minutes without showing seconds for medium intervals', function () {
  35. const start = new Date('2023-06-15T08:00:00Z');
  36. const end = new Date('2023-06-15T23:00:00Z');
  37. const config = getConfigFromTimeRange(start, end, timelineWidth);
  38. expect(config).toEqual({
  39. start,
  40. end,
  41. dateLabelFormat: getFormat({timeOnly: true}),
  42. elapsedMinutes: 900,
  43. markerInterval: 120,
  44. minimumMarkerInterval: 112.5,
  45. dateTimeProps: {timeOnly: true},
  46. });
  47. });
  48. it('divides into days for larger intervals', function () {
  49. const start = new Date('2023-05-15T11:00:00Z');
  50. const end = new Date('2023-06-15T11:00:00Z');
  51. const config = getConfigFromTimeRange(start, end, timelineWidth);
  52. expect(config).toEqual({
  53. start,
  54. end,
  55. dateLabelFormat: getFormat(),
  56. // 31 elapsed days
  57. elapsedMinutes: 31 * 24 * 60,
  58. // 5 days in between each time label
  59. markerInterval: 5 * 24 * 60,
  60. minimumMarkerInterval: 6138,
  61. dateTimeProps: {dateOnly: true},
  62. });
  63. });
  64. });
  65. });