Add a separator between blame and the edit icon

Change-Id: I36cf9acfbf4686404d42bf6d9d04f8ab9eca3ef4
(cherry picked from commit 32a9265505)
This commit is contained in:
Tao Zhou
2020-02-27 15:59:39 +01:00
committed by Paladox none
parent ff3b433f40
commit 24c6b9a586
3 changed files with 56 additions and 14 deletions

View File

@@ -290,13 +290,15 @@ limitations under the License.
on-tap="_toggleBlame">[[_computeBlameToggleLabel(_isBlameLoaded, _isBlameLoading)]]</gr-button>
</span>
<template is="dom-if" if="[[_computeIsLoggedIn(_loggedIn)]]">
<span class="separator"></span>
<span class="editButton">
<a href$="[[_computeEditURL(_change, _patchRange, _path)]]">
<iron-icon icon="gr-icons:edit"></iron-icon>
</a>
<span class="separator"></span>
<gr-button
link
title="Edit current file"
on-click="_goToEditFile">edit</gr-button>
</span>
</template>
<span class="separator"></span>
<div class$="diffModeSelector [[_computeModeSelectHideClass(_isImageDiff)]]">
<span>Diff view:</span>
<gr-diff-mode-selector

View File

@@ -526,12 +526,11 @@
return this._getDiffUrl(this._change, this._patchRange, newPath.path);
},
_computeEditURL(change, patchRange, path) {
if ([change, patchRange, path].some(arg => arg === undefined)) {
return '';
}
return Gerrit.Nav.getEditUrlForDiff(
change, path, patchRange.patchNum);
_goToEditFile() {
// TODO(taoalpha): add a shortcut for editing
const editUrl = Gerrit.Nav.getEditUrlForDiff(
this._change, this._path, this._patchRange.patchNum);
return Gerrit.Nav.navigateToRelativeUrl(editUrl);
},
/**

View File

@@ -344,10 +344,51 @@ limitations under the License.
PARENT), 'Should navigate to /c/42/1');
});
test('_computeEditURL uses Gerrit.Nav', () => {
const getUrlStub = sandbox.stub(Gerrit.Nav, 'getEditUrlForDiff');
element._computeEditURL(123, {patchNum: undefined}, 'abc/def');
assert.isTrue(getUrlStub.called);
test('edit should redirect to edit page', done => {
element._loggedIn = true;
element._path = 't.txt';
element._patchRange = {
basePatchNum: PARENT,
patchNum: '1',
};
element._change = {
_number: 42,
revisions: {
a: {_number: 1, commit: {parents: []}},
b: {_number: 2, commit: {parents: []}},
},
};
const redirectStub = sandbox.stub(Gerrit.Nav, 'navigateToRelativeUrl');
flush(() => {
const editBtn = Polymer.dom(element.root)
.querySelector('.editButton gr-button');
assert.isTrue(!!editBtn);
MockInteractions.tap(editBtn);
assert.isTrue(redirectStub.called);
done();
});
});
test('edit hidden when not logged in', done => {
element._loggedIn = false;
element._path = 't.txt';
element._patchRange = {
basePatchNum: PARENT,
patchNum: '1',
};
element._change = {
_number: 42,
revisions: {
a: {_number: 1, commit: {parents: []}},
b: {_number: 2, commit: {parents: []}},
},
};
flush(() => {
const editBtn = Polymer.dom(element.root)
.querySelector('.editButton gr-button');
assert.isFalse(!!editBtn);
done();
});
});
test('Diff preferences hidden when no prefs or logged out', () => {