diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/frontend/diffs/utils/queue_events_spec.js | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/frontend/diffs/utils/queue_events_spec.js')
-rw-r--r-- | spec/frontend/diffs/utils/queue_events_spec.js | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/spec/frontend/diffs/utils/queue_events_spec.js b/spec/frontend/diffs/utils/queue_events_spec.js index 007748d8b2c..ad2745f5188 100644 --- a/spec/frontend/diffs/utils/queue_events_spec.js +++ b/spec/frontend/diffs/utils/queue_events_spec.js @@ -1,11 +1,15 @@ import api from '~/api'; -import { DEFER_DURATION } from '~/diffs/constants'; +import { DEFER_DURATION, TRACKING_CAP_KEY, TRACKING_CAP_LENGTH } from '~/diffs/constants'; import { queueRedisHllEvents } from '~/diffs/utils/queue_events'; jest.mock('~/api', () => ({ trackRedisHllUserEvent: jest.fn(), })); +beforeAll(() => { + localStorage.clear(); +}); + describe('diffs events queue', () => { describe('queueRedisHllEvents', () => { it('does not dispatch the event immediately', () => { @@ -17,6 +21,7 @@ describe('diffs events queue', () => { queueRedisHllEvents(['know_event']); jest.advanceTimersByTime(DEFER_DURATION + 1); expect(api.trackRedisHllUserEvent).toHaveBeenCalled(); + expect(localStorage.getItem(TRACKING_CAP_KEY)).toBe(null); }); it('increase defer duration based on the provided events count', () => { @@ -32,5 +37,35 @@ describe('diffs events queue', () => { deferDuration *= index + 1; }); }); + + describe('with tracking cap verification', () => { + const currentTimestamp = Date.now(); + + beforeEach(() => { + localStorage.clear(); + }); + + it('dispatches the event if cap value is not found', () => { + queueRedisHllEvents(['know_event'], { verifyCap: true }); + jest.advanceTimersByTime(DEFER_DURATION + 1); + expect(api.trackRedisHllUserEvent).toHaveBeenCalled(); + expect(localStorage.getItem(TRACKING_CAP_KEY)).toBe(currentTimestamp.toString()); + }); + + it('dispatches the event if cap value is less than limit', () => { + localStorage.setItem(TRACKING_CAP_KEY, 1); + queueRedisHllEvents(['know_event'], { verifyCap: true }); + jest.advanceTimersByTime(DEFER_DURATION + 1); + expect(api.trackRedisHllUserEvent).toHaveBeenCalled(); + expect(localStorage.getItem(TRACKING_CAP_KEY)).toBe(currentTimestamp.toString()); + }); + + it('does not dispatch the event if cap value is greater than limit', () => { + localStorage.setItem(TRACKING_CAP_KEY, currentTimestamp - (TRACKING_CAP_LENGTH + 1)); + queueRedisHllEvents(['know_event'], { verifyCap: true }); + jest.advanceTimersByTime(DEFER_DURATION + 1); + expect(api.trackRedisHllUserEvent).toHaveBeenCalled(); + }); + }); }); }); |