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.

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { shallowMount } from '@vue/test-utils';
2023-06-20 00:43:36 +05:30
import Vue 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');
2023-06-20 00:43:36 +05:30
describe('TrackEvent directive', () => {
let wrapper;
2019-12-21 20:55:43 +05:30
2023-06-20 00:43:36 +05:30
const clickButton = () => wrapper.find('button').trigger('click');
2019-12-21 20:55:43 +05:30
2023-06-20 00:43:36 +05:30
const createComponent = (trackingOptions) =>
Vue.component('DummyElement', {
directives: {
TrackEvent,
},
data() {
return {
trackingOptions,
};
},
template: '<button v-track-event="trackingOptions"></button>',
});
const mountComponent = (trackingOptions) => shallowMount(createComponent(trackingOptions));
it('does not track the event if required arguments are not provided', () => {
wrapper = mountComponent();
clickButton();
2019-12-21 20:55:43 +05:30
expect(Tracking.event).not.toHaveBeenCalled();
});
2023-06-20 00:43:36 +05:30
it('tracks event on click if tracking info provided', () => {
wrapper = mountComponent({
2019-12-21 20:55:43 +05:30
category: 'Tracking',
action: 'click_trackable_btn',
label: 'Trackable Info',
2023-06-20 00:43:36 +05:30
});
clickButton();
2020-03-13 15:44:24 +05:30
2023-06-20 00:43:36 +05:30
expect(Tracking.event).toHaveBeenCalledWith('Tracking', 'click_trackable_btn', {
label: 'Trackable Info',
});
2019-12-21 20:55:43 +05:30
});
});