2019-12-26 22:10:19 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { GlIcon } from '@gitlab/ui';
|
2019-12-26 22:10:19 +05:30
|
|
|
import CommitComponent from '~/vue_shared/components/commit.vue';
|
|
|
|
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Commit component', () => {
|
|
|
|
let props;
|
2019-12-26 22:10:19 +05:30
|
|
|
let wrapper;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const findIcon = name => {
|
2020-11-24 15:15:51 +05:30
|
|
|
const icons = wrapper.findAll(GlIcon).filter(c => c.attributes('name') === name);
|
2020-03-13 15:44:24 +05:30
|
|
|
return icons.length ? icons.at(0) : icons;
|
|
|
|
};
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const findUserAvatar = () => wrapper.find(UserAvatarLink);
|
|
|
|
|
|
|
|
const createComponent = propsData => {
|
|
|
|
wrapper = shallowMount(CommitComponent, {
|
|
|
|
propsData,
|
|
|
|
});
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
afterEach(() => {
|
2019-12-26 22:10:19 +05:30
|
|
|
wrapper.destroy();
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it('should render a fork icon if it does not represent a tag', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
createComponent({
|
2018-10-15 14:42:47 +05:30
|
|
|
tag: false,
|
|
|
|
commitRef: {
|
|
|
|
name: 'master',
|
|
|
|
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
|
|
|
|
},
|
|
|
|
commitUrl:
|
2019-12-04 20:38:33 +05:30
|
|
|
'https://gitlab.com/gitlab-org/gitlab-foss/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
2018-10-15 14:42:47 +05:30
|
|
|
shortSha: 'b7836edd',
|
|
|
|
title: 'Commit message',
|
|
|
|
author: {
|
|
|
|
avatar_url: 'https://gitlab.com/uploads/-/system/user/avatar/300478/avatar.png',
|
|
|
|
web_url: 'https://gitlab.com/jschatz1',
|
|
|
|
path: '/jschatz1',
|
|
|
|
username: 'jschatz1',
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(
|
|
|
|
wrapper
|
|
|
|
.find('.icon-container')
|
2020-11-24 15:15:51 +05:30
|
|
|
.find(GlIcon)
|
2019-12-26 22:10:19 +05:30
|
|
|
.exists(),
|
|
|
|
).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('Given all the props', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
props = {
|
|
|
|
tag: true,
|
|
|
|
commitRef: {
|
|
|
|
name: 'master',
|
|
|
|
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
commitUrl:
|
2019-12-04 20:38:33 +05:30
|
|
|
'https://gitlab.com/gitlab-org/gitlab-foss/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
2017-08-17 22:00:37 +05:30
|
|
|
shortSha: 'b7836edd',
|
|
|
|
title: 'Commit message',
|
|
|
|
author: {
|
2017-09-10 17:25:29 +05:30
|
|
|
avatar_url: 'https://gitlab.com/uploads/-/system/user/avatar/300478/avatar.png',
|
2017-08-17 22:00:37 +05:30
|
|
|
web_url: 'https://gitlab.com/jschatz1',
|
2017-09-10 17:25:29 +05:30
|
|
|
path: '/jschatz1',
|
2017-08-17 22:00:37 +05:30
|
|
|
username: 'jschatz1',
|
|
|
|
},
|
|
|
|
};
|
2019-12-26 22:10:19 +05:30
|
|
|
createComponent(props);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a tag icon if it represents a tag', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(findIcon('tag').exists()).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a link to the ref url', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.ref-name').attributes('href')).toBe(props.commitRef.ref_url);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the ref name', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.ref-name').text()).toContain(props.commitRef.name);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the commit short sha with a link to the commit url', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.commit-sha').attributes('href')).toEqual(props.commitUrl);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.commit-sha').text()).toContain(props.shortSha);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
it('should render icon for commit', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(findIcon('commit').exists()).toBe(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('Given commit title and author props', () => {
|
|
|
|
it('should render a link to the author profile', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
const userAvatar = findUserAvatar();
|
|
|
|
|
|
|
|
expect(userAvatar.props('linkHref')).toBe(props.author.path);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('Should render the author avatar with title and alt attributes', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
const userAvatar = findUserAvatar();
|
|
|
|
|
|
|
|
expect(userAvatar.exists()).toBe(true);
|
|
|
|
|
|
|
|
expect(userAvatar.props('imgAlt')).toBe(`${props.author.username}'s avatar`);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the commit title', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.commit-row-message').attributes('href')).toEqual(props.commitUrl);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.commit-row-message').text()).toContain(props.title);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When commit title is not provided', () => {
|
|
|
|
it('should render default message', () => {
|
|
|
|
props = {
|
|
|
|
tag: false,
|
|
|
|
commitRef: {
|
|
|
|
name: 'master',
|
|
|
|
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
commitUrl:
|
2019-12-04 20:38:33 +05:30
|
|
|
'https://gitlab.com/gitlab-org/gitlab-foss/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
2017-08-17 22:00:37 +05:30
|
|
|
shortSha: 'b7836edd',
|
|
|
|
title: null,
|
|
|
|
author: {},
|
|
|
|
};
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
createComponent(props);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.commit-title span').text()).toContain(
|
2018-10-15 14:42:47 +05:30
|
|
|
"Can't find HEAD commit for this branch",
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
describe('When commit ref is provided, but merge ref is not', () => {
|
|
|
|
it('should render the commit ref', () => {
|
|
|
|
props = {
|
|
|
|
tag: false,
|
|
|
|
commitRef: {
|
|
|
|
name: 'master',
|
|
|
|
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
|
|
|
|
},
|
|
|
|
commitUrl:
|
2019-12-04 20:38:33 +05:30
|
|
|
'https://gitlab.com/gitlab-org/gitlab-foss/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
2019-07-07 11:18:12 +05:30
|
|
|
shortSha: 'b7836edd',
|
|
|
|
title: null,
|
|
|
|
author: {},
|
|
|
|
};
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
createComponent(props);
|
|
|
|
const refEl = wrapper.find('.ref-name');
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(refEl.text()).toContain('master');
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(refEl.attributes('href')).toBe(props.commitRef.ref_url);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(refEl.attributes('title')).toBe(props.commitRef.name);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(findIcon('branch').exists()).toBe(true);
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When both commit and merge ref are provided', () => {
|
|
|
|
it('should render the merge ref', () => {
|
|
|
|
props = {
|
|
|
|
tag: false,
|
|
|
|
commitRef: {
|
|
|
|
name: 'master',
|
|
|
|
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
|
|
|
|
},
|
|
|
|
commitUrl:
|
2019-12-04 20:38:33 +05:30
|
|
|
'https://gitlab.com/gitlab-org/gitlab-foss/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
2019-07-07 11:18:12 +05:30
|
|
|
mergeRequestRef: {
|
|
|
|
iid: 1234,
|
|
|
|
path: 'https://example.com/path/to/mr',
|
|
|
|
title: 'Test MR',
|
|
|
|
},
|
|
|
|
shortSha: 'b7836edd',
|
|
|
|
title: null,
|
|
|
|
author: {},
|
|
|
|
};
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
createComponent(props);
|
|
|
|
const refEl = wrapper.find('.ref-name');
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(refEl.text()).toContain('1234');
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(refEl.attributes('href')).toBe(props.mergeRequestRef.path);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(refEl.attributes('title')).toBe(props.mergeRequestRef.title);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(findIcon('git-merge').exists()).toBe(true);
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When showRefInfo === false', () => {
|
|
|
|
it('should not render any ref info', () => {
|
|
|
|
props = {
|
|
|
|
tag: false,
|
|
|
|
commitRef: {
|
|
|
|
name: 'master',
|
|
|
|
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
|
|
|
|
},
|
|
|
|
commitUrl:
|
2019-12-04 20:38:33 +05:30
|
|
|
'https://gitlab.com/gitlab-org/gitlab-foss/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
2019-07-07 11:18:12 +05:30
|
|
|
mergeRequestRef: {
|
|
|
|
iid: 1234,
|
|
|
|
path: '/path/to/mr',
|
|
|
|
title: 'Test MR',
|
|
|
|
},
|
|
|
|
shortSha: 'b7836edd',
|
|
|
|
title: null,
|
|
|
|
author: {},
|
|
|
|
showRefInfo: false,
|
|
|
|
};
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
createComponent(props);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find('.ref-name').exists()).toBe(false);
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|