diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/frontend/tracking_spec.js | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/frontend/tracking_spec.js')
-rw-r--r-- | spec/frontend/tracking_spec.js | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/spec/frontend/tracking_spec.js b/spec/frontend/tracking_spec.js index 30a8e138df2..08a26d46618 100644 --- a/spec/frontend/tracking_spec.js +++ b/spec/frontend/tracking_spec.js @@ -4,6 +4,7 @@ import Tracking, { initUserTracking } from '~/tracking'; describe('Tracking', () => { let snowplowSpy; let bindDocumentSpy; + let trackLoadEventsSpy; beforeEach(() => { window.snowplow = window.snowplow || (() => {}); @@ -18,6 +19,7 @@ describe('Tracking', () => { describe('initUserTracking', () => { beforeEach(() => { bindDocumentSpy = jest.spyOn(Tracking, 'bindDocument').mockImplementation(() => null); + trackLoadEventsSpy = jest.spyOn(Tracking, 'trackLoadEvents').mockImplementation(() => null); }); it('calls through to get a new tracker with the expected options', () => { @@ -44,10 +46,11 @@ describe('Tracking', () => { expect(snowplowSpy).not.toHaveBeenCalledWith('enableFormTracking'); expect(snowplowSpy).not.toHaveBeenCalledWith('enableLinkClickTracking'); - window.snowplowOptions = Object.assign({}, window.snowplowOptions, { + window.snowplowOptions = { + ...window.snowplowOptions, formTracking: true, linkClickTracking: true, - }); + }; initUserTracking(); expect(snowplowSpy).toHaveBeenCalledWith('enableFormTracking'); @@ -58,6 +61,11 @@ describe('Tracking', () => { initUserTracking(); expect(bindDocumentSpy).toHaveBeenCalled(); }); + + it('tracks page loaded events', () => { + initUserTracking(); + expect(trackLoadEventsSpy).toHaveBeenCalled(); + }); }); describe('.event', () => { @@ -127,6 +135,7 @@ describe('Tracking', () => { <input type="checkbox" data-track-event="toggle_checkbox" value="_value_" checked/> <input class="dropdown" data-track-event="toggle_dropdown"/> <div data-track-event="nested_event"><span class="nested"></span></div> + <input data-track-eventbogus="click_bogusinput" data-track-label="_label_" value="_value_"/> `); }); @@ -139,6 +148,12 @@ describe('Tracking', () => { }); }); + it('does not bind to clicks on elements without [data-track-event]', () => { + trigger('[data-track-eventbogus="click_bogusinput"]'); + + expect(eventSpy).not.toHaveBeenCalled(); + }); + it('allows value override with the data-track-value attribute', () => { trigger('[data-track-event="click_input2"]'); @@ -178,6 +193,44 @@ describe('Tracking', () => { }); }); + describe('tracking page loaded events', () => { + let eventSpy; + + beforeEach(() => { + eventSpy = jest.spyOn(Tracking, 'event'); + setHTMLFixture(` + <input data-track-event="render" data-track-label="label1" value="_value_" data-track-property="_property_"/> + <span data-track-event="render" data-track-label="label2" data-track-value="_value_"> + Something + </span> + <input data-track-event="_render_bogus_" data-track-label="label3" value="_value_" data-track-property="_property_"/> + `); + Tracking.trackLoadEvents('_category_'); // only happens once + }); + + it('sends tracking events when [data-track-event="render"] is on an element', () => { + expect(eventSpy.mock.calls).toEqual([ + [ + '_category_', + 'render', + { + label: 'label1', + value: '_value_', + property: '_property_', + }, + ], + [ + '_category_', + 'render', + { + label: 'label2', + value: '_value_', + }, + ], + ]); + }); + }); + describe('tracking mixin', () => { describe('trackingOptions', () => { it('return the options defined on initialisation', () => { |