debian-mirror-gitlab/spec/javascripts/vue_shared/components/commit_spec.js

235 lines
7.2 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
import Vue from 'vue';
2017-09-10 17:25:29 +05:30
import commitComp from '~/vue_shared/components/commit.vue';
2018-10-15 14:42:47 +05:30
import mountComponent from '../../helpers/vue_mount_component_helper';
2017-08-17 22:00:37 +05:30
describe('Commit component', () => {
let props;
let component;
let CommitComponent;
beforeEach(() => {
CommitComponent = Vue.extend(commitComp);
});
2018-10-15 14:42:47 +05:30
afterEach(() => {
component.$destroy();
});
2018-03-17 18:26:18 +05:30
it('should render a fork icon if it does not represent a tag', () => {
2018-10-15 14:42:47 +05:30
component = mountComponent(CommitComponent, {
tag: false,
commitRef: {
name: 'master',
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
},
commitUrl:
'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
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
2018-03-17 18:26:18 +05:30
expect(component.$el.querySelector('.icon-container').children).toContain('svg');
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:
'https://gitlab.com/gitlab-org/gitlab-ce/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',
},
};
2018-10-15 14:42:47 +05:30
component = mountComponent(CommitComponent, props);
2017-08-17 22:00:37 +05:30
});
it('should render a tag icon if it represents a tag', () => {
2019-05-18 00:54:41 +05:30
expect(component.$el.querySelector('.icon-container svg.ic-tag')).not.toBeNull();
2017-08-17 22:00:37 +05:30
});
it('should render a link to the ref url', () => {
2018-10-15 14:42:47 +05:30
expect(component.$el.querySelector('.ref-name').getAttribute('href')).toEqual(
props.commitRef.ref_url,
);
2017-08-17 22:00:37 +05:30
});
it('should render the ref name', () => {
2017-09-10 17:25:29 +05:30
expect(component.$el.querySelector('.ref-name').textContent).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', () => {
2018-10-15 14:42:47 +05:30
expect(component.$el.querySelector('.commit-sha').getAttribute('href')).toEqual(
props.commitUrl,
);
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(component.$el.querySelector('.commit-sha').textContent).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', () => {
expect(
component.$el.querySelector('.js-commit-icon use').getAttribute('xlink:href'),
).toContain('commit');
2017-08-17 22:00:37 +05:30
});
describe('Given commit title and author props', () => {
it('should render a link to the author profile', () => {
expect(
component.$el.querySelector('.commit-title .avatar-image-container').getAttribute('href'),
2017-09-10 17:25:29 +05:30
).toEqual(props.author.path);
2017-08-17 22:00:37 +05:30
});
it('Should render the author avatar with title and alt attributes', () => {
expect(
2018-10-15 14:42:47 +05:30
component.$el
2018-12-13 13:39:08 +05:30
.querySelector('.commit-title .avatar-image-container .js-user-avatar-image-toolip')
.textContent.trim(),
2017-08-17 22:00:37 +05:30
).toContain(props.author.username);
2018-12-13 13:39:08 +05:30
2017-08-17 22:00:37 +05:30
expect(
2018-10-15 14:42:47 +05:30
component.$el
.querySelector('.commit-title .avatar-image-container img')
.getAttribute('alt'),
2017-08-17 22:00:37 +05:30
).toContain(`${props.author.username}'s avatar`);
});
});
it('should render the commit title', () => {
2018-10-15 14:42:47 +05:30
expect(component.$el.querySelector('a.commit-row-message').getAttribute('href')).toEqual(
props.commitUrl,
);
2018-12-13 13:39:08 +05:30
2018-10-15 14:42:47 +05:30
expect(component.$el.querySelector('a.commit-row-message').textContent).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:
'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
2017-08-17 22:00:37 +05:30
shortSha: 'b7836edd',
title: null,
author: {},
};
2018-10-15 14:42:47 +05:30
component = mountComponent(CommitComponent, props);
2017-08-17 22:00:37 +05:30
2018-10-15 14:42:47 +05:30
expect(component.$el.querySelector('.commit-title span').textContent).toContain(
"Can't find HEAD commit for this branch",
);
2017-08-17 22:00:37 +05:30
});
});
2019-05-18 00:54:41 +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:
'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
shortSha: 'b7836edd',
title: null,
author: {},
};
component = mountComponent(CommitComponent, props);
const refEl = component.$el.querySelector('.ref-name');
expect(refEl.textContent).toContain('master');
expect(refEl.href).toBe(props.commitRef.ref_url);
expect(refEl.getAttribute('data-original-title')).toBe(props.commitRef.name);
expect(component.$el.querySelector('.icon-container .ic-branch')).not.toBeNull();
});
});
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:
'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
mergeRequestRef: {
iid: 1234,
path: 'https://example.com/path/to/mr',
title: 'Test MR',
},
shortSha: 'b7836edd',
title: null,
author: {},
};
component = mountComponent(CommitComponent, props);
const refEl = component.$el.querySelector('.ref-name');
expect(refEl.textContent).toContain('1234');
expect(refEl.href).toBe(props.mergeRequestRef.path);
expect(refEl.getAttribute('data-original-title')).toBe(props.mergeRequestRef.title);
expect(component.$el.querySelector('.icon-container .ic-git-merge')).not.toBeNull();
});
});
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:
'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
mergeRequestRef: {
iid: 1234,
path: '/path/to/mr',
title: 'Test MR',
},
shortSha: 'b7836edd',
title: null,
author: {},
showRefInfo: false,
};
component = mountComponent(CommitComponent, props);
expect(component.$el.querySelector('.ref-name')).toBeNull();
});
});
2017-08-17 22:00:37 +05:30
});