Mimic GWT UI logic for Quick Approve button
Quick approve button is now added when all of the following are met:
- single last approval label is missing
- user can approve label to maximal score
- no one set maximal negative score (rejected)
Bug: Issue 5063
Change-Id: Id76bed7729f6368ad273437a2b1f63a98f051b2c
diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
index 9643e93..b41567c 100644
--- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
+++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html
@@ -505,10 +505,16 @@
element.change = {
current_revision: 'abc1234',
labels: {
- foo: {},
+ foo: {
+ values: {
+ '-1': '',
+ ' 0': '',
+ '+1': '',
+ },
+ },
},
permitted_labels: {
- foo: ['-1', '0', '+1'],
+ foo: ['-1', ' 0', '+1'],
},
};
flushAsynchronousOperations();
@@ -530,10 +536,11 @@
labels: {
foo: {
approved: {},
+ values: {},
},
},
permitted_labels: {
- foo: [],
+ foo: [' 0', '+1'],
},
};
flushAsynchronousOperations();
@@ -545,7 +552,7 @@
element.change = {
current_revision: 'abc1234',
labels: {
- foo: {},
+ foo: {values: {}},
},
permitted_labels: {
bar: [],
@@ -568,12 +575,12 @@
fireActionStub.restore();
});
- test('higher permitted score has priority', function() {
+ test('not added when multiple labels are required', function() {
element.change = {
current_revision: 'abc1234',
labels: {
- foo: {},
- bar: {},
+ foo: {values: {}},
+ bar: {values: {}},
},
permitted_labels: {
foo: [' 0', '+1'],
@@ -582,15 +589,20 @@
};
flushAsynchronousOperations();
var approveButton = element.$$('gr-button[data-action-key=\'review\']');
- assert.equal(approveButton.getAttribute('data-label'), 'bar+2');
+ assert.isNull(approveButton);
});
test('button label for missing approval', function() {
element.change = {
current_revision: 'abc1234',
labels: {
- foo: {},
- bar: {approved: {}},
+ foo: {
+ values: {
+ ' 0': '',
+ '+1': '',
+ },
+ },
+ bar: {approved: {}, values: {}},
},
permitted_labels: {
foo: [' 0', '+1'],
@@ -602,11 +614,18 @@
assert.equal(approveButton.getAttribute('data-label'), 'foo+1');
});
- test('non-approving score', function() {
+ test('no quick approve if score is not maximal for a label', function() {
element.change = {
current_revision: 'abc1234',
labels: {
- bar: {value: 1},
+ bar: {
+ value: 1,
+ values: {
+ ' 0': '',
+ '+1': '',
+ '+2': '',
+ },
+ },
},
permitted_labels: {
bar: [' 0', '+1'],
@@ -621,7 +640,14 @@
element.change = {
current_revision: 'abc1234',
labels: {
- bar: {value: 1},
+ bar: {
+ value: 1,
+ values: {
+ ' 0': '',
+ '+1': '',
+ '+2': '',
+ },
+ },
},
permitted_labels: {
bar: [' 0', '+1', '+2'],