ES6ify /gr-patch-range-select/*
Bug: Issue 6179 Change-Id: I9285ea11f9ff63244f1321cc5a3ba8466db56ae8
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Maximum length for patch set descriptions.
|
// Maximum length for patch set descriptions.
|
||||||
var PATCH_DESC_MAX_LENGTH = 500;
|
const PATCH_DESC_MAX_LENGTH = 500;
|
||||||
|
|
||||||
Polymer({
|
Polymer({
|
||||||
is: 'gr-patch-range-select',
|
is: 'gr-patch-range-select',
|
||||||
@@ -36,15 +36,15 @@
|
|||||||
|
|
||||||
behaviors: [Gerrit.PatchSetBehavior],
|
behaviors: [Gerrit.PatchSetBehavior],
|
||||||
|
|
||||||
_updateSelected: function() {
|
_updateSelected() {
|
||||||
this._rightSelected = this.patchRange.patchNum;
|
this._rightSelected = this.patchRange.patchNum;
|
||||||
this._leftSelected = this.patchRange.basePatchNum;
|
this._leftSelected = this.patchRange.basePatchNum;
|
||||||
},
|
},
|
||||||
|
|
||||||
_handlePatchChange: function(e) {
|
_handlePatchChange(e) {
|
||||||
var leftPatch = this._leftSelected;
|
const leftPatch = this._leftSelected;
|
||||||
var rightPatch = this._rightSelected;
|
const rightPatch = this._rightSelected;
|
||||||
var rangeStr = rightPatch;
|
let rangeStr = rightPatch;
|
||||||
if (leftPatch != 'PARENT') {
|
if (leftPatch != 'PARENT') {
|
||||||
rangeStr = leftPatch + '..' + rangeStr;
|
rangeStr = leftPatch + '..' + rangeStr;
|
||||||
}
|
}
|
||||||
@@ -52,11 +52,11 @@
|
|||||||
e.target.blur();
|
e.target.blur();
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeLeftDisabled: function(patchNum, patchRange) {
|
_computeLeftDisabled(patchNum, patchRange) {
|
||||||
return parseInt(patchNum, 10) >= parseInt(patchRange.patchNum, 10);
|
return parseInt(patchNum, 10) >= parseInt(patchRange.patchNum, 10);
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeRightDisabled: function(patchNum, patchRange) {
|
_computeRightDisabled(patchNum, patchRange) {
|
||||||
if (patchRange.basePatchNum == 'PARENT') { return false; }
|
if (patchRange.basePatchNum == 'PARENT') { return false; }
|
||||||
return parseInt(patchNum, 10) <= parseInt(patchRange.basePatchNum, 10);
|
return parseInt(patchNum, 10) <= parseInt(patchRange.basePatchNum, 10);
|
||||||
},
|
},
|
||||||
@@ -66,16 +66,16 @@
|
|||||||
// are loaded, the correct value will get selected. I attempted to
|
// are loaded, the correct value will get selected. I attempted to
|
||||||
// debounce these, but because they are detecting two different
|
// debounce these, but because they are detecting two different
|
||||||
// events, sometimes the timing was off and one ended up missing.
|
// events, sometimes the timing was off and one ended up missing.
|
||||||
_synchronizeSelectionRight: function() {
|
_synchronizeSelectionRight() {
|
||||||
this.$.rightPatchSelect.value = this._rightSelected;
|
this.$.rightPatchSelect.value = this._rightSelected;
|
||||||
},
|
},
|
||||||
|
|
||||||
_synchronizeSelectionLeft: function() {
|
_synchronizeSelectionLeft() {
|
||||||
this.$.leftPatchSelect.value = this._leftSelected;
|
this.$.leftPatchSelect.value = this._leftSelected;
|
||||||
},
|
},
|
||||||
|
|
||||||
_computePatchSetDescription: function(revisions, patchNum) {
|
_computePatchSetDescription(revisions, patchNum) {
|
||||||
var rev = this.getRevisionByPatchNum(revisions, patchNum);
|
const rev = this.getRevisionByPatchNum(revisions, patchNum);
|
||||||
return (rev && rev.description) ?
|
return (rev && rev.description) ?
|
||||||
rev.description.substring(0, PATCH_DESC_MAX_LENGTH) : '';
|
rev.description.substring(0, PATCH_DESC_MAX_LENGTH) : '';
|
||||||
},
|
},
|
||||||
|
@@ -34,24 +34,24 @@ limitations under the License.
|
|||||||
</test-fixture>
|
</test-fixture>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
suite('gr-patch-range-select tests', function() {
|
suite('gr-patch-range-select tests', () => {
|
||||||
var element;
|
let element;
|
||||||
|
|
||||||
setup(function() {
|
setup(() => {
|
||||||
element = fixture('basic');
|
element = fixture('basic');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('enabled/disabled options', function() {
|
test('enabled/disabled options', () => {
|
||||||
var patchRange = {
|
const patchRange = {
|
||||||
basePatchNum: 'PARENT',
|
basePatchNum: 'PARENT',
|
||||||
patchNum: '3',
|
patchNum: '3',
|
||||||
};
|
};
|
||||||
['1', '2', '3'].forEach(function(patchNum) {
|
for (const patchNum of ['1', '2', '3']) {
|
||||||
assert.isFalse(element._computeRightDisabled(patchNum, patchRange));
|
assert.isFalse(element._computeRightDisabled(patchNum, patchRange));
|
||||||
});
|
}
|
||||||
['PARENT', '1', '2'].forEach(function(patchNum) {
|
for (const patchNum of ['PARENT', '1', '2']) {
|
||||||
assert.isFalse(element._computeLeftDisabled(patchNum, patchRange));
|
assert.isFalse(element._computeLeftDisabled(patchNum, patchRange));
|
||||||
});
|
}
|
||||||
assert.isTrue(element._computeLeftDisabled('3', patchRange));
|
assert.isTrue(element._computeLeftDisabled('3', patchRange));
|
||||||
|
|
||||||
patchRange.basePatchNum = '2';
|
patchRange.basePatchNum = '2';
|
||||||
@@ -61,11 +61,11 @@ limitations under the License.
|
|||||||
assert.isFalse(element._computeRightDisabled('3', patchRange));
|
assert.isFalse(element._computeRightDisabled('3', patchRange));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('navigation', function(done) {
|
test('navigation', done => {
|
||||||
var showStub = sinon.stub(page, 'show');
|
const showStub = sinon.stub(page, 'show');
|
||||||
var leftSelectEl = element.$.leftPatchSelect;
|
const leftSelectEl = element.$.leftPatchSelect;
|
||||||
var rightSelectEl = element.$.rightPatchSelect;
|
const rightSelectEl = element.$.rightPatchSelect;
|
||||||
var blurSpy = sinon.spy(leftSelectEl, 'blur');
|
const blurSpy = sinon.spy(leftSelectEl, 'blur');
|
||||||
element.changeNum = '42';
|
element.changeNum = '42';
|
||||||
element.path = 'path/to/file.txt';
|
element.path = 'path/to/file.txt';
|
||||||
element.availablePatches = ['1', '2', '3'];
|
element.availablePatches = ['1', '2', '3'];
|
||||||
@@ -75,8 +75,8 @@ limitations under the License.
|
|||||||
};
|
};
|
||||||
flushAsynchronousOperations();
|
flushAsynchronousOperations();
|
||||||
|
|
||||||
var numEvents = 0;
|
let numEvents = 0;
|
||||||
leftSelectEl.addEventListener('change', function(e) {
|
leftSelectEl.addEventListener('change', e => {
|
||||||
numEvents++;
|
numEvents++;
|
||||||
if (numEvents == 1) {
|
if (numEvents == 1) {
|
||||||
assert(showStub.lastCall.calledWithExactly(
|
assert(showStub.lastCall.calledWithExactly(
|
||||||
@@ -98,23 +98,23 @@ limitations under the License.
|
|||||||
element.fire('change', {}, {node: leftSelectEl});
|
element.fire('change', {}, {node: leftSelectEl});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('filesWeblinks', function() {
|
test('filesWeblinks', () => {
|
||||||
element.filesWeblinks = {
|
element.filesWeblinks = {
|
||||||
meta_a: [
|
meta_a: [
|
||||||
{
|
{
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
url: 'f.oo',
|
url: 'f.oo',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
meta_b: [
|
meta_b: [
|
||||||
{
|
{
|
||||||
name: 'bar',
|
name: 'bar',
|
||||||
url: 'ba.r',
|
url: 'ba.r',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
flushAsynchronousOperations();
|
flushAsynchronousOperations();
|
||||||
var domApi = Polymer.dom(element.root);
|
const domApi = Polymer.dom(element.root);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
domApi.querySelector('a[href="f.oo"]').textContent, 'foo');
|
domApi.querySelector('a[href="f.oo"]').textContent, 'foo');
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
Reference in New Issue
Block a user