utils.spec.tsx 2.8 KB

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