summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/admin/gr-rule-editor/gr-rule-editor_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/admin/gr-rule-editor/gr-rule-editor_test.html')
-rw-r--r--polygerrit-ui/app/elements/admin/gr-rule-editor/gr-rule-editor_test.html258
1 files changed, 127 insertions, 131 deletions
diff --git a/polygerrit-ui/app/elements/admin/gr-rule-editor/gr-rule-editor_test.html b/polygerrit-ui/app/elements/admin/gr-rule-editor/gr-rule-editor_test.html
index 3594e4ba44..f85c2b228c 100644
--- a/polygerrit-ui/app/elements/admin/gr-rule-editor/gr-rule-editor_test.html
+++ b/polygerrit-ui/app/elements/admin/gr-rule-editor/gr-rule-editor_test.html
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<!--
+@license
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
@@ -49,16 +50,16 @@ limitations under the License.
suite('unit tests', () => {
test('_computeForce, _computeForceClass, and _computeForceOptions',
() => {
- const FORCE_PUSH_OPTIONS = [
- {
- name: 'No Force Push',
- value: false,
- },
- {
- name: 'Force Push',
- value: true,
- },
- ];
+ const ForcePushOptions = {
+ ALLOW: [
+ {name: 'Allow pushing (but not force pushing)', value: false},
+ {name: 'Allow pushing with or without force', value: true},
+ ],
+ BLOCK: [
+ {name: 'Block pushing with or without force', value: false},
+ {name: 'Block force pushing', value: true},
+ ],
+ };
const FORCE_EDIT_OPTIONS = [
{
@@ -71,10 +72,26 @@ limitations under the License.
},
];
let permission = 'push';
- assert.isTrue(element._computeForce(permission));
- assert.equal(element._computeForceClass(permission), 'force');
- assert.deepEqual(element._computeForceOptions(permission),
- FORCE_PUSH_OPTIONS);
+ let action = 'ALLOW';
+ assert.isTrue(element._computeForce(permission, action));
+ assert.equal(element._computeForceClass(permission, action),
+ 'force');
+ assert.deepEqual(element._computeForceOptions(permission, action),
+ ForcePushOptions.ALLOW);
+
+ action = 'BLOCK';
+ assert.isTrue(element._computeForce(permission, action));
+ assert.equal(element._computeForceClass(permission, action),
+ 'force');
+ assert.deepEqual(element._computeForceOptions(permission, action),
+ ForcePushOptions.BLOCK);
+
+ action = 'DENY';
+ assert.isFalse(element._computeForce(permission, action));
+ assert.equal(element._computeForceClass(permission, action), '');
+ assert.equal(
+ element._computeForceOptions(permission, action).length, 0);
+
permission = 'editTopicName';
assert.isTrue(element._computeForce(permission));
assert.equal(element._computeForceClass(permission), 'force');
@@ -152,11 +169,24 @@ limitations under the License.
});
test('_handleValueChange', () => {
+ const modifiedHandler = sandbox.stub();
+ element.rule = {value: {}};
+ element.addEventListener('access-modified', modifiedHandler);
element._handleValueChange();
- assert.isFalse(element._modified);
+ assert.isNotOk(element.rule.value.modified);
element._originalRuleValues = {};
element._handleValueChange();
- assert.isTrue(element._modified);
+ assert.isTrue(element.rule.value.modified);
+ assert.isTrue(modifiedHandler.called);
+ });
+
+ test('_handleAccessSaved', () => {
+ const originalValue = {action: 'DENY'};
+ const newValue = {action: 'ALLOW'};
+ element._originalRuleValues = originalValue;
+ element.rule = {value: newValue};
+ element._handleAccessSaved();
+ assert.deepEqual(element._originalRuleValues, newValue);
});
test('_setOriginalRuleValues', () => {
@@ -199,22 +229,27 @@ limitations under the License.
assert.isFalse(element.$.force.classList.contains('force'));
});
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
+ test('modify and cancel restores original values', () => {
+ element.editing = true;
+ assert.notEqual(getComputedStyle(element.$.removeBtn).display, 'none');
+ assert.isNotOk(element.rule.value.modified);
+ element.$.action.bindValue = 'DENY';
+ assert.isTrue(element.rule.value.modified);
+ element.editing = false;
+ assert.equal(getComputedStyle(element.$.removeBtn).display, 'none');
+ assert.deepEqual(element._originalRuleValues, element.rule.value);
+ assert.equal(element.$.action.bindValue, 'ALLOW');
+ assert.isNotOk(element.rule.value.modified);
+ });
+
+ test('modify value', () => {
+ assert.isNotOk(element.rule.value.modified);
element.$.action.bindValue = 'DENY';
flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
+ assert.isTrue(element.rule.value.modified);
// The original value should now differ from the rule values.
assert.notDeepEqual(element._originalRuleValues, element.rule.value);
-
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
- assert.equal(element.$.action.bindValue, 'ALLOW');
- assert.isFalse(element._modified);
});
test('all selects are disabled when not in edit mode', () => {
@@ -235,12 +270,39 @@ limitations under the License.
element.$.deletedContainer.classList.contains('deleted'));
MockInteractions.tap(element.$.removeBtn);
assert.isTrue(element.$.deletedContainer.classList.contains('deleted'));
+ assert.isTrue(element._deleted);
assert.isTrue(element.rule.value.deleted);
MockInteractions.tap(element.$.undoRemoveBtn);
+ assert.isFalse(element._deleted);
assert.isNotOk(element.rule.value.deleted);
});
+ test('remove rule and cancel', () => {
+ element.editing = true;
+ assert.notEqual(getComputedStyle(element.$.removeBtn).display, 'none');
+ assert.equal(getComputedStyle(element.$.deletedContainer).display,
+ 'none');
+
+ element.rule = {id: 123, value: {action: 'ALLOW'}};
+ MockInteractions.tap(element.$.removeBtn);
+ assert.notEqual(getComputedStyle(element.$.removeBtn).display, 'none');
+ assert.notEqual(getComputedStyle(element.$.deletedContainer).display,
+ 'none');
+ assert.isTrue(element._deleted);
+ assert.isTrue(element.rule.value.deleted);
+
+ element.editing = false;
+ assert.isFalse(element._deleted);
+ assert.isNotOk(element.rule.value.deleted);
+ assert.isNotOk(element.rule.value.modified);
+
+ assert.deepEqual(element._originalRuleValues, element.rule.value);
+ assert.equal(getComputedStyle(element.$.removeBtn).display, 'none');
+ assert.equal(getComputedStyle(element.$.deletedContainer).display,
+ 'none');
+ });
+
test('_computeGroupPath', () => {
const group = '123';
assert.equal(element._computeGroupPath(group),
@@ -258,38 +320,42 @@ limitations under the License.
element.section = 'refs/*';
element._setupValues(element.rule);
flushAsynchronousOperations();
+ element.rule.value.added = true;
});
test('_ruleValues and _originalRuleValues are set correctly', () => {
// Since the element does not already have default values, they should
// be set. The original values should be set to those too.
- assert.isFalse(element._modified);
+ assert.isNotOk(element.rule.value.modified);
const expectedRuleValue = {
action: 'ALLOW',
force: false,
+ added: true,
};
assert.deepEqual(element.rule.value, expectedRuleValue);
- assert.deepEqual(element._originalRuleValues, expectedRuleValue);
test('values are set correctly', () => {
assert.equal(element.$.action.bindValue, expectedRuleValue.action);
assert.equal(element.$.force.bindValue, expectedRuleValue.action);
});
});
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
+ test('modify value', () => {
+ assert.isNotOk(element.rule.value.modified);
element.$.force.bindValue = true;
flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
+ assert.isTrue(element.rule.value.modified);
// The original value should now differ from the rule values.
assert.notDeepEqual(element._originalRuleValues, element.rule.value);
+ });
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
+ test('remove value', () => {
+ element.editing = true;
+ const removeStub = sandbox.stub();
+ element.addEventListener('added-rule-removed', removeStub);
+ MockInteractions.tap(element.$.removeBtn);
+ flushAsynchronousOperations();
+ assert.isTrue(removeStub.called);
});
});
@@ -333,20 +399,17 @@ limitations under the License.
assert.isFalse(element.$.force.classList.contains('force'));
});
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
+ test('modify value', () => {
+ const removeStub = sandbox.stub();
+ element.addEventListener('added-rule-removed', removeStub);
+ assert.isNotOk(element.rule.value.modified);
Polymer.dom(element.root).querySelector('#labelMin').bindValue = 1;
flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
+ assert.isTrue(element.rule.value.modified);
+ assert.isFalse(removeStub.called);
// The original value should now differ from the rule values.
assert.notDeepEqual(element._originalRuleValues, element.rule.value);
-
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
});
});
@@ -368,21 +431,22 @@ limitations under the License.
element.section = 'refs/*';
element._setupValues(element.rule);
flushAsynchronousOperations();
+ element.rule.value.added = true;
});
test('_ruleValues and _originalRuleValues are set correctly', () => {
// Since the element does not already have default values, they should
// be set. The original values should be set to those too.
- assert.isFalse(element._modified);
+ assert.isNotOk(element.rule.value.modified);
assert.isTrue(element._setDefaultRuleValues.called);
const expectedRuleValue = {
max: element.label.values[element.label.values.length - 1].value,
min: element.label.values[0].value,
action: 'ALLOW',
+ added: true,
};
assert.deepEqual(element.rule.value, expectedRuleValue);
- assert.deepEqual(element._originalRuleValues, expectedRuleValue);
test('values are set correctly', () => {
assert.equal(
element.$.action.bindValue,
@@ -396,20 +460,14 @@ limitations under the License.
});
});
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
+ test('modify value', () => {
+ assert.isNotOk(element.rule.value.modified);
Polymer.dom(element.root).querySelector('#labelMin').bindValue = 1;
flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
+ assert.isTrue(element.rule.value.modified);
// The original value should now differ from the rule values.
assert.notDeepEqual(element._originalRuleValues, element.rule.value);
-
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
});
});
@@ -443,20 +501,14 @@ limitations under the License.
assert.isNotOk(Polymer.dom(element.root).querySelector('#labelMax'));
});
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
+ test('modify value', () => {
+ assert.isNotOk(element.rule.value.modified);
element.$.action.bindValue = false;
flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
+ assert.isTrue(element.rule.value.modified);
// The original value should now differ from the rule values.
assert.notDeepEqual(element._originalRuleValues, element.rule.value);
-
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
});
});
@@ -470,38 +522,33 @@ limitations under the License.
element.section = 'refs/*';
element._setupValues(element.rule);
flushAsynchronousOperations();
+ element.rule.value.added = true;
});
test('_ruleValues and _originalRuleValues are set correctly', () => {
// Since the element does not already have default values, they should
// be set. The original values should be set to those too.
- assert.isFalse(element._modified);
+ assert.isNotOk(element.rule.value.modified);
const expectedRuleValue = {
action: 'ALLOW',
force: false,
+ added: true,
};
assert.deepEqual(element.rule.value, expectedRuleValue);
- assert.deepEqual(element._originalRuleValues, expectedRuleValue);
test('values are set correctly', () => {
assert.equal(element.$.action.bindValue, expectedRuleValue.action);
assert.equal(element.$.force.bindValue, expectedRuleValue.action);
});
});
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
+ test('modify value', () => {
+ assert.isNotOk(element.rule.value.modified);
element.$.force.bindValue = true;
flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
+ assert.isTrue(element.rule.value.modified);
// The original value should now differ from the rule values.
assert.notDeepEqual(element._originalRuleValues, element.rule.value);
-
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
});
});
@@ -535,65 +582,14 @@ limitations under the License.
assert.isNotOk(Polymer.dom(element.root).querySelector('#labelMax'));
});
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
+ test('modify value', () => {
+ assert.isNotOk(element.rule.value.modified);
element.$.action.bindValue = false;
flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
-
- // The original value should now differ from the rule values.
- assert.notDeepEqual(element._originalRuleValues, element.rule.value);
-
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
- });
- });
-
- suite('new edit rule', () => {
- setup(() => {
- element.group = 'Group Name';
- element.permission = 'editTopicName';
- element.rule = {
- id: '123',
- };
- element.section = 'refs/*';
- element._setupValues(element.rule);
- flushAsynchronousOperations();
- });
-
- test('_ruleValues and _originalRuleValues are set correctly', () => {
- // Since the element does not already have default values, they should
- // be set. The original values should be set to those too.
- assert.isFalse(element._modified);
- const expectedRuleValue = {
- action: 'ALLOW',
- force: false,
- };
- assert.deepEqual(element.rule.value, expectedRuleValue);
- assert.deepEqual(element._originalRuleValues, expectedRuleValue);
- test('values are set correctly', () => {
- assert.equal(element.$.action.bindValue, expectedRuleValue.action);
- assert.equal(element.$.force.bindValue, expectedRuleValue.action);
- });
- });
-
- test('modify and undo value', () => {
- assert.isFalse(element._modified);
- assert.isFalse(element.$.undoBtn.classList.contains('modified'));
- element.$.force.bindValue = true;
- flushAsynchronousOperations();
- assert.isTrue(element._modified);
- assert.isTrue(element.$.undoBtn.classList.contains('modified'));
+ assert.isTrue(element.rule.value.modified);
// The original value should now differ from the rule values.
assert.notDeepEqual(element._originalRuleValues, element.rule.value);
-
- // After undoing the change, the original value should get reset.
- MockInteractions.tap(element.$.undoBtn);
- assert.deepEqual(element._originalRuleValues, element.rule.value);
});
});
});