2019-09-26 02:06:27 -04:00
|
|
|
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-02-24 16:09:08 -05:00
|
|
|
handlers = Tracking.bindDocument(category, document);
|
2019-09-26 02:06:27 -04:00
|
|
|
return spyMethod ? spyMethod(Tracking, 'event') : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unmockTracking() {
|
|
|
|
window.snowplow = undefined;
|
2020-12-23 16:10:24 -05:00
|
|
|
handlers.forEach((event) => document.removeEventListener(event.name, event.func));
|
2019-09-26 02:06:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|