Commit cdf5a6e3 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'jivl-fix-extra-by-approvals' into 'master'

Fix extra by on the mr_widget approvals body

Closes #4988

See merge request gitlab-org/gitlab-ee!5105
parents 1b67593b 1f06d072
...@@ -45,12 +45,27 @@ export default { ...@@ -45,12 +45,27 @@ export default {
}, },
computed: { computed: {
approvalsRequiredStringified() { approvalsRequiredStringified() {
let approvedString = s__('MergeRequest|Approved'); if (this.approvalsLeft === 0) {
if (this.approvalsLeft >= 1) { return s__('mrWidget|Approved');
approvedString = sprintf(n__('mrWidget|Requires 1 more approval by',
'MergeRequest|Requires %d more approvals by', this.approvalsLeft));
} }
return approvedString;
if (this.suggestedApprovers.length >= 1) {
return sprintf(
n__(
'mrWidget|Requires 1 more approval by',
'mrWidget|Requires %d more approvals by',
this.approvalsLeft,
),
);
}
return sprintf(
n__(
'mrWidget|Requires 1 more approval',
'mrWidget|Requires %d more approvals',
this.approvalsLeft,
),
);
}, },
approveButtonText() { approveButtonText() {
let approveButtonText = s__('mrWidget|Approve'); let approveButtonText = s__('mrWidget|Approve');
...@@ -74,8 +89,9 @@ export default { ...@@ -74,8 +89,9 @@ export default {
methods: { methods: {
approveMergeRequest() { approveMergeRequest() {
this.approving = true; this.approving = true;
this.service.approveMergeRequest() this.service
.then((data) => { .approveMergeRequest()
.then(data => {
this.mr.setApprovals(data); this.mr.setApprovals(data);
eventHub.$emit('MRWidgetUpdateRequested'); eventHub.$emit('MRWidgetUpdateRequested');
this.approving = false; this.approving = false;
......
...@@ -41,12 +41,12 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr ...@@ -41,12 +41,12 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr
}); });
} }
describe('Approvals Body Component', function () { describe('Approvals Body Component', function() {
beforeEach(function () { beforeEach(function() {
initApprovalsBodyComponent.call(this); initApprovalsBodyComponent.call(this);
}); });
it('should correctly set component props', function () { it('should correctly set component props', function() {
const approvalsBody = this.approvalsBody; const approvalsBody = this.approvalsBody;
_.each(approvalsBody, (propValue, propKey) => { _.each(approvalsBody, (propValue, propKey) => {
if (this.initialData[propKey]) { if (this.initialData[propKey]) {
...@@ -55,14 +55,14 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr ...@@ -55,14 +55,14 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr
}); });
}); });
describe('Computed properties', function () { describe('Computed properties', function() {
describe('approvalsRequiredStringified', function () { describe('approvalsRequiredStringified', function() {
it('should display the correct string for 1 possible approver', function () { it('should display the correct string for 1 possible approver', function() {
const correctText = 'Requires 1 more approval by'; const correctText = 'Requires 1 more approval by';
expect(this.approvalsBody.approvalsRequiredStringified).toBe(correctText); expect(this.approvalsBody.approvalsRequiredStringified).toBe(correctText);
}); });
it('should display the correct string for 2 possible approvers', function (done) { it('should display the correct string for 2 possible approvers', function(done) {
this.approvalsBody.approvalsLeft = 2; this.approvalsBody.approvalsLeft = 2;
this.approvalsBody.suggestedApprovers.push({ name: 'Approver 2' }); this.approvalsBody.suggestedApprovers.push({ name: 'Approver 2' });
...@@ -73,7 +73,7 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr ...@@ -73,7 +73,7 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr
}); });
}); });
it('shows the "Approved" text message when there is enough approvals in place', function (done) { it('shows the "Approved" text message when there is enough approvals in place', function(done) {
this.approvalsBody.approvalsLeft = 0; this.approvalsBody.approvalsLeft = 0;
Vue.nextTick(() => { Vue.nextTick(() => {
...@@ -81,10 +81,20 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr ...@@ -81,10 +81,20 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr
done(); done();
}); });
}); });
it('shows the "Requires 1 more approval" without by when no suggested approvals are available', function(done) {
const correctText = 'Requires 1 more approval';
this.approvalsBody.suggestedApprovers = [];
Vue.nextTick(() => {
expect(this.approvalsBody.approvalsRequiredStringified).toBe(correctText);
done();
});
});
}); });
describe('showApproveButton', function () { describe('showApproveButton', function() {
it('should not be true when the user cannot approve', function (done) { it('should not be true when the user cannot approve', function(done) {
this.approvalsBody.userCanApprove = false; this.approvalsBody.userCanApprove = false;
this.approvalsBody.userHasApproved = true; this.approvalsBody.userHasApproved = true;
Vue.nextTick(() => { Vue.nextTick(() => {
...@@ -93,7 +103,7 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr ...@@ -93,7 +103,7 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr
}); });
}); });
it('should be true when the user can approve', function (done) { it('should be true when the user can approve', function(done) {
this.approvalsBody.userCanApprove = true; this.approvalsBody.userCanApprove = true;
this.approvalsBody.userHasApproved = false; this.approvalsBody.userHasApproved = false;
Vue.nextTick(() => { Vue.nextTick(() => {
...@@ -103,8 +113,8 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr ...@@ -103,8 +113,8 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr
}); });
}); });
describe('approveButtonText', function () { describe('approveButtonText', function() {
it('The approve button should have the "Approve" text', function (done) { it('The approve button should have the "Approve" text', function(done) {
this.approvalsBody.approvalsLeft = 1; this.approvalsBody.approvalsLeft = 1;
this.approvalsBody.userHasApproved = false; this.approvalsBody.userHasApproved = false;
this.approvalsBody.userCanApprove = true; this.approvalsBody.userCanApprove = true;
...@@ -115,7 +125,7 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr ...@@ -115,7 +125,7 @@ import ApprovalsBody from 'ee/vue_merge_request_widget/components/approvals/appr
}); });
}); });
it('The approve button should have the "Add approval" text', function (done) { it('The approve button should have the "Add approval" text', function(done) {
this.approvalsBody.approvalsLeft = 0; this.approvalsBody.approvalsLeft = 0;
this.approvalsBody.userHasApproved = false; this.approvalsBody.userHasApproved = false;
this.approvalsBody.userCanApprove = true; this.approvalsBody.userCanApprove = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment