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