getTimeRangeFromEvent.spec.tsx 947 B

12345678910111213141516171819202122232425
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {getTimeRangeFromEvent} from './getTimeRangeFromEvent';
  3. describe('getTimeRangeFromEvent', function () {
  4. it('correctly creates a centered 24h time window', function () {
  5. const event = EventFixture({dateReceived: '2023-07-26T09:00:00Z'});
  6. const now = new Date('2023-07-27T11:00:00Z');
  7. const {start, end} = getTimeRangeFromEvent(event, now, '24h');
  8. expect(start).toEqual(new Date('2023-07-25T21:00:00Z'));
  9. expect(end).toEqual(new Date('2023-07-26T21:00:00Z'));
  10. });
  11. it('falls back to last 24h if the event cannot be centered', function () {
  12. const event = EventFixture({dateReceived: '2023-07-27T09:00:00Z'});
  13. const now = new Date('2023-07-27T11:00:00Z');
  14. const {start, end} = getTimeRangeFromEvent(event, now, '24h');
  15. expect(start).toEqual(new Date('2023-07-26T11:00:00Z'));
  16. expect(end).toEqual(new Date('2023-07-27T11:00:00Z'));
  17. });
  18. });