Welcome to mirror list, hosted at ThFree Co, Russian Federation.

blob_links_tracking_spec.js « blob « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 22e087bc180a6b1d2a0fda2aeae7bc3046b1b48b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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(`
    <div id="blob-content-holder">
      <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>
    `);
    addBlobLinksTracking('#blob-content-holder', eventsToTrack);
    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();
  });
});