Merge "Update gr-rule-editor"

This commit is contained in:
Becky Siegel
2017-12-12 18:54:16 +00:00
committed by Gerrit Code Review
2 changed files with 45 additions and 0 deletions

View File

@@ -56,6 +56,7 @@
editing: {
type: Boolean,
value: false,
observer: '_handleEditingChanged',
},
groupId: String,
groupName: String,
@@ -87,6 +88,10 @@
'_handleValueChange(rule.value.*)',
],
listeners: {
'access-saved': '_handleAccessSaved',
},
ready() {
// Called on ready rather than the observer because when new rules are
// added, the observer is triggered prior to being ready.
@@ -114,6 +119,21 @@
return `${this.getBaseUrl()}/admin/groups/${this.encodeURL(group, true)}`;
},
_handleAccessSaved() {
// Set a new 'original' value to keep track of after the value has been
// saved.
this._setOriginalRuleValues(this.rule.value);
},
_handleEditingChanged(editing, editingOld) {
// Ignore when editing gets set initially.
if (!editingOld) { return; }
// Restore original values if no longer editing.
if (!editing) {
this._handleUndoChange();
}
},
_computeSectionClass(editing, deleted) {
const classList = [];
if (editing) {
@@ -179,6 +199,8 @@
_handleValueChange() {
if (!this._originalRuleValues) { return; }
this._modified = true;
// Allows overall access page to know a change has been made.
this.dispatchEvent(new CustomEvent('access-modified', {bubbles: true}));
},
_setOriginalRuleValues(value) {

View File

@@ -152,11 +152,23 @@ limitations under the License.
});
test('_handleValueChange', () => {
const modifiedHandler = sandbox.stub();
element.addEventListener('access-modified', modifiedHandler);
element._handleValueChange();
assert.isFalse(element._modified);
element._originalRuleValues = {};
element._handleValueChange();
assert.isTrue(element._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,6 +211,17 @@ limitations under the License.
assert.isFalse(element.$.force.classList.contains('force'));
});
test('modify and cancel restores original values', () => {
element.editing = true;
assert.isFalse(element._modified);
element.$.action.bindValue = 'DENY';
assert.isTrue(element._modified);
element.editing = false;
assert.deepEqual(element._originalRuleValues, element.rule.value);
assert.equal(element.$.action.bindValue, 'ALLOW');
assert.isFalse(element._modified);
});
test('modify and undo value', () => {
assert.isFalse(element._modified);
assert.isFalse(element.$.undoBtn.classList.contains('modified'));