summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/admin/gr-access-section/gr-access-section_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/admin/gr-access-section/gr-access-section_test.html')
-rw-r--r--polygerrit-ui/app/elements/admin/gr-access-section/gr-access-section_test.html146
1 files changed, 115 insertions, 31 deletions
diff --git a/polygerrit-ui/app/elements/admin/gr-access-section/gr-access-section_test.html b/polygerrit-ui/app/elements/admin/gr-access-section/gr-access-section_test.html
index 38c5d6739a..21a426f2bf 100644
--- a/polygerrit-ui/app/elements/admin/gr-access-section/gr-access-section_test.html
+++ b/polygerrit-ui/app/elements/admin/gr-access-section/gr-access-section_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");
@@ -88,12 +89,12 @@ limitations under the License.
default_value: 0,
},
};
- element._sectionChanged(element.section);
+ element._updateSection(element.section);
flushAsynchronousOperations();
});
- test('_sectionChanged', () => {
- // _sectionChanged was called in setup, so just make assertions.
+ test('_updateSection', () => {
+ // _updateSection was called in setup, so just make assertions.
const expectedPermissions = [
{
id: 'read',
@@ -128,6 +129,13 @@ limitations under the License.
expectedLabelOptions);
});
+ test('_handleAccessSaved', () => {
+ assert.equal(element._originalId, 'refs/*');
+ element.section.id = 'refs/for/bar';
+ element._handleAccessSaved();
+ assert.equal(element._originalId, 'refs/for/bar');
+ });
+
test('_computePermissions', () => {
sandbox.stub(element, 'toSortedArray').returns(
[{
@@ -257,42 +265,44 @@ limitations under the License.
assert.isFalse(element._editingRef);
});
- test('_handleEditReference', () => {
- element._handleEditReference();
+ test('editReference', () => {
+ element.editReference();
assert.isTrue(element._editingRef);
});
- test('_undoReferenceEdit', () => {
- element._originalId = 'refs/for/old';
- element.section.id = 'refs/for/new';
- element.editing = true;
- element._undoReferenceEdit();
- assert.isFalse(element._editingRef);
- assert.equal(element.section.id, 'refs/for/old');
- });
-
test('_computeSectionClass', () => {
let editingRef = false;
+ let canUpload = false;
+ let ownerOf = [];
let editing = false;
let deleted = false;
- assert.equal(element._computeSectionClass(editing, editingRef, deleted),
- '');
+ assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
+ editingRef, deleted), '');
editing = true;
- assert.equal(element._computeSectionClass(editing, editingRef, deleted),
- 'editing');
+ assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
+ editingRef, deleted), '');
+
+ ownerOf = ['refs/*'];
+ assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
+ editingRef, deleted), 'editing');
+
+ ownerOf = [];
+ canUpload = true;
+ assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
+ editingRef, deleted), 'editing');
editingRef = true;
- assert.equal(element._computeSectionClass(editing, editingRef, deleted),
- 'editing editingRef');
+ assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
+ editingRef, deleted), 'editing editingRef');
deleted = true;
- assert.equal(element._computeSectionClass(editing, editingRef, deleted),
- 'editing editingRef deleted');
+ assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
+ editingRef, deleted), 'editing editingRef deleted');
editingRef = false;
- assert.equal(element._computeSectionClass(editing, editingRef, deleted),
- 'editing deleted');
+ assert.equal(element._computeSectionClass(editing, canUpload, ownerOf,
+ editingRef, deleted), 'editing deleted');
});
test('_computeEditBtnClass', () => {
@@ -348,7 +358,7 @@ limitations under the License.
name: 'Create Account',
},
};
- element._sectionChanged(element.section);
+ element._updateSection(element.section);
flushAsynchronousOperations();
});
@@ -356,6 +366,10 @@ limitations under the License.
assert.isFalse(element.$.section.classList.contains('editing'));
assert.isFalse(element.$.section.classList.contains('deleted'));
assert.isTrue(element.$.editBtn.classList.contains('global'));
+ element.editing = true;
+ element.canUpload = true;
+ element.ownerOf = [];
+ assert.equal(getComputedStyle(element.$.editBtn).display, 'none');
});
});
@@ -372,7 +386,7 @@ limitations under the License.
},
};
element.capabilities = {};
- element._sectionChanged(element.section);
+ element._updateSection(element.section);
flushAsynchronousOperations();
});
@@ -380,9 +394,15 @@ limitations under the License.
assert.isFalse(element.$.section.classList.contains('editing'));
assert.isFalse(element.$.section.classList.contains('deleted'));
assert.isFalse(element.$.editBtn.classList.contains('global'));
+ element.editing = true;
+ element.canUpload = true;
+ element.ownerOf = [];
+ flushAsynchronousOperations();
+ assert.notEqual(getComputedStyle(element.$.editBtn).display, 'none');
});
test('add permission', () => {
+ element.editing = true;
element.$.permissionSelect.value = 'label-Code-Review';
assert.equal(element._permissions.length, 1);
assert.equal(Object.keys(element.section.value.permissions).length,
@@ -396,6 +416,7 @@ limitations under the License.
let permission = {
id: 'label-Code-Review',
value: {
+ added: true,
label: 'Code-Review',
rules: {},
},
@@ -408,7 +429,6 @@ limitations under the License.
element.section.value.permissions['label-Code-Review'],
permission.value);
-
element.$.permissionSelect.value = 'abandon';
MockInteractions.tap(element.$.addBtn);
flushAsynchronousOperations();
@@ -416,6 +436,7 @@ limitations under the License.
permission = {
id: 'abandon',
value: {
+ added: true,
rules: {},
},
};
@@ -426,9 +447,18 @@ limitations under the License.
3);
assert.deepEqual(element.section.value.permissions['abandon'],
permission.value);
+
+ // Unsaved changes are discarded when editing is cancelled.
+ element.editing = false;
+ assert.equal(element._permissions.length, 1);
+ assert.equal(Object.keys(element.section.value.permissions).length,
+ 1);
});
test('edit section reference', () => {
+ element.canUpload = true;
+ element.ownerOf = [];
+ element.section = {id: 'refs/for/bar', value: {permissions: {}}};
assert.isFalse(element.$.section.classList.contains('editing'));
element.editing = true;
assert.isTrue(element.$.section.classList.contains('editing'));
@@ -439,19 +469,49 @@ limitations under the License.
assert.equal(element.section.id, 'new/ref');
assert.isTrue(element._editingRef);
assert.isTrue(element.$.section.classList.contains('editingRef'));
- MockInteractions.tap(element.$.undoEdit);
- flushAsynchronousOperations();
+ element.editing = false;
assert.isFalse(element._editingRef);
- assert.isFalse(element.$.section.classList.contains('editingRef'));
- assert.equal(element.section.id, 'refs/*');
+ assert.equal(element.section.id, 'refs/for/bar');
+ });
+
+ test('_handleValueChange', () => {
+ // For an exising section.
+ const modifiedHandler = sandbox.stub();
+ element.section = {id: 'refs/for/bar', value: {permissions: {}}};
+ assert.notOk(element.section.value.updatedId);
+ element.section.id = 'refs/for/baz';
+ element.addEventListener('access-modified', modifiedHandler);
+ assert.isNotOk(element.section.value.modified);
+ element._handleValueChange();
+ assert.equal(element.section.value.updatedId, 'refs/for/baz');
+ assert.isTrue(element.section.value.modified);
+ assert.equal(modifiedHandler.callCount, 1);
+ element.section.id = 'refs/for/bar';
+ element._handleValueChange();
+ assert.isFalse(element.section.value.modified);
+ assert.equal(modifiedHandler.callCount, 2);
+
+ // For a new section.
+ element.section.value.added = true;
+ element._handleValueChange();
+ assert.isFalse(element.section.value.modified);
+ assert.equal(modifiedHandler.callCount, 2);
+ element.section.id = 'refs/for/bar';
+ element._handleValueChange();
+ assert.isFalse(element.section.value.modified);
+ assert.equal(modifiedHandler.callCount, 2);
});
test('remove section', () => {
element.editing = true;
+ element.canUpload = true;
+ element.ownerOf = [];
assert.isFalse(element._deleted);
+ assert.isNotOk(element.section.value.deleted);
MockInteractions.tap(element.$.deleteBtn);
flushAsynchronousOperations();
assert.isTrue(element._deleted);
+ assert.isTrue(element.section.value.deleted);
assert.isTrue(element.$.section.classList.contains('deleted'));
assert.isTrue(element.section.value.deleted);
@@ -459,6 +519,30 @@ limitations under the License.
flushAsynchronousOperations();
assert.isFalse(element._deleted);
assert.isNotOk(element.section.value.deleted);
+
+ MockInteractions.tap(element.$.deleteBtn);
+ assert.isTrue(element._deleted);
+ assert.isTrue(element.section.value.deleted);
+ element.editing = false;
+ assert.isFalse(element._deleted);
+ assert.isNotOk(element.section.value.deleted);
+ });
+
+ test('removing an added permission', () => {
+ element.editing = true;
+ assert.equal(element._permissions.length, 1);
+ element.$$('gr-permission').fire('added-permission-removed');
+ flushAsynchronousOperations();
+ assert.equal(element._permissions.length, 0);
+ });
+
+ test('remove an added section', () => {
+ const removeStub = sandbox.stub();
+ element.addEventListener('added-section-removed', removeStub);
+ element.editing = true;
+ element.section.value.added = true;
+ MockInteractions.tap(element.$.deleteBtn);
+ assert.isTrue(removeStub.called);
});
});
});