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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.3 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
2020-07-28 23:09:34 +05:30
import PipelineUrlComponent from '~/pipelines/components/pipelines_list/pipeline_url.vue';
2022-06-21 17:19:12 +05:30
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
2022-04-04 11:22:00 +05:30
import { mockPipeline, mockPipelineBranch, mockPipelineTag } from './mock_data';
2020-01-01 13:55:28 +05:30
2021-04-17 20:07:23 +05:30
const projectPath = 'test/test';
2020-01-01 13:55:28 +05:30
describe('Pipeline Url Component', () => {
let wrapper;
2022-04-04 11:22:00 +05:30
const findTableCell = () => wrapper.findByTestId('pipeline-url-table-cell');
const findPipelineUrlLink = () => wrapper.findByTestId('pipeline-url-link');
const findRefName = () => wrapper.findByTestId('merge-request-ref');
const findCommitShortSha = () => wrapper.findByTestId('commit-short-sha');
const findCommitIcon = () => wrapper.findByTestId('commit-icon');
const findCommitIconType = () => wrapper.findByTestId('commit-icon-type');
const findCommitTitleContainer = () => wrapper.findByTestId('commit-title-container');
const findCommitTitle = (commitWrapper) => commitWrapper.find('[data-testid="commit-title"]');
const defaultProps = mockPipeline(projectPath);
2022-05-07 20:08:51 +05:30
const createComponent = (props) => {
2022-04-04 11:22:00 +05:30
wrapper = shallowMountExtended(PipelineUrlComponent, {
2020-07-28 23:09:34 +05:30
propsData: { ...defaultProps, ...props },
2021-02-22 17:27:13 +05:30
provide: {
2021-04-17 20:07:23 +05:30
targetProjectFullPath: projectPath,
2021-02-22 17:27:13 +05:30
},
2020-01-01 13:55:28 +05:30
});
};
afterEach(() => {
wrapper.destroy();
2020-07-28 23:09:34 +05:30
wrapper = null;
2020-01-01 13:55:28 +05:30
});
2022-05-07 20:08:51 +05:30
it('should render pipeline url table cell', () => {
createComponent();
2020-07-28 23:09:34 +05:30
2022-05-07 20:08:51 +05:30
expect(findTableCell().exists()).toBe(true);
});
2022-04-04 11:22:00 +05:30
2022-05-07 20:08:51 +05:30
it('should render a link the provided path and id', () => {
createComponent();
2021-02-22 17:27:13 +05:30
2022-05-07 20:08:51 +05:30
expect(findPipelineUrlLink().attributes('href')).toBe('foo');
2021-03-11 19:13:27 +05:30
2022-05-07 20:08:51 +05:30
expect(findPipelineUrlLink().text()).toBe('#1');
});
2022-04-04 11:22:00 +05:30
2022-05-07 20:08:51 +05:30
it('should render the commit title, commit reference and commit-short-sha', () => {
createComponent({}, true);
2021-03-11 19:13:27 +05:30
2022-05-07 20:08:51 +05:30
const commitWrapper = findCommitTitleContainer();
2022-04-04 11:22:00 +05:30
2022-05-07 20:08:51 +05:30
expect(findCommitTitle(commitWrapper).exists()).toBe(true);
expect(findRefName().exists()).toBe(true);
expect(findCommitShortSha().exists()).toBe(true);
2021-03-11 19:13:27 +05:30
});
2022-06-21 17:19:12 +05:30
describe('commit user avatar', () => {
it('renders when commit author exists', () => {
const pipelineBranch = mockPipelineBranch();
2022-08-27 11:52:29 +05:30
const { avatar_url: imgSrc, name, path } = pipelineBranch.pipeline.commit.author;
2022-06-21 17:19:12 +05:30
createComponent(pipelineBranch);
const component = wrapper.findComponent(UserAvatarLink);
expect(component.exists()).toBe(true);
expect(component.props()).toMatchObject({
imgSize: 16,
2022-08-27 11:52:29 +05:30
imgSrc,
2022-06-21 17:19:12 +05:30
imgAlt: name,
linkHref: path,
tooltipText: name,
});
});
it('does not render when commit author does not exist', () => {
createComponent();
expect(wrapper.findComponent(UserAvatarLink).exists()).toBe(false);
});
});
2022-05-07 20:08:51 +05:30
it('should render commit icon tooltip', () => {
createComponent({}, true);
2022-04-04 11:22:00 +05:30
2022-05-07 20:08:51 +05:30
expect(findCommitIcon().attributes('title')).toBe('Commit');
});
2022-04-04 11:22:00 +05:30
2022-05-07 20:08:51 +05:30
it.each`
pipeline | expectedTitle
${mockPipelineTag()} | ${'Tag'}
${mockPipelineBranch()} | ${'Branch'}
${mockPipeline()} | ${'Merge Request'}
`('should render tooltip $expectedTitle for commit icon type', ({ pipeline, expectedTitle }) => {
createComponent(pipeline, true);
2022-04-04 11:22:00 +05:30
2022-05-07 20:08:51 +05:30
expect(findCommitIconType().attributes('title')).toBe(expectedTitle);
2021-03-11 19:13:27 +05:30
});
2020-01-01 13:55:28 +05:30
});