utils.spec.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. timeMarkerInterval: 1,
  16. dateTimeProps: {timeOnly: true},
  17. });
  18. });
  19. it('divides into minutes without showing seconds for medium intervals', function () {
  20. const start = new Date('2023-06-15T08:00:00Z');
  21. const end = new Date('2023-06-15T23:00:00Z');
  22. const config = getConfigFromTimeRange(start, end, timelineWidth);
  23. expect(config).toEqual({
  24. start,
  25. end,
  26. dateLabelFormat: getFormat({timeOnly: true}),
  27. elapsedMinutes: 900,
  28. timeMarkerInterval: 240,
  29. dateTimeProps: {timeOnly: true},
  30. });
  31. });
  32. it('divides into days for larger intervals', function () {
  33. const start = new Date('2023-05-15T11:00:00Z');
  34. const end = new Date('2023-06-15T11:00:00Z');
  35. const config = getConfigFromTimeRange(start, end, timelineWidth);
  36. expect(config).toEqual({
  37. start,
  38. end,
  39. dateLabelFormat: getFormat(),
  40. // 31 elapsed days
  41. elapsedMinutes: 31 * 24 * 60,
  42. // 4 days in between each time label
  43. timeMarkerInterval: 4 * 24 * 60,
  44. dateTimeProps: {dateOnly: true},
  45. });
  46. });
  47. });
  48. });