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

144 lines
4.6 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', () => {
expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-tag');
});
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,
);
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
.querySelector('.commit-title .avatar-image-container img')
.getAttribute('data-original-title'),
2017-08-17 22:00:37 +05:30
).toContain(props.author.username);
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,
);
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
});
});
});