2021-12-11 22:18:48 +05:30
|
|
|
import { GlButton, GlLink, GlIcon } 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';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { TRIGGER_ELEMENT_BUTTON, TRIGGER_ELEMENT_SIDE_NAV } from '~/invite_members/constants';
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
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-12-11 22:18:48 +05:30
|
|
|
'side-nav': GlLink,
|
2021-04-29 21:17:54 +05:30
|
|
|
};
|
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-12-11 22:18:48 +05:30
|
|
|
const triggerItems = [
|
|
|
|
{
|
|
|
|
triggerElement: TRIGGER_ELEMENT_BUTTON,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
triggerElement: 'anchor',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
triggerElement: TRIGGER_ELEMENT_SIDE_NAV,
|
|
|
|
icon: 'plus',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
describe.each(triggerItems)('with triggerElement as %s', (triggerItem) => {
|
|
|
|
triggerProps = { ...triggerItem, triggerSource };
|
|
|
|
|
|
|
|
findButton = () => wrapper.findComponent(triggerComponent[triggerItem.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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
describe('side-nav with icon', () => {
|
|
|
|
it('includes the specified icon with correct size when triggerElement is link', () => {
|
|
|
|
const findIcon = () => wrapper.findComponent(GlIcon);
|
|
|
|
|
|
|
|
createComponent({ triggerElement: TRIGGER_ELEMENT_SIDE_NAV, icon: 'plus' });
|
|
|
|
|
|
|
|
expect(findIcon().exists()).toBe(true);
|
|
|
|
expect(findIcon().props('name')).toBe('plus');
|
|
|
|
});
|
|
|
|
});
|