utils.spec.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. timelineWidth,
  19. });
  20. });
  21. it('displays dates when more than 1 day window size', function () {
  22. const start = new Date('2023-06-15T11:00:00Z');
  23. const end = new Date('2023-06-16T11:05:00Z');
  24. const config = getConfigFromTimeRange(start, end, timelineWidth);
  25. expect(config).toEqual({
  26. start,
  27. end,
  28. dateLabelFormat: getFormat(),
  29. elapsedMinutes: 1445,
  30. markerInterval: 240,
  31. minimumMarkerInterval: 198.6875,
  32. dateTimeProps: {timeOnly: false},
  33. timelineWidth,
  34. });
  35. });
  36. it('divides into minutes without showing seconds for medium intervals', function () {
  37. const start = new Date('2023-06-15T08:00:00Z');
  38. const end = new Date('2023-06-15T23:00:00Z');
  39. const config = getConfigFromTimeRange(start, end, timelineWidth);
  40. expect(config).toEqual({
  41. start,
  42. end,
  43. dateLabelFormat: getFormat({timeOnly: true}),
  44. elapsedMinutes: 900,
  45. markerInterval: 120,
  46. minimumMarkerInterval: 112.5,
  47. dateTimeProps: {timeOnly: true},
  48. timelineWidth,
  49. });
  50. });
  51. it('divides into days for larger intervals', function () {
  52. const start = new Date('2023-05-15T11:00:00Z');
  53. const end = new Date('2023-06-15T11:00:00Z');
  54. const config = getConfigFromTimeRange(start, end, timelineWidth);
  55. expect(config).toEqual({
  56. start,
  57. end,
  58. dateLabelFormat: getFormat(),
  59. // 31 elapsed days
  60. elapsedMinutes: 31 * 24 * 60,
  61. // 5 days in between each time label
  62. markerInterval: 5 * 24 * 60,
  63. minimumMarkerInterval: 6138,
  64. dateTimeProps: {dateOnly: true},
  65. timelineWidth,
  66. });
  67. });
  68. });
  69. });