debian-mirror-gitlab/spec/frontend/design_management/utils/tracking_spec.js

60 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { mockTracking } from 'helpers/tracking_helper';
import { trackDesignDetailView } from '~/design_management/utils/tracking';
function getTrackingSpy(key) {
return mockTracking(key, undefined, jest.spyOn);
}
describe('Tracking Events', () => {
describe('trackDesignDetailView', () => {
const eventKey = 'projects:issues:design';
2020-07-28 23:09:34 +05:30
const eventName = 'view_design';
2020-05-24 23:13:21 +05:30
it('trackDesignDetailView fires a tracking event when called', () => {
const trackingSpy = getTrackingSpy(eventKey);
trackDesignDetailView();
expect(trackingSpy).toHaveBeenCalledWith(
eventKey,
eventName,
expect.objectContaining({
label: eventName,
2020-07-28 23:09:34 +05:30
context: {
schema: expect.any(String),
data: {
'design-version-number': 1,
'design-is-current-version': false,
'internal-object-referrer': '',
'design-collection-owner': '',
},
2020-05-24 23:13:21 +05:30
},
}),
);
});
it('trackDesignDetailView allows to customize the value payload', () => {
const trackingSpy = getTrackingSpy(eventKey);
trackDesignDetailView('from-a-test', 'test', 100, true);
expect(trackingSpy).toHaveBeenCalledWith(
eventKey,
eventName,
expect.objectContaining({
label: eventName,
2020-07-28 23:09:34 +05:30
context: {
schema: expect.any(String),
data: {
'design-version-number': 100,
'design-is-current-version': true,
'internal-object-referrer': 'from-a-test',
'design-collection-owner': 'test',
},
2020-05-24 23:13:21 +05:30
},
}),
);
});
});
});