debian-mirror-gitlab/spec/frontend/vue_shared/directives/track_event_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { shallowMount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import Vue, { nextTick } from 'vue';
2019-12-21 20:55:43 +05:30
import Tracking from '~/tracking';
import TrackEvent from '~/vue_shared/directives/track_event';
jest.mock('~/tracking');
2021-03-11 19:13:27 +05:30
const Component = Vue.component('DummyElement', {
2019-12-21 20:55:43 +05:30
directives: {
TrackEvent,
},
data() {
return {
trackingOptions: null,
};
},
template: '<button id="trackable" v-track-event="trackingOptions"></button>',
});
let wrapper;
let button;
describe('Error Tracking directive', () => {
beforeEach(() => {
2020-03-13 15:44:24 +05:30
wrapper = shallowMount(Component);
2019-12-21 20:55:43 +05:30
button = wrapper.find('#trackable');
});
it('should not track the event if required arguments are not provided', () => {
button.trigger('click');
expect(Tracking.event).not.toHaveBeenCalled();
});
2022-04-04 11:22:00 +05:30
it('should track event on click if tracking info provided', async () => {
2019-12-21 20:55:43 +05:30
const trackingOptions = {
category: 'Tracking',
action: 'click_trackable_btn',
label: 'Trackable Info',
};
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2019-12-21 20:55:43 +05:30
wrapper.setData({ trackingOptions });
const { category, action, label, property, value } = trackingOptions;
2020-03-13 15:44:24 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
button.trigger('click');
expect(Tracking.event).toHaveBeenCalledWith(category, action, { label, property, value });
2019-12-21 20:55:43 +05:30
});
});