2021-04-29 21:17:54 +05:30
|
|
|
import { GlButton, GlLink } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-04-29 21:17:54 +05:30
|
|
|
import ExperimentTracking from '~/experimentation/experiment_tracking';
|
2021-01-03 14:25:43 +05:30
|
|
|
import InviteMembersTrigger from '~/invite_members/components/invite_members_trigger.vue';
|
2021-04-29 21:17:54 +05:30
|
|
|
import eventHub from '~/invite_members/event_hub';
|
|
|
|
|
|
|
|
jest.mock('~/experimentation/experiment_tracking');
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
const displayText = 'Invite team members';
|
2021-09-04 01:27:46 +05:30
|
|
|
const triggerSource = '_trigger_source_';
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
let wrapper;
|
|
|
|
let triggerProps;
|
|
|
|
let findButton;
|
|
|
|
const triggerComponent = {
|
|
|
|
button: GlButton,
|
|
|
|
anchor: GlLink,
|
|
|
|
};
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
2021-04-29 21:17:54 +05:30
|
|
|
wrapper = shallowMount(InviteMembersTrigger, {
|
2021-01-03 14:25:43 +05:30
|
|
|
propsData: {
|
|
|
|
displayText,
|
2021-04-29 21:17:54 +05:30
|
|
|
...triggerProps,
|
2021-01-03 14:25:43 +05:30
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe.each(['button', 'anchor'])('with triggerElement as %s', (triggerElement) => {
|
2021-09-04 01:27:46 +05:30
|
|
|
triggerProps = { triggerElement, triggerSource };
|
2021-04-29 21:17:54 +05:30
|
|
|
findButton = () => wrapper.findComponent(triggerComponent[triggerElement]);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('displayText', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
it('includes the correct displayText for the button', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(findButton().text()).toBe(displayText);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('clicking the link', () => {
|
|
|
|
let spy;
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-04-29 21:17:54 +05:30
|
|
|
spy = jest.spyOn(eventHub, '$emit');
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('emits openModal from a named source', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
createComponent();
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
findButton().vm.$emit('click');
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith('openModal', {
|
|
|
|
inviteeType: 'members',
|
2021-09-04 01:27:46 +05:30
|
|
|
source: triggerSource,
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tracking', () => {
|
|
|
|
it('tracks on mounting', () => {
|
|
|
|
createComponent({ trackExperiment: '_track_experiment_' });
|
|
|
|
|
|
|
|
expect(ExperimentTracking).toHaveBeenCalledWith('_track_experiment_');
|
|
|
|
expect(ExperimentTracking.prototype.event).toHaveBeenCalledWith('comment_invite_shown');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not track on mounting', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(ExperimentTracking).not.toHaveBeenCalledWith('_track_experiment_');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add tracking attributes', () => {
|
|
|
|
createComponent();
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(findButton().attributes('data-track-action')).toBeUndefined();
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(findButton().attributes('data-track-label')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds tracking attributes', () => {
|
|
|
|
createComponent({ label: '_label_', event: '_event_' });
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
expect(findButton().attributes('data-track-action')).toBe('_event_');
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(findButton().attributes('data-track-label')).toBe('_label_');
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|