debian-mirror-gitlab/spec/frontend/__helpers__/tracking_helper.js

26 lines
781 B
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import Tracking from '~/tracking';
export default Tracking;
let document;
let handlers;
export function mockTracking(category = '_category_', documentOverride, spyMethod) {
document = documentOverride || window.document;
window.snowplow = () => {};
2020-04-08 14:13:33 +05:30
handlers = Tracking.bindDocument(category, document);
2019-12-21 20:55:43 +05:30
return spyMethod ? spyMethod(Tracking, 'event') : null;
}
export function unmockTracking() {
window.snowplow = undefined;
2021-03-08 18:12:59 +05:30
handlers.forEach((event) => document.removeEventListener(event.name, event.func));
2019-12-21 20:55:43 +05:30
}
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);
}