getConfigFromTimeRange.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {getFormat} from 'sentry/utils/dates';
  2. import {getConfigFromTimeRange} from './getConfigFromTimeRange';
  3. describe('getConfigFromTimeRange', function () {
  4. const timelineWidth = 800;
  5. it('divides into minutes for small intervals', function () {
  6. const start = new Date('2023-06-15T11:00:00Z');
  7. const end = new Date('2023-06-15T11:05:00Z');
  8. const config = getConfigFromTimeRange(start, end, timelineWidth);
  9. expect(config).toEqual({
  10. start,
  11. end,
  12. dateLabelFormat: getFormat({timeOnly: true, seconds: true}),
  13. elapsedMinutes: 5,
  14. intervals: {
  15. normalMarkerInterval: 1,
  16. minimumMarkerInterval: 0.625,
  17. referenceMarkerInterval: 0.71875,
  18. },
  19. dateTimeProps: {timeOnly: true},
  20. timelineWidth,
  21. });
  22. });
  23. it('displays dates when more than 1 day window size', function () {
  24. const start = new Date('2023-06-15T11:00:00Z');
  25. const end = new Date('2023-06-16T11:05:00Z');
  26. const config = getConfigFromTimeRange(start, end, timelineWidth);
  27. expect(config).toEqual({
  28. start,
  29. end,
  30. dateLabelFormat: getFormat(),
  31. elapsedMinutes: 1445,
  32. intervals: {
  33. normalMarkerInterval: 240,
  34. minimumMarkerInterval: 198.6875,
  35. referenceMarkerInterval: 207.71875,
  36. },
  37. dateTimeProps: {timeOnly: false},
  38. timelineWidth,
  39. });
  40. });
  41. it('divides into minutes without showing seconds for medium intervals', function () {
  42. const start = new Date('2023-06-15T08:00:00Z');
  43. const end = new Date('2023-06-15T23:00:00Z');
  44. const config = getConfigFromTimeRange(start, end, timelineWidth);
  45. expect(config).toEqual({
  46. start,
  47. end,
  48. dateLabelFormat: getFormat({timeOnly: true}),
  49. elapsedMinutes: 900,
  50. intervals: {
  51. normalMarkerInterval: 120,
  52. minimumMarkerInterval: 112.5,
  53. referenceMarkerInterval: 129.375,
  54. },
  55. dateTimeProps: {timeOnly: true},
  56. timelineWidth,
  57. });
  58. });
  59. it('divides into days for larger intervals', function () {
  60. const start = new Date('2023-05-15T11:00:00Z');
  61. const end = new Date('2023-06-15T11:00:00Z');
  62. const config = getConfigFromTimeRange(start, end, timelineWidth);
  63. expect(config).toEqual({
  64. start,
  65. end,
  66. dateLabelFormat: getFormat(),
  67. // 31 elapsed days
  68. elapsedMinutes: 31 * 24 * 60,
  69. // 5 days in between each time label
  70. intervals: {
  71. normalMarkerInterval: 5 * 24 * 60,
  72. minimumMarkerInterval: 6138,
  73. referenceMarkerInterval: 6417,
  74. },
  75. dateTimeProps: {dateOnly: true},
  76. timelineWidth,
  77. });
  78. });
  79. it('Includes dates when the window spans days', function () {
  80. const start = new Date('2023-05-14T20:00:00Z');
  81. const end = new Date('2023-05-15T10:00:00Z');
  82. const config = getConfigFromTimeRange(start, end, timelineWidth);
  83. expect(config).toEqual({
  84. start,
  85. end,
  86. dateLabelFormat: getFormat(),
  87. // 14 hours
  88. elapsedMinutes: 14 * 60,
  89. intervals: {
  90. normalMarkerInterval: 120,
  91. minimumMarkerInterval: 115.5,
  92. referenceMarkerInterval: 120.75,
  93. },
  94. dateTimeProps: {timeOnly: false},
  95. timelineWidth,
  96. });
  97. });
  98. });