2020-03-13 15:44:24 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { GlLink } from '@gitlab/ui';
|
|
|
|
import suggestPipelineComponent from '~/vue_merge_request_widget/components/mr_widget_suggest_pipeline.vue';
|
2020-04-08 14:13:33 +05:30
|
|
|
import stubChildren from 'helpers/stub_children';
|
|
|
|
import PipelineTourState from '~/vue_merge_request_widget/components/states/mr_widget_pipeline_tour.vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
import MrWidgetIcon from '~/vue_merge_request_widget/components/mr_widget_icon.vue';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { mockTracking, triggerEvent, unmockTracking } from 'helpers/tracking_helper';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
describe('MRWidgetHeader', () => {
|
|
|
|
let wrapper;
|
|
|
|
const pipelinePath = '/foo/bar/add/pipeline/path';
|
2020-04-08 14:13:33 +05:30
|
|
|
const pipelineSvgPath = '/foo/bar/pipeline/svg/path';
|
|
|
|
const humanAccess = 'maintainer';
|
2020-03-13 15:44:24 +05:30
|
|
|
const iconName = 'status_notfound';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mount(suggestPipelineComponent, {
|
2020-04-08 14:13:33 +05:30
|
|
|
propsData: { pipelinePath, pipelineSvgPath, humanAccess },
|
|
|
|
stubs: {
|
|
|
|
...stubChildren(PipelineTourState),
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
it('renders add pipeline file link', () => {
|
|
|
|
const link = wrapper.find(GlLink);
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(link.exists()).toBe(true);
|
|
|
|
expect(link.attributes().href).toBe(pipelinePath);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the expected text', () => {
|
|
|
|
const messageText = /\s*No pipeline\s*Add the .gitlab-ci.yml file\s*to create one./;
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(wrapper.text()).toMatch(messageText);
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders widget icon', () => {
|
|
|
|
const icon = wrapper.find(MrWidgetIcon);
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(icon.exists()).toBe(true);
|
|
|
|
expect(icon.props()).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
name: iconName,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tracking', () => {
|
|
|
|
let spy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
unmockTracking();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('send an event when ok button is clicked', () => {
|
|
|
|
const link = wrapper.find(GlLink);
|
|
|
|
triggerEvent(link.element);
|
|
|
|
|
|
|
|
expect(spy).toHaveBeenCalledWith('_category_', 'click_link', {
|
|
|
|
label: 'no_pipeline_noticed',
|
|
|
|
property: humanAccess,
|
|
|
|
value: '30',
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|