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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
44fa842f
Commit
44fa842f
authored
Dec 16, 2016
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve logic for stringified approvers, get tests passing.
parent
917496be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
12 deletions
+27
-12
app/assets/javascripts/merge_request_widget/approvals/components/approvals_body.js.es6
...request_widget/approvals/components/approvals_body.js.es6
+17
-5
spec/javascripts/approvals/approvals_body_spec.js.es6
spec/javascripts/approvals/approvals_body_spec.js.es6
+10
-7
No files found.
app/assets/javascripts/merge_request_widget/approvals/components/approvals_body.js.es6
View file @
44fa842f
...
@@ -13,12 +13,24 @@
...
@@ -13,12 +13,24 @@
approverNamesStringified() {
approverNamesStringified() {
const approvers = this.suggestedApprovers;
const approvers = this.suggestedApprovers;
if (approvers && approvers.length) {
if (approvers && approvers.length) {
const lastIdx = approvers.length - 1;
if (approvers.length === 1) {
return approvers[0].name;
}
const lastIndex = approvers.length - 1;
const nextToLastIndex = approvers.length - 2;
return approvers.reduce((memo, curr, index) => {
return approvers.reduce((memo, curr, index) => {
const userDisplayName = curr.name;
let suffix;
const newList = index !== lastIdx ? `${memo} ${userDisplayName}, ` :
`${memo} or ${userDisplayName}`;
if (index === nextToLastIndex) {
return newList;
suffix = ' or ';
} else if (index === lastIndex) {
suffix = '';
} else {
suffix = ', ';
}
const nameToAdd = `${curr.name}${suffix}`;
return `${memo}${nameToAdd}`;
}, '');
}, '');
}
}
return null;
return null;
...
...
spec/javascripts/approvals/approvals_body_spec.js.es6
View file @
44fa842f
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
`);
`);
this.initialData = {
this.initialData = {
suggestedApprovers: [
'Approver 1'
],
suggestedApprovers: [
{ name: 'Approver 1' }
],
userCanApprove: false,
userCanApprove: false,
userHasApproved: true,
userHasApproved: true,
approvedBy: [],
approvedBy: [],
...
@@ -65,7 +65,7 @@
...
@@ -65,7 +65,7 @@
it('should display the correct string for 2 possible approver', function (done) {
it('should display the correct string for 2 possible approver', function (done) {
this.approvalsBody.approvalsLeft = 2;
this.approvalsBody.approvalsLeft = 2;
this.approvalsBody.suggestedApprovers.push(
'Approver 2'
);
this.approvalsBody.suggestedApprovers.push(
{ name: 'Approver 2' }
);
Vue.nextTick(() => {
Vue.nextTick(() => {
const correctText = '2 more approvals';
const correctText = '2 more approvals';
...
@@ -77,14 +77,17 @@
...
@@ -77,14 +77,17 @@
describe('approverNamesStringified', function () {
describe('approverNamesStringified', function () {
// Preceded by: Requires {one more approval} required from _____
// Preceded by: Requires {one more approval} required from _____
it('should display the correct string for 1 possible approver name', function () {
it('should display the correct string for 1 possible approver name', function (
done
) {
const correctText = 'Approver 1';
const correctText = 'Approver 1';
expect(this.approvalsBody.approverNamesStringified).toBe(correctText);
Vue.nextTick(() => {
expect(this.approvalsBody.approverNamesStringified).toBe(correctText);
done();
});
});
});
it('should display the correct string for 2 possible approver names', function (done) {
it('should display the correct string for 2 possible approver names', function (done) {
this.approvalsBody.approvalsLeft = 2;
this.approvalsBody.approvalsLeft = 2;
this.approvalsBody.suggestedApprovers.push(
'Approver 2'
);
this.approvalsBody.suggestedApprovers.push(
{ name: 'Approver 2' }
);
Vue.nextTick(() => {
Vue.nextTick(() => {
const correctText = 'Approver 1 or Approver 2';
const correctText = 'Approver 1 or Approver 2';
...
@@ -95,8 +98,8 @@
...
@@ -95,8 +98,8 @@
it('should display the correct string for 3 possible approver names', function (done) {
it('should display the correct string for 3 possible approver names', function (done) {
this.approvalsBody.approvalsLeft = 3;
this.approvalsBody.approvalsLeft = 3;
this.approvalsBody.suggestedApprovers.push(
'Approver 2'
);
this.approvalsBody.suggestedApprovers.push(
{ name: 'Approver 2' }
);
this.approvalsBody.suggestedApprovers.push(
'Approver 3'
);
this.approvalsBody.suggestedApprovers.push(
{ name: 'Approver 3' }
);
Vue.nextTick(() => {
Vue.nextTick(() => {
const correctText = 'Approver 1, Approver 2 or Approver 3';
const correctText = 'Approver 1, Approver 2 or Approver 3';
...
...
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