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