diff options
Diffstat (limited to 'polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.html')
-rw-r--r-- | polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.html | 143 |
1 files changed, 97 insertions, 46 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.html b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.html index 45a23fae0c..e2685e1c88 100644 --- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_test.html +++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header_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"); @@ -96,35 +97,9 @@ limitations under the License. 'Add patchset description'); }); - test('_computePatchSetDisabled', () => { - element.revisions = [ - {_number: 1}, - {_number: 2}, - {_number: element.EDIT_NAME, basePatchNum: 2}, - {_number: 3}, - ]; - let basePatchNum = 'PARENT'; - let patchNum = 1; - assert.equal(element._computePatchSetDisabled(patchNum, basePatchNum), - false); - basePatchNum = 1; - assert.equal(element._computePatchSetDisabled(patchNum, basePatchNum), - true); - patchNum = 2; - assert.equal(element._computePatchSetDisabled(patchNum, basePatchNum), - false); - basePatchNum = element.EDIT_NAME; - assert.equal(element._computePatchSetDisabled(patchNum, basePatchNum), - true); - patchNum = '3'; - assert.equal(element._computePatchSetDisabled(patchNum, basePatchNum), - false); - }); - - test('_handleDescriptionChanged', () => { + test('description editing', () => { const putDescStub = sandbox.stub(element.$.restAPI, 'setDescription') .returns(Promise.resolve({ok: true})); - sandbox.stub(element, '_computeDescriptionReadOnly'); element.changeNum = '42'; element.basePatchNum = 'PARENT'; @@ -145,15 +120,46 @@ limitations under the License. element.loggedIn = true; flushAsynchronousOperations(); - const label = element.$.descriptionLabel; - assert.equal(label.value, 'test'); - label.editing = true; - label._inputText = 'test2'; - label._save(); - flushAsynchronousOperations(); - assert.isTrue(putDescStub.called); - assert.equal(putDescStub.args[0][2], 'test2'); - assert.equal(element.change.revisions.rev1.description, 'test'); + + // The element has a description, so the account chip should be visible + // and the description label should not exist. + const chip = Polymer.dom(element.root).querySelector('#descriptionChip'); + let label = Polymer.dom(element.root).querySelector('#descriptionLabel'); + + assert.equal(chip.text, 'test'); + assert.isNotOk(label); + + // Simulate tapping the remove button, but call function directly so that + // can determine what happens after the promise is resolved. + return element._handleDescriptionRemoved().then(() => { + // The API stub should be called with an empty string for the new + // description. + assert.equal(putDescStub.lastCall.args[2], ''); + assert.equal(element.change.revisions.rev1.description, ''); + + flushAsynchronousOperations(); + // The editable label should now be visible and the chip hidden. + label = Polymer.dom(element.root).querySelector('#descriptionLabel'); + assert.isOk(label); + assert.equal(getComputedStyle(chip).display, 'none'); + assert.notEqual(getComputedStyle(label).display, 'none'); + assert.isFalse(label.readOnly); + // Edit the label to have a new value of test2, and save. + label.editing = true; + label._inputText = 'test2'; + label._save(); + flushAsynchronousOperations(); + // The API stub should be called with an `test2` for the new + // description. + assert.equal(putDescStub.callCount, 2); + assert.equal(putDescStub.lastCall.args[2], 'test2'); + }).then(() => { + flushAsynchronousOperations(); + // The chip should be visible again, and the label hidden. + assert.equal(element.change.revisions.rev1.description, 'test2'); + assert.equal(getComputedStyle(label).display, 'none'); + assert.notEqual(getComputedStyle(chip).display, 'none'); + }); }); test('expandAllDiffs called when expand button clicked', () => { @@ -191,15 +197,39 @@ limitations under the License. }); }); - test('diff mode selector is set correctly', () => { - const select = element.$.modeSelect; - element.diffViewMode = 'SIDE_BY_SIDE'; + test('fileViewActions are properly hidden', () => { + const actions = element.$$('.fileViewActions'); + assert.equal(getComputedStyle(actions).display, 'none'); + element.filesExpanded = GrFileListConstants.FilesExpandedState.SOME; + flushAsynchronousOperations(); + assert.notEqual(getComputedStyle(actions).display, 'none'); + element.filesExpanded = GrFileListConstants.FilesExpandedState.ALL; flushAsynchronousOperations(); - assert.equal(select.nativeSelect.value, 'SIDE_BY_SIDE'); + assert.notEqual(getComputedStyle(actions).display, 'none'); + element.filesExpanded = GrFileListConstants.FilesExpandedState.NONE; + flushAsynchronousOperations(); + assert.equal(getComputedStyle(actions).display, 'none'); + }); - element.diffViewMode = 'UNIFIED_DIFF'; + test('expand/collapse buttons are toggled correctly', () => { + element.shownFileCount = 10; + flushAsynchronousOperations(); + const expandBtn = element.$$('#expandBtn'); + const collapseBtn = element.$$('#collapseBtn'); + assert.notEqual(getComputedStyle(expandBtn).display, 'none'); + assert.equal(getComputedStyle(collapseBtn).display, 'none'); + element.filesExpanded = GrFileListConstants.FilesExpandedState.SOME; flushAsynchronousOperations(); - assert.equal(select.nativeSelect.value, 'UNIFIED_DIFF'); + assert.notEqual(getComputedStyle(expandBtn).display, 'none'); + assert.equal(getComputedStyle(collapseBtn).display, 'none'); + element.filesExpanded = GrFileListConstants.FilesExpandedState.ALL; + flushAsynchronousOperations(); + assert.equal(getComputedStyle(expandBtn).display, 'none'); + assert.notEqual(getComputedStyle(collapseBtn).display, 'none'); + element.filesExpanded = GrFileListConstants.FilesExpandedState.NONE; + flushAsynchronousOperations(); + assert.notEqual(getComputedStyle(expandBtn).display, 'none'); + assert.equal(getComputedStyle(collapseBtn).display, 'none'); }); test('navigateToChange called when range select changes', () => { @@ -225,7 +255,7 @@ limitations under the License. }); test('class is applied to file list on old patch set', () => { - const allPatchSets = [{num: 1}, {num: 2}, {num: 4}]; + const allPatchSets = [{num: 4}, {num: 2}, {num: 1}]; assert.equal(element._computePatchInfoClass('1', allPatchSets), 'patchInfoOldPatchSet'); assert.equal(element._computePatchInfoClass('2', allPatchSets), @@ -233,7 +263,7 @@ limitations under the License. assert.equal(element._computePatchInfoClass('4', allPatchSets), ''); }); - suite('editLoaded behavior', () => { + suite('editMode behavior', () => { setup(() => { element.loggedIn = true; element.diffPrefs = {}; @@ -245,19 +275,40 @@ limitations under the License. }; test('patch specific elements', () => { - element.editLoaded = true; + element.editMode = true; sandbox.stub(element, 'computeLatestPatchNum').returns('2'); flushAsynchronousOperations(); assert.isFalse(isVisible(element.$.diffPrefsContainer)); assert.isFalse(isVisible(element.$$('.descriptionContainer'))); - element.editLoaded = false; + element.editMode = false; flushAsynchronousOperations(); assert.isTrue(isVisible(element.$$('.descriptionContainer'))); assert.isTrue(isVisible(element.$.diffPrefsContainer)); }); + + test('edit-controls visibility', () => { + element.editMode = true; + flushAsynchronousOperations(); + assert.isTrue(isVisible(element.$.editControls.parentElement)); + + element.editMode = false; + flushAsynchronousOperations(); + assert.isFalse(isVisible(element.$.editControls.parentElement)); + }); + + test('_computeUploadHelpContainerClass', () => { + // Only show the upload helper button when an unmerged change is viewed + // by its owner. + const accountA = {_account_id: 1}; + const accountB = {_account_id: 2}; + assert.notInclude(element._computeUploadHelpContainerClass( + {owner: accountA}, accountA), 'hide'); + assert.include(element._computeUploadHelpContainerClass( + {owner: accountA}, accountB), 'hide'); + }); }); }); </script> |