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.

173 lines
5.6 KiB
JavaScript
Raw Normal View History

2023-01-13 00:05:48 +05:30
import { merge } from 'lodash';
2022-10-11 01:57:18 +05:30
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
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-10-11 01:57:18 +05:30
import { TRACKING_CATEGORIES } from '~/pipelines/constants';
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-10-11 01:57:18 +05:30
let trackingSpy;
2020-01-01 13:55:28 +05:30
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');
2022-10-11 01:57:18 +05:30
const findCommitRefName = () => wrapper.findByTestId('commit-ref-name');
2022-04-04 11:22:00 +05:30
const findCommitTitleContainer = () => wrapper.findByTestId('commit-title-container');
2023-01-13 00:05:48 +05:30
const findPipelineNameContainer = () => wrapper.findByTestId('pipeline-name-container');
2022-04-04 11:22:00 +05:30
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
});
};
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
2023-01-13 00:05:48 +05:30
it('should render the pipeline name instead of commit title', () => {
createComponent(merge(mockPipeline(projectPath), { pipeline: { name: 'Build pipeline' } }));
expect(findCommitTitleContainer().exists()).toBe(false);
expect(findPipelineNameContainer().exists()).toBe(true);
expect(findRefName().exists()).toBe(true);
expect(findCommitShortSha().exists()).toBe(true);
});
it('should render the commit title when pipeline has no name', () => {
2022-10-11 01:57:18 +05:30
createComponent();
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);
2023-01-13 00:05:48 +05:30
expect(findPipelineNameContainer().exists()).toBe(false);
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', () => {
2022-10-11 01:57:18 +05:30
createComponent();
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 }) => {
2022-10-11 01:57:18 +05:30
createComponent(pipeline);
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
});
2022-10-11 01:57:18 +05:30
describe('tracking', () => {
beforeEach(() => {
trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
});
afterEach(() => {
unmockTracking();
});
it('tracks pipeline id click', () => {
createComponent();
findPipelineUrlLink().vm.$emit('click');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_pipeline_id', {
label: TRACKING_CATEGORIES.table,
});
});
it('tracks merge request ref click', () => {
createComponent();
findRefName().vm.$emit('click');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_mr_ref', {
label: TRACKING_CATEGORIES.table,
});
});
it('tracks commit ref name click', () => {
createComponent(mockPipelineBranch());
findCommitRefName().vm.$emit('click');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_commit_name', {
label: TRACKING_CATEGORIES.table,
});
});
it('tracks commit title click', () => {
2023-01-13 00:05:48 +05:30
createComponent(merge(mockPipelineBranch(), { pipeline: { name: null } }));
2022-10-11 01:57:18 +05:30
findCommitTitle(findCommitTitleContainer()).vm.$emit('click');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_commit_title', {
label: TRACKING_CATEGORIES.table,
});
});
it('tracks commit short sha click', () => {
createComponent(mockPipelineBranch());
findCommitShortSha().vm.$emit('click');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_commit_sha', {
label: TRACKING_CATEGORIES.table,
});
});
});
2020-01-01 13:55:28 +05:30
});