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

track_event_spec.js « directives « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b4a68e394afbd0201d7331ec51f27df0fd3e920 (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
61
62
63
64
65
66
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import Tracking from '~/tracking';
import TrackEvent from '~/vue_shared/directives/track_event';

jest.mock('~/tracking');

describe('TrackEvent directive', () => {
  let wrapper;

  const clickButton = () => wrapper.find('button').trigger('click');

  const DummyTrackComponent = Vue.component('DummyTrackComponent', {
    directives: {
      TrackEvent,
    },
    props: {
      category: {
        type: String,
        required: false,
        default: '',
      },
      action: {
        type: String,
        required: false,
        default: '',
      },
      label: {
        type: String,
        required: false,
        default: '',
      },
    },
    template: '<button v-track-event="{ category, action, label }"></button>',
  });

  const mountComponent = ({ propsData = {} } = {}) => {
    wrapper = shallowMount(DummyTrackComponent, {
      propsData,
    });
  };

  it('does not track the event if required arguments are not provided', () => {
    mountComponent();
    clickButton();

    expect(Tracking.event).not.toHaveBeenCalled();
  });

  it('tracks event on click if tracking info provided', async () => {
    mountComponent({
      propsData: {
        category: 'Tracking',
        action: 'click_trackable_btn',
        label: 'Trackable Info',
      },
    });

    await nextTick();
    clickButton();

    expect(Tracking.event).toHaveBeenCalledWith('Tracking', 'click_trackable_btn', {
      label: 'Trackable Info',
    });
  });
});