2022-08-27 11:52:29 +05:30
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
|
|
|
import addBlobLinksTracking from '~/blob/blob_links_tracking';
|
|
|
|
import Tracking from '~/tracking';
|
|
|
|
|
|
|
|
describe('Blob links Tracking', () => {
|
|
|
|
const eventName = 'click_link';
|
|
|
|
const label = 'file_line_action';
|
|
|
|
|
|
|
|
const eventsToTrack = [
|
|
|
|
{ selector: '.file-line-blame', property: 'blame' },
|
|
|
|
{ selector: '.file-line-num', property: 'link' },
|
|
|
|
];
|
|
|
|
|
|
|
|
const [blameLinkClickEvent, numLinkClickEvent] = eventsToTrack;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setHTMLFixture(`
|
2022-10-02 17:18:49 +05:30
|
|
|
<div class="file-holder">
|
2022-08-27 11:52:29 +05:30
|
|
|
<div class="line-links diff-line-num">
|
|
|
|
<a href="#L5" class="file-line-blame"></a>
|
|
|
|
<a id="L5" href="#L5" data-line-number="5" class="file-line-num">5</a>
|
|
|
|
</div>
|
|
|
|
<pre id="LC5">Line 5 content</pre>
|
|
|
|
</div>
|
|
|
|
`);
|
2022-10-02 17:18:49 +05:30
|
|
|
addBlobLinksTracking();
|
2022-08-27 11:52:29 +05:30
|
|
|
jest.spyOn(Tracking, 'event');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tracks blame link click event', () => {
|
|
|
|
const blameButton = document.querySelector(blameLinkClickEvent.selector);
|
|
|
|
blameButton.click();
|
|
|
|
|
|
|
|
expect(Tracking.event).toHaveBeenCalledWith(undefined, eventName, {
|
|
|
|
label,
|
|
|
|
property: blameLinkClickEvent.property,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tracks num link click event', () => {
|
|
|
|
const numLinkButton = document.querySelector(numLinkClickEvent.selector);
|
|
|
|
numLinkButton.click();
|
|
|
|
|
|
|
|
expect(Tracking.event).toHaveBeenCalledWith(undefined, eventName, {
|
|
|
|
label,
|
|
|
|
property: numLinkClickEvent.property,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't fire tracking if the user clicks on any element that is not a link", () => {
|
|
|
|
const codeLine = document.querySelector('#LC5');
|
|
|
|
codeLine.click();
|
|
|
|
|
|
|
|
expect(Tracking.event).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|