2017-03-17 13:30:32 -04:00
|
|
|
import Vue from 'vue';
|
2017-06-14 09:04:50 -04:00
|
|
|
import commitComp from '~/vue_shared/components/commit.vue';
|
2016-11-10 13:58:35 -05:00
|
|
|
|
|
|
|
describe('Commit component', () => {
|
2016-11-16 06:53:05 -05:00
|
|
|
let props;
|
|
|
|
let component;
|
2017-03-17 13:30:32 -04:00
|
|
|
let CommitComponent;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
CommitComponent = Vue.extend(commitComp);
|
|
|
|
});
|
2016-11-16 06:53:05 -05:00
|
|
|
|
|
|
|
it('should render a code-fork icon if it does not represent a tag', () => {
|
2017-03-17 13:30:32 -04:00
|
|
|
component = new CommitComponent({
|
2016-11-16 06:53:05 -05:00
|
|
|
propsData: {
|
|
|
|
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',
|
|
|
|
},
|
2016-12-08 07:06:49 -05:00
|
|
|
commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
|
|
|
shortSha: 'b7836edd',
|
2016-11-16 06:53:05 -05:00
|
|
|
title: 'Commit message',
|
|
|
|
author: {
|
2017-06-07 23:32:38 -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',
|
|
|
|
},
|
2016-11-10 13:58:35 -05:00
|
|
|
},
|
2017-03-17 13:30:32 -04:00
|
|
|
}).$mount();
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2016-11-16 06:53:05 -05:00
|
|
|
expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-code-fork');
|
|
|
|
});
|
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',
|
|
|
|
},
|
2016-12-08 07:06:49 -05:00
|
|
|
commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
|
|
|
shortSha: 'b7836edd',
|
2016-11-16 06:53:05 -05:00
|
|
|
title: 'Commit message',
|
|
|
|
author: {
|
2017-06-07 23:32:38 -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',
|
|
|
|
},
|
2016-12-08 07:06:49 -05:00
|
|
|
commitIconSvg: '<svg></svg>',
|
2016-11-16 06:53:05 -05:00
|
|
|
};
|
|
|
|
|
2017-03-17 13:30:32 -04:00
|
|
|
component = new CommitComponent({
|
2016-11-16 06:53:05 -05:00
|
|
|
propsData: props,
|
2017-03-17 13:30:32 -04:00
|
|
|
}).$mount();
|
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', () => {
|
|
|
|
expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-tag');
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a link to the ref url', () => {
|
2017-05-11 11:47:44 -04:00
|
|
|
expect(component.$el.querySelector('.ref-name').getAttribute('href')).toEqual(props.commitRef.ref_url);
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the ref name', () => {
|
2017-05-11 11:47:44 -04:00
|
|
|
expect(component.$el.querySelector('.ref-name').textContent).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', () => {
|
2017-05-11 11:47:44 -04:00
|
|
|
expect(component.$el.querySelector('.commit-sha').getAttribute('href')).toEqual(props.commitUrl);
|
|
|
|
expect(component.$el.querySelector('.commit-sha').textContent).toContain(props.shortSha);
|
2016-12-08 07:06:49 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the given commitIconSvg', () => {
|
|
|
|
expect(component.$el.querySelector('.js-commit-icon').children).toContain('svg');
|
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 commit title and author props', () => {
|
2016-12-08 07:06:49 -05:00
|
|
|
it('should render a link to the author profile', () => {
|
2016-11-16 06:53:05 -05:00
|
|
|
expect(
|
2016-11-14 17:37:13 -05:00
|
|
|
component.$el.querySelector('.commit-title .avatar-image-container').getAttribute('href'),
|
2017-06-02 09:24:42 -04:00
|
|
|
).toEqual(props.author.path);
|
2016-11-16 06:53:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should render the author avatar with title and alt attributes', () => {
|
|
|
|
expect(
|
2017-04-15 19:38:07 -04:00
|
|
|
component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('data-original-title'),
|
2016-11-16 06:53:05 -05:00
|
|
|
).toContain(props.author.username);
|
|
|
|
expect(
|
2016-11-14 17:37:13 -05:00
|
|
|
component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('alt'),
|
2016-11-16 06:53:05 -05:00
|
|
|
).toContain(`${props.author.username}'s avatar`);
|
|
|
|
});
|
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
|
2016-11-16 06:53:05 -05:00
|
|
|
it('should render the commit title', () => {
|
|
|
|
expect(
|
2016-11-14 17:37:13 -05:00
|
|
|
component.$el.querySelector('a.commit-row-message').getAttribute('href'),
|
2016-12-08 07:06:49 -05:00
|
|
|
).toEqual(props.commitUrl);
|
2016-11-16 06:53:05 -05:00
|
|
|
expect(
|
2016-11-14 17:37:13 -05:00
|
|
|
component.$el.querySelector('a.commit-row-message').textContent,
|
2016-11-16 06:53:05 -05:00
|
|
|
).toContain(props.title);
|
|
|
|
});
|
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',
|
|
|
|
},
|
2016-12-08 07:06:49 -05:00
|
|
|
commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
|
|
|
|
shortSha: 'b7836edd',
|
2016-11-16 06:53:05 -05:00
|
|
|
title: null,
|
|
|
|
author: {},
|
|
|
|
};
|
|
|
|
|
2017-03-17 13:30:32 -04:00
|
|
|
component = new CommitComponent({
|
2016-11-16 06:53:05 -05:00
|
|
|
propsData: props,
|
2017-03-17 13:30:32 -04:00
|
|
|
}).$mount();
|
2016-11-16 06:53:05 -05:00
|
|
|
|
|
|
|
expect(
|
2016-11-14 17:37:13 -05:00
|
|
|
component.$el.querySelector('.commit-title span').textContent,
|
2016-11-16 06:53:05 -05:00
|
|
|
).toContain('Cant find HEAD commit for this branch');
|
|
|
|
});
|
2016-11-10 13:58:35 -05:00
|
|
|
});
|
|
|
|
});
|