Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/tracking/utils_spec.js')
-rw-r--r--spec/frontend/tracking/utils_spec.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/frontend/tracking/utils_spec.js b/spec/frontend/tracking/utils_spec.js
index d6f2c5095b4..7ba65cce15d 100644
--- a/spec/frontend/tracking/utils_spec.js
+++ b/spec/frontend/tracking/utils_spec.js
@@ -4,6 +4,8 @@ import {
addExperimentContext,
addReferrersCacheEntry,
filterOldReferrersCacheEntries,
+ InternalEventHandler,
+ createInternalEventPayload,
} from '~/tracking/utils';
import { TRACKING_CONTEXT_SCHEMA } from '~/experimentation/constants';
import { REFERRER_TTL, URLS_CACHE_STORAGE_KEY } from '~/tracking/constants';
@@ -95,5 +97,40 @@ describe('~/tracking/utils', () => {
expect(cache[0].timestamp).toBeDefined();
});
});
+
+ describe('createInternalEventPayload', () => {
+ it('should return event name from element', () => {
+ const mockEl = { dataset: { eventTracking: 'click' } };
+ const result = createInternalEventPayload(mockEl);
+ expect(result).toEqual('click');
+ });
+ });
+
+ describe('InternalEventHandler', () => {
+ it.each([
+ ['should call the provided function with the correct event payload', 'click', true],
+ [
+ 'should not call the provided function if the closest matching element is not found',
+ null,
+ false,
+ ],
+ ])('%s', (_, payload, shouldCallFunc) => {
+ const mockFunc = jest.fn();
+ const mockEl = payload ? { dataset: { eventTracking: payload } } : null;
+ const mockEvent = {
+ target: {
+ closest: jest.fn().mockReturnValue(mockEl),
+ },
+ };
+
+ InternalEventHandler(mockEvent, mockFunc);
+
+ if (shouldCallFunc) {
+ expect(mockFunc).toHaveBeenCalledWith(payload);
+ } else {
+ expect(mockFunc).not.toHaveBeenCalled();
+ }
+ });
+ });
});
});