Commit c5398a33 authored by jejacks0n's avatar jejacks0n

Disable form event tracking without a whitelist

parent cbc32912
......@@ -156,11 +156,16 @@ export default class Tracking {
static enableFormTracking(config, contexts = []) {
if (!this.enabled()) return;
if (!config?.forms?.whitelist?.length && !config?.fields?.whitelist?.length) {
// eslint-disable-next-line @gitlab/require-i18n-strings
throw new Error('Unable to enable form event tracking without whitelist rules.');
}
contexts.unshift(STANDARD_CONTEXT);
const enabler = () => window.snowplow('enableFormTracking', config, contexts);
if (document.readyState !== 'loading') enabler();
else document.addEventListener('DOMContentLoaded', enabler)
// else document.addEventListener('DOMContentLoaded', enabler)
}
static mixin(opts = {}) {
......
......@@ -165,6 +165,20 @@ describe('Tracking', () => {
'_passed_context_',
]);
});
it('throws an error if no whitelist rules are provided', () => {
const expectedError = new Error(
'Unable to enable form event tracking without whitelist rules.',
);
expect(() => Tracking.enableFormTracking()).toThrow(expectedError);
expect(() => Tracking.enableFormTracking({ fields: { whitelist: [] } })).toThrow(
expectedError,
);
expect(() => Tracking.enableFormTracking({ fields: { whitelist: [1] } })).not.toThrow(
expectedError,
);
});
});
describe('.flushPendingEvents', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment