2020-10-24 23:57:45 +05:30
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { GlLink, GlSprintf } from '@gitlab/ui';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-03-13 15:44:24 +05:30
|
|
|
import suggestPipelineComponent from '~/vue_merge_request_widget/components/mr_widget_suggest_pipeline.vue';
|
|
|
|
import MrWidgetIcon from '~/vue_merge_request_widget/components/mr_widget_icon.vue';
|
2020-10-24 23:57:45 +05:30
|
|
|
import dismissibleContainer from '~/vue_shared/components/dismissible_container.vue';
|
|
|
|
import { suggestProps, iconName } from './pipeline_tour_mock_data';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import {
|
|
|
|
SP_TRACK_LABEL,
|
|
|
|
SP_LINK_TRACK_EVENT,
|
|
|
|
SP_SHOW_TRACK_EVENT,
|
|
|
|
SP_LINK_TRACK_VALUE,
|
|
|
|
SP_SHOW_TRACK_VALUE,
|
|
|
|
SP_HELP_URL,
|
|
|
|
} from '~/vue_merge_request_widget/constants';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe('MRWidgetSuggestPipeline', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('template', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('core functionality', () => {
|
|
|
|
const findOkBtn = () => wrapper.find('[data-testid="ok"]');
|
|
|
|
let trackingSpy;
|
|
|
|
let mockAxios;
|
|
|
|
|
|
|
|
const mockTrackingOnWrapper = () => {
|
|
|
|
unmockTracking();
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockAxios = new MockAdapter(axios);
|
|
|
|
document.body.dataset.page = 'projects:merge_requests:show';
|
|
|
|
trackingSpy = mockTracking('_category_', undefined, jest.spyOn);
|
|
|
|
|
|
|
|
wrapper = mount(suggestPipelineComponent, {
|
|
|
|
propsData: suggestProps,
|
|
|
|
stubs: {
|
|
|
|
GlSprintf,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
afterEach(() => {
|
|
|
|
unmockTracking();
|
|
|
|
mockAxios.restore();
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders add pipeline file link', () => {
|
|
|
|
const link = wrapper.find(GlLink);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(link.exists()).toBe(true);
|
|
|
|
expect(link.attributes().href).toBe(suggestProps.pipelinePath);
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders the expected text', () => {
|
|
|
|
const messageText = /\s*No pipeline\s*Add the .gitlab-ci.yml file\s*to create one./;
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(wrapper.text()).toMatch(messageText);
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders widget icon', () => {
|
|
|
|
const icon = wrapper.find(MrWidgetIcon);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(icon.exists()).toBe(true);
|
|
|
|
expect(icon.props()).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
name: iconName,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders the show me how button', () => {
|
|
|
|
const button = findOkBtn();
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(button.exists()).toBe(true);
|
|
|
|
expect(button.classes('btn-info')).toEqual(true);
|
|
|
|
expect(button.attributes('href')).toBe(suggestProps.pipelinePath);
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders the help link', () => {
|
|
|
|
const link = wrapper.find('[data-testid="help"]');
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(link.exists()).toBe(true);
|
|
|
|
expect(link.attributes('href')).toBe(SP_HELP_URL);
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('renders the empty pipelines image', () => {
|
|
|
|
const image = wrapper.find('[data-testid="pipeline-image"]');
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(image.exists()).toBe(true);
|
|
|
|
expect(image.attributes().src).toBe(suggestProps.pipelineSvgPath);
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('tracking', () => {
|
|
|
|
it('send event for basic view of the suggest pipeline widget', () => {
|
|
|
|
const expectedCategory = undefined;
|
|
|
|
const expectedAction = undefined;
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(expectedCategory, expectedAction, {
|
|
|
|
label: SP_TRACK_LABEL,
|
|
|
|
property: suggestProps.humanAccess,
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('send an event when add pipeline link is clicked', () => {
|
|
|
|
mockTrackingOnWrapper();
|
|
|
|
const link = wrapper.find('[data-testid="add-pipeline-link"]');
|
|
|
|
triggerEvent(link.element);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', SP_LINK_TRACK_EVENT, {
|
|
|
|
label: SP_TRACK_LABEL,
|
|
|
|
property: suggestProps.humanAccess,
|
|
|
|
value: SP_LINK_TRACK_VALUE.toString(),
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('send an event when ok button is clicked', () => {
|
|
|
|
mockTrackingOnWrapper();
|
|
|
|
const okBtn = findOkBtn();
|
|
|
|
triggerEvent(okBtn.element);
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(trackingSpy).toHaveBeenCalledWith('_category_', SP_SHOW_TRACK_EVENT, {
|
|
|
|
label: SP_TRACK_LABEL,
|
|
|
|
property: suggestProps.humanAccess,
|
|
|
|
value: SP_SHOW_TRACK_VALUE.toString(),
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
describe('dismissible', () => {
|
|
|
|
const findDismissContainer = () => wrapper.find(dismissibleContainer);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallowMount(suggestPipelineComponent, { propsData: suggestProps });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the dismissal container', () => {
|
|
|
|
expect(findDismissContainer().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits dismiss upon dismissal button click', () => {
|
|
|
|
findDismissContainer().vm.$emit('dismiss');
|
|
|
|
|
|
|
|
expect(wrapper.emitted().dismiss).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|