getTimeRangeFromEvent.spec.tsx 901 B

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