|
1 | 1 | import 'jsdom-worker';
|
2 | 2 |
|
3 | 3 | import { BASE_TIMESTAMP } from '../..';
|
4 |
| -import { REPLAY_MAX_EVENT_BUFFER_SIZE } from '../../../src/constants'; |
| 4 | +import { MAX_REPLAY_DURATION, REPLAY_MAX_EVENT_BUFFER_SIZE, SESSION_IDLE_PAUSE_DURATION } from '../../../src/constants'; |
5 | 5 | import type { EventBufferProxy } from '../../../src/eventBuffer/EventBufferProxy';
|
6 |
| -import { addEvent } from '../../../src/util/addEvent'; |
| 6 | +import { addEvent, shouldAddEvent } from '../../../src/util/addEvent'; |
7 | 7 | import { getTestEventIncremental } from '../../utils/getTestEvent';
|
8 | 8 | import { setupReplayContainer } from '../../utils/setupReplayContainer';
|
9 | 9 | import { useFakeTimers } from '../../utils/use-fake-timers';
|
@@ -57,4 +57,65 @@ describe('Unit | util | addEvent', () => {
|
57 | 57 |
|
58 | 58 | expect(replay.isEnabled()).toEqual(false);
|
59 | 59 | });
|
| 60 | + |
| 61 | + describe('shouldAddEvent', () => { |
| 62 | + beforeEach(() => { |
| 63 | + jest.setSystemTime(BASE_TIMESTAMP); |
| 64 | + }); |
| 65 | + |
| 66 | + it('returns true by default', () => { |
| 67 | + const replay = setupReplayContainer({}); |
| 68 | + const event = getTestEventIncremental({ timestamp: BASE_TIMESTAMP }); |
| 69 | + |
| 70 | + expect(shouldAddEvent(replay, event)).toEqual(true); |
| 71 | + }); |
| 72 | + |
| 73 | + it('returns false when paused', () => { |
| 74 | + const replay = setupReplayContainer({}); |
| 75 | + const event = getTestEventIncremental({ timestamp: BASE_TIMESTAMP }); |
| 76 | + |
| 77 | + replay.pause(); |
| 78 | + |
| 79 | + expect(shouldAddEvent(replay, event)).toEqual(false); |
| 80 | + }); |
| 81 | + |
| 82 | + it('returns false when disabled', async () => { |
| 83 | + const replay = setupReplayContainer({}); |
| 84 | + const event = getTestEventIncremental({ timestamp: BASE_TIMESTAMP }); |
| 85 | + |
| 86 | + await replay.stop(); |
| 87 | + |
| 88 | + expect(shouldAddEvent(replay, event)).toEqual(false); |
| 89 | + }); |
| 90 | + |
| 91 | + it('returns false if there is no eventBuffer', () => { |
| 92 | + const replay = setupReplayContainer({}); |
| 93 | + const event = getTestEventIncremental({ timestamp: BASE_TIMESTAMP }); |
| 94 | + |
| 95 | + replay.eventBuffer = null; |
| 96 | + |
| 97 | + expect(shouldAddEvent(replay, event)).toEqual(false); |
| 98 | + }); |
| 99 | + |
| 100 | + it('returns false when event is too old', () => { |
| 101 | + const replay = setupReplayContainer({}); |
| 102 | + const event = getTestEventIncremental({ timestamp: BASE_TIMESTAMP - SESSION_IDLE_PAUSE_DURATION - 1 }); |
| 103 | + |
| 104 | + expect(shouldAddEvent(replay, event)).toEqual(false); |
| 105 | + }); |
| 106 | + |
| 107 | + it('returns false if event is too long after initial timestamp', () => { |
| 108 | + const replay = setupReplayContainer({}); |
| 109 | + const event = getTestEventIncremental({ timestamp: BASE_TIMESTAMP + MAX_REPLAY_DURATION + 1 }); |
| 110 | + |
| 111 | + expect(shouldAddEvent(replay, event)).toEqual(false); |
| 112 | + }); |
| 113 | + |
| 114 | + it('returns true if event is withing max duration after after initial timestamp', () => { |
| 115 | + const replay = setupReplayContainer({}); |
| 116 | + const event = getTestEventIncremental({ timestamp: BASE_TIMESTAMP + MAX_REPLAY_DURATION - 1 }); |
| 117 | + |
| 118 | + expect(shouldAddEvent(replay, event)).toEqual(true); |
| 119 | + }); |
| 120 | + }); |
60 | 121 | });
|
0 commit comments