debian-mirror-gitlab/spec/frontend/pipelines/pipeline_triggerer_spec.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { shallowMount } from '@vue/test-utils';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
2019-07-31 22:56:46 +05:30
import pipelineTriggerer from '~/pipelines/components/pipeline_triggerer.vue';
describe('Pipelines Triggerer', () => {
let wrapper;
2020-01-01 13:55:28 +05:30
const expectComponentWithProps = (Component, props = {}) => {
const componentWrapper = wrapper.find(Component);
expect(componentWrapper.isVisible()).toBe(true);
expect(componentWrapper.props()).toEqual(expect.objectContaining(props));
};
2019-07-31 22:56:46 +05:30
const mockData = {
pipeline: {
user: {
name: 'foo',
avatar_url: '/avatar',
path: '/path',
},
},
};
const createComponent = () => {
2020-01-01 13:55:28 +05:30
wrapper = shallowMount(pipelineTriggerer, {
2019-07-31 22:56:46 +05:30
propsData: mockData,
2019-12-26 22:10:19 +05:30
sync: false,
2020-01-01 13:55:28 +05:30
attachToDocument: true,
2019-07-31 22:56:46 +05:30
});
};
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
it('should render a table cell', () => {
expect(wrapper.contains('.table-section')).toBe(true);
});
2020-01-01 13:55:28 +05:30
it('should pass triggerer information when triggerer is provided', () => {
expectComponentWithProps(UserAvatarLink, {
linkHref: mockData.pipeline.user.path,
tooltipText: mockData.pipeline.user.name,
imgSrc: mockData.pipeline.user.avatar_url,
});
2019-07-31 22:56:46 +05:30
});
it('should render "API" when no triggerer is provided', () => {
wrapper.setProps({
pipeline: {
user: null,
},
});
2020-01-01 13:55:28 +05:30
return wrapper.vm.$nextTick(() => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.js-pipeline-url-api').text()).toEqual('API');
});
2019-07-31 22:56:46 +05:30
});
});