diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-26 06:06:27 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-26 06:06:27 +0000 |
commit | 9735395f94088df7e6470e3e8a2638385ede36b6 (patch) | |
tree | fbd42e043d05dbc78872b0458baac3a216ea232e /spec/frontend/helpers | |
parent | 33586a7aa128171b1bbc9380648b6945b09f5e2d (diff) | |
download | gitlab-ce-9735395f94088df7e6470e3e8a2638385ede36b6.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/helpers')
-rw-r--r-- | spec/frontend/helpers/tracking_helper.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/frontend/helpers/tracking_helper.js b/spec/frontend/helpers/tracking_helper.js new file mode 100644 index 00000000000..68c1bd2dbca --- /dev/null +++ b/spec/frontend/helpers/tracking_helper.js @@ -0,0 +1,25 @@ +import Tracking from '~/tracking'; + +export default Tracking; + +let document; +let handlers; + +export function mockTracking(category = '_category_', documentOverride, spyMethod) { + document = documentOverride || window.document; + window.snowplow = () => {}; + Tracking.bindDocument(category, document); + return spyMethod ? spyMethod(Tracking, 'event') : null; +} + +export function unmockTracking() { + window.snowplow = undefined; + handlers.forEach(event => document.removeEventListener(event.name, event.func)); +} + +export function triggerEvent(selectorOrEl, eventName = 'click') { + const event = new Event(eventName, { bubbles: true }); + const el = typeof selectorOrEl === 'string' ? document.querySelector(selectorOrEl) : selectorOrEl; + + el.dispatchEvent(event); +} |