gitlab-org--gitlab-foss/spec/javascripts/vue_shared/components/commit_spec.js

144 lines
4.6 KiB
JavaScript
Raw Normal View History

import Vue from 'vue';
import commitComp from '~/vue_shared/components/commit.vue';
2018-04-14 16:02:04 -04:00
import mountComponent from '../../helpers/vue_mount_component_helper';
describe('Commit component', () => {
let props;
let component;
let CommitComponent;
beforeEach(() => {
CommitComponent = Vue.extend(commitComp);
});
2018-04-14 16:02:04 -04:00
afterEach(() => {
component.$destroy();
});
2017-12-06 13:38:35 -05:00
it('should render a fork icon if it does not represent a tag', () => {
2018-04-14 16:02:04 -04:00
component = mountComponent(CommitComponent, {
tag: false,
commitRef: {
name: 'master',
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
},
2018-04-14 16:02:04 -04:00
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-12-06 13:38:35 -05:00
expect(component.$el.querySelector('.icon-container').children).toContain('svg');
});
describe('Given all the props', () => {
beforeEach(() => {
props = {
tag: true,
2016-12-08 07:06:49 -05:00
commitRef: {
name: 'master',
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
},
2018-04-14 16:02:04 -04:00
commitUrl:
'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
2016-12-08 07:06:49 -05:00
shortSha: 'b7836edd',
title: 'Commit message',
author: {
2017-07-17 09:46:59 -04:00
avatar_url: 'https://gitlab.com/uploads/-/system/user/avatar/300478/avatar.png',
web_url: 'https://gitlab.com/jschatz1',
path: '/jschatz1',
username: 'jschatz1',
},
};
2018-04-14 16:02:04 -04:00
component = mountComponent(CommitComponent, props);
});
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-04-14 16:02:04 -04:00
expect(component.$el.querySelector('.ref-name').getAttribute('href')).toEqual(
2018-04-23 07:34:05 -04:00
props.commitRef.ref_url,
2018-04-14 16:02:04 -04:00
);
});
it('should render the ref name', () => {
expect(component.$el.querySelector('.ref-name').textContent).toContain(props.commitRef.name);
});
it('should render the commit short sha with a link to the commit url', () => {
2018-04-14 16:02:04 -04:00
expect(component.$el.querySelector('.commit-sha').getAttribute('href')).toEqual(
2018-04-23 07:34:05 -04:00
props.commitUrl,
2018-04-14 16:02:04 -04:00
);
expect(component.$el.querySelector('.commit-sha').textContent).toContain(props.shortSha);
2016-12-08 07:06:49 -05:00
});
it('should render icon for commit', () => {
expect(
2018-04-23 07:34:05 -04:00
component.$el.querySelector('.js-commit-icon use').getAttribute('xlink:href'),
).toContain('commit');
});
describe('Given commit title and author props', () => {
2016-12-08 07:06:49 -05:00
it('should render a link to the author profile', () => {
expect(
2018-04-23 07:34:05 -04:00
component.$el.querySelector('.commit-title .avatar-image-container').getAttribute('href'),
).toEqual(props.author.path);
});
it('Should render the author avatar with title and alt attributes', () => {
expect(
2018-04-14 16:02:04 -04:00
component.$el
.querySelector('.commit-title .avatar-image-container img')
2018-04-23 07:34:05 -04:00
.getAttribute('data-original-title'),
).toContain(props.author.username);
expect(
2018-04-14 16:02:04 -04:00
component.$el
.querySelector('.commit-title .avatar-image-container img')
2018-04-23 07:34:05 -04:00
.getAttribute('alt'),
).toContain(`${props.author.username}'s avatar`);
});
});
it('should render the commit title', () => {
2018-04-14 16:02:04 -04:00
expect(component.$el.querySelector('a.commit-row-message').getAttribute('href')).toEqual(
2018-04-23 07:34:05 -04:00
props.commitUrl,
2018-04-14 16:02:04 -04:00
);
expect(component.$el.querySelector('a.commit-row-message').textContent).toContain(
2018-04-23 07:34:05 -04:00
props.title,
2018-04-14 16:02:04 -04:00
);
});
});
describe('When commit title is not provided', () => {
2016-12-08 07:06:49 -05:00
it('should render default message', () => {
props = {
tag: false,
2016-12-08 07:06:49 -05:00
commitRef: {
name: 'master',
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
},
2018-04-14 16:02:04 -04:00
commitUrl:
'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
2016-12-08 07:06:49 -05:00
shortSha: 'b7836edd',
title: null,
author: {},
};
2018-04-14 16:02:04 -04:00
component = mountComponent(CommitComponent, props);
2018-04-14 16:02:04 -04:00
expect(component.$el.querySelector('.commit-title span').textContent).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
);
});
});
});