Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
f55206ce
Commit
f55206ce
authored
Nov 16, 2016
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds missing tests for commit component
parent
b210cbca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
69 deletions
+108
-69
app/assets/javascripts/vue_common_component/commit.js.es6
app/assets/javascripts/vue_common_component/commit.js.es6
+1
-1
spec/javascripts/vue_common_components/commit_spec.js.es6
spec/javascripts/vue_common_components/commit_spec.js.es6
+107
-68
No files found.
app/assets/javascripts/vue_common_component/commit.js.es6
View file @
f55206ce
...
@@ -133,7 +133,7 @@
...
@@ -133,7 +133,7 @@
<div v-if="hasRef" class="icon-container">
<div v-if="hasRef" class="icon-container">
<i v-if="tag" class="fa fa-tag"></i>
<i v-if="tag" class="fa fa-tag"></i>
<i v-
else
class="fa fa-code-fork"></i>
<i v-
if="!tag"
class="fa fa-code-fork"></i>
</div>
</div>
<a v-if="hasRef"
<a v-if="hasRef"
...
...
spec/javascripts/vue_common_components/commit_spec.js.es6
View file @
f55206ce
/*= require vue_common_components/commit */
//= require vue_common_component/commit
/* eslint-disable */
describe('Commit component', () => {
describe('Commit component', () => {
const getRenderedText = (Component, propsData) => {
const Constructor = Vue.extend(Component);
const vm = new Constructor({propsData}).$mount();
return vm.$el.textContent;
};
const MyComponent = window.gl.commitComponent;
let props;
let component;
it('should render a code-fork icon if it does not represent a tag', () => {
fixture.set('<div class="test-commit-container"></div>');
component = new window.gl.CommitComponent({
el: document.querySelector('.test-commit-container'),
propsData: {
tag: false,
ref: {
name: 'master',
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
},
commit_url: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
short_sha: 'b7836edd',
title: 'Commit message',
author: {
avatar_url: 'https://gitlab.com/uploads/user/avatar/300478/avatar.png',
web_url: 'https://gitlab.com/jschatz1',
username: 'jschatz1',
},
},
});
expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-code-fork');
});
describe('When `ref` is provided', () => {
describe('Given all the props', () => {
const props = {
beforeEach(() => {
fixture.set('<div class="test-commit-container"></div>');
props = {
tag: true,
tag: true,
ref: {
ref: {
name: 'master',
name: 'master',
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master'
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
},
},
commit_url: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
commit_url: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
short_sha: 'b7836edd',
short_sha: 'b7836edd',
...
@@ -23,67 +46,83 @@ describe('Commit component', () => {
...
@@ -23,67 +46,83 @@ describe('Commit component', () => {
author: {
author: {
avatar_url: 'https://gitlab.com/uploads/user/avatar/300478/avatar.png',
avatar_url: 'https://gitlab.com/uploads/user/avatar/300478/avatar.png',
web_url: 'https://gitlab.com/jschatz1',
web_url: 'https://gitlab.com/jschatz1',
username: 'jschatz1'
username: 'jschatz1',
}
},
};
};
it('should render a tag icon if it represents a tag', () => {
component = new window.gl.CommitComponent({
const renderedText = getRenderedText(MyComponent, props);
el: document.querySelector('.test-commit-container'),
propsData: props,
});
});
});
it('should render a
code-fork icon if it does not represent
a tag', () => {
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', () => {
it('should render a link to the ref url', () => {
expect(component.$el.querySelector('.branch-name').getAttribute('href')).toEqual(props.ref.ref_url);
});
});
it('should render the ref name', () => {
it('should render the ref name', () => {
expect(component.$el.querySelector('.branch-name').textContent).toContain(props.ref.name);
});
});
});
});
it('should render the commit icon as an svg', () => {
it('should render the commit short sha with a link to the commit url', () => {
expect(component.$el.querySelector('.commit-id').getAttribute('href')).toEqual(props.commit_url);
});
expect(component.$el.querySelector('.commit-id').textContent).toContain(props.short_sha);
});
it('should render the commit short sha with a link to the commit url', () => {
});
describe('Given commit title and author props', () => {
describe('Given commit title and author props', () => {
it('Should render a link to the author profile', () => {
it('Should render a link to the author profile', () => {
expect(
component.$el.querySelector('.commit-title .avatar-image-container').getAttribute('href')
).toEqual(props.author.web_url);
});
});
it('Should render the author avatar with title and alt attributes', () => {
it('Should render the author avatar with title and alt attributes', () => {
expect(
component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('title')
).toContain(props.author.username);
expect(
component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('alt')
).toContain(`${props.author.username}'s avatar`);
});
});
});
describe('When commit title is not provided', () => {
it('Should render default message', () => {
});
});
});
describe('Given no ref prop', () => {
it('Should render without errors', () => {
it('should render the commit title', () => {
expect(
component.$el.querySelector('a.commit-row-message').getAttribute('href')
).toEqual(props.commit_url);
expect(
component.$el.querySelector('a.commit-row-message').textContent
).toContain(props.title);
});
});
});
});
describe('Given no title prop', () => {
describe('When commit title is not provided', () => {
it('Should render without errors', () => {
it('Should render default message', () => {
fixture.set('<div class="test-commit-container"></div>');
props = {
tag: false,
ref: {
name: 'master',
ref_url: 'http://localhost/namespace2/gitlabhq/tree/master',
},
commit_url: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067',
short_sha: 'b7836edd',
title: null,
author: {},
};
component = new window.gl.CommitComponent({
el: document.querySelector('.test-commit-container'),
propsData: props,
});
});
});
describe('Given no author prop', () => {
it('Should render without errors', () => {
expect(
component.$el.querySelector('.commit-title span').textContent
).toContain('Cant find HEAD commit for this branch');
});
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment