Merge "ES6ify /gr-diff-view/*"
This commit is contained in:
@@ -14,17 +14,17 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var COMMIT_MESSAGE_PATH = '/COMMIT_MSG';
|
||||
var MERGE_LIST_PATH = '/MERGE_LIST';
|
||||
const COMMIT_MESSAGE_PATH = '/COMMIT_MSG';
|
||||
const MERGE_LIST_PATH = '/MERGE_LIST';
|
||||
|
||||
var COMMENT_SAVE = 'Try again when all comments have saved.';
|
||||
const COMMENT_SAVE = 'Try again when all comments have saved.';
|
||||
|
||||
var DiffSides = {
|
||||
const DiffSides = {
|
||||
LEFT: 'left',
|
||||
RIGHT: 'right',
|
||||
};
|
||||
|
||||
var HASH_PATTERN = /^[ab]?\d+$/;
|
||||
const HASH_PATTERN = /^[ab]?\d+$/;
|
||||
|
||||
Polymer({
|
||||
is: 'gr-diff-view',
|
||||
@@ -51,12 +51,12 @@
|
||||
},
|
||||
keyEventTarget: {
|
||||
type: Object,
|
||||
value: function() { return document.body; },
|
||||
value() { return document.body; },
|
||||
},
|
||||
changeViewState: {
|
||||
type: Object,
|
||||
notify: true,
|
||||
value: function() { return {}; },
|
||||
value() { return {}; },
|
||||
},
|
||||
|
||||
_patchRange: Object,
|
||||
@@ -65,7 +65,7 @@
|
||||
_diff: Object,
|
||||
_fileList: {
|
||||
type: Array,
|
||||
value: function() { return []; },
|
||||
value() { return []; },
|
||||
},
|
||||
_path: {
|
||||
type: String,
|
||||
@@ -134,18 +134,18 @@
|
||||
',': '_handleCommaKey',
|
||||
},
|
||||
|
||||
attached: function() {
|
||||
this._getLoggedIn().then(function(loggedIn) {
|
||||
attached() {
|
||||
this._getLoggedIn().then(loggedIn => {
|
||||
this._loggedIn = loggedIn;
|
||||
if (loggedIn) {
|
||||
this._setReviewed(true);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
if (this.changeViewState.diffMode === null) {
|
||||
// If screen size is small, always default to unified view.
|
||||
this.$.restAPI.getPreferences().then(function(prefs) {
|
||||
this.$.restAPI.getPreferences().then(prefs => {
|
||||
this.set('changeViewState.diffMode', prefs.default_diff_view);
|
||||
}.bind(this));
|
||||
});
|
||||
}
|
||||
|
||||
if (this._path) {
|
||||
@@ -156,63 +156,63 @@
|
||||
this.$.cursor.push('diffs', this.$.diff);
|
||||
},
|
||||
|
||||
_getLoggedIn: function() {
|
||||
_getLoggedIn() {
|
||||
return this.$.restAPI.getLoggedIn();
|
||||
},
|
||||
|
||||
_getProjectConfig: function(project) {
|
||||
_getProjectConfig(project) {
|
||||
return this.$.restAPI.getProjectConfig(project).then(
|
||||
function(config) {
|
||||
config => {
|
||||
this._projectConfig = config;
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
_getChangeDetail: function(changeNum) {
|
||||
_getChangeDetail(changeNum) {
|
||||
return this.$.restAPI.getDiffChangeDetail(changeNum).then(
|
||||
function(change) {
|
||||
change => {
|
||||
this._change = change;
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
_getFiles: function(changeNum, patchRangeRecord) {
|
||||
var patchRange = patchRangeRecord.base;
|
||||
_getFiles(changeNum, patchRangeRecord) {
|
||||
const patchRange = patchRangeRecord.base;
|
||||
return this.$.restAPI.getChangeFilePathsAsSpeciallySortedArray(
|
||||
changeNum, patchRange).then(function(files) {
|
||||
changeNum, patchRange).then(files => {
|
||||
this._fileList = files;
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
_getDiffPreferences: function() {
|
||||
_getDiffPreferences() {
|
||||
return this.$.restAPI.getDiffPreferences();
|
||||
},
|
||||
|
||||
_getPreferences: function() {
|
||||
_getPreferences() {
|
||||
return this.$.restAPI.getPreferences();
|
||||
},
|
||||
|
||||
_getWindowWidth: function() {
|
||||
_getWindowWidth() {
|
||||
return window.innerWidth;
|
||||
},
|
||||
|
||||
_handleReviewedChange: function(e) {
|
||||
_handleReviewedChange(e) {
|
||||
this._setReviewed(Polymer.dom(e).rootTarget.checked);
|
||||
},
|
||||
|
||||
_setReviewed: function(reviewed) {
|
||||
_setReviewed(reviewed) {
|
||||
this.$.reviewed.checked = reviewed;
|
||||
this._saveReviewedState(reviewed).catch(function(err) {
|
||||
this._saveReviewedState(reviewed).catch(err => {
|
||||
alert('Couldn’t change file review status. Check the console ' +
|
||||
'and contact the PolyGerrit team for assistance.');
|
||||
throw err;
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
_saveReviewedState: function(reviewed) {
|
||||
_saveReviewedState(reviewed) {
|
||||
return this.$.restAPI.saveFileReviewed(this._changeNum,
|
||||
this._patchRange.patchNum, this._path, reviewed);
|
||||
},
|
||||
|
||||
_handleEscKey: function(e) {
|
||||
_handleEscKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e) ||
|
||||
this.modifierPressed(e)) { return; }
|
||||
|
||||
@@ -220,21 +220,21 @@
|
||||
this.$.diff.displayLine = false;
|
||||
},
|
||||
|
||||
_handleShiftLeftKey: function(e) {
|
||||
_handleShiftLeftKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
|
||||
e.preventDefault();
|
||||
this.$.cursor.moveLeft();
|
||||
},
|
||||
|
||||
_handleShiftRightKey: function(e) {
|
||||
_handleShiftRightKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
|
||||
e.preventDefault();
|
||||
this.$.cursor.moveRight();
|
||||
},
|
||||
|
||||
_handleUpKey: function(e) {
|
||||
_handleUpKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
if (e.detail.keyboardEvent.shiftKey &&
|
||||
e.detail.keyboardEvent.keyCode === 75) { // 'K'
|
||||
@@ -248,7 +248,7 @@
|
||||
this.$.cursor.moveUp();
|
||||
},
|
||||
|
||||
_handleDownKey: function(e) {
|
||||
_handleDownKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
if (e.detail.keyboardEvent.shiftKey &&
|
||||
e.detail.keyboardEvent.keyCode === 74) { // 'J'
|
||||
@@ -262,33 +262,33 @@
|
||||
this.$.cursor.moveDown();
|
||||
},
|
||||
|
||||
_moveToPreviousFileWithComment: function() {
|
||||
_moveToPreviousFileWithComment() {
|
||||
if (this._commentSkips && this._commentSkips.previous) {
|
||||
page.show(this._getDiffURL(this._changeNum, this._patchRange,
|
||||
this._commentSkips.previous));
|
||||
}
|
||||
},
|
||||
|
||||
_moveToNextFileWithComment: function() {
|
||||
_moveToNextFileWithComment() {
|
||||
if (this._commentSkips && this._commentSkips.next) {
|
||||
page.show(this._getDiffURL(this._changeNum, this._patchRange,
|
||||
this._commentSkips.next));
|
||||
}
|
||||
},
|
||||
|
||||
_handleCKey: function(e) {
|
||||
_handleCKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
if (this.$.diff.isRangeSelected()) { return; }
|
||||
if (this.modifierPressed(e)) { return; }
|
||||
|
||||
e.preventDefault();
|
||||
var line = this.$.cursor.getTargetLineElement();
|
||||
const line = this.$.cursor.getTargetLineElement();
|
||||
if (line) {
|
||||
this.$.diff.addDraftAtLine(line);
|
||||
}
|
||||
},
|
||||
|
||||
_handleLeftBracketKey: function(e) {
|
||||
_handleLeftBracketKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e) ||
|
||||
this.modifierPressed(e)) { return; }
|
||||
|
||||
@@ -296,7 +296,7 @@
|
||||
this._navToFile(this._path, this._fileList, -1);
|
||||
},
|
||||
|
||||
_handleRightBracketKey: function(e) {
|
||||
_handleRightBracketKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e) ||
|
||||
this.modifierPressed(e)) { return; }
|
||||
|
||||
@@ -304,7 +304,7 @@
|
||||
this._navToFile(this._path, this._fileList, 1);
|
||||
},
|
||||
|
||||
_handleNKey: function(e) {
|
||||
_handleNKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
|
||||
e.preventDefault();
|
||||
@@ -316,7 +316,7 @@
|
||||
}
|
||||
},
|
||||
|
||||
_handlePKey: function(e) {
|
||||
_handlePKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
|
||||
e.preventDefault();
|
||||
@@ -328,7 +328,7 @@
|
||||
}
|
||||
},
|
||||
|
||||
_handleAKey: function(e) {
|
||||
_handleAKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
|
||||
if (e.detail.keyboardEvent.shiftKey) { // Hide left diff.
|
||||
@@ -351,7 +351,7 @@
|
||||
this._navToChangeView();
|
||||
},
|
||||
|
||||
_handleUKey: function(e) {
|
||||
_handleUKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e) ||
|
||||
this.modifierPressed(e)) { return; }
|
||||
|
||||
@@ -359,7 +359,7 @@
|
||||
this._navToChangeView();
|
||||
},
|
||||
|
||||
_handleCommaKey: function(e) {
|
||||
_handleCommaKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e) ||
|
||||
this.modifierPressed(e)) { return; }
|
||||
|
||||
@@ -367,7 +367,7 @@
|
||||
this.$.diffPreferences.open();
|
||||
},
|
||||
|
||||
_navToChangeView: function() {
|
||||
_navToChangeView() {
|
||||
if (!this._changeNum || !this._patchRange.patchNum) { return; }
|
||||
|
||||
page.show(this._getChangePath(
|
||||
@@ -376,15 +376,15 @@
|
||||
this._change && this._change.revisions));
|
||||
},
|
||||
|
||||
_computeUpURL: function(changeNum, patchRange, change, changeRevisions) {
|
||||
_computeUpURL(changeNum, patchRange, change, changeRevisions) {
|
||||
return this._getChangePath(
|
||||
changeNum,
|
||||
patchRange,
|
||||
change && changeRevisions);
|
||||
},
|
||||
|
||||
_navToFile: function(path, fileList, direction) {
|
||||
var url = this._computeNavLinkURL(path, fileList, direction);
|
||||
_navToFile(path, fileList, direction) {
|
||||
const url = this._computeNavLinkURL(path, fileList, direction);
|
||||
if (!url) { return; }
|
||||
|
||||
page.show(this._computeNavLinkURL(path, fileList, direction));
|
||||
@@ -401,12 +401,14 @@
|
||||
* @return {?string} The next URL when proceeding in the specified
|
||||
* direction.
|
||||
*/
|
||||
_computeNavLinkURL: function(path, fileList, direction, opt_noUp) {
|
||||
_computeNavLinkURL(path, fileList, direction, opt_noUp) {
|
||||
if (!path || fileList.length === 0) { return null; }
|
||||
|
||||
var idx = fileList.indexOf(path);
|
||||
let idx = fileList.indexOf(path);
|
||||
if (idx === -1) {
|
||||
var file = direction > 0 ? fileList[0] : fileList[fileList.length - 1];
|
||||
const file = direction > 0 ?
|
||||
fileList[0] :
|
||||
fileList[fileList.length - 1];
|
||||
return this._getDiffURL(this._changeNum, this._patchRange, file);
|
||||
}
|
||||
|
||||
@@ -423,7 +425,7 @@
|
||||
return this._getDiffURL(this._changeNum, this._patchRange, fileList[idx]);
|
||||
},
|
||||
|
||||
_paramsChanged: function(value) {
|
||||
_paramsChanged(value) {
|
||||
if (value.view != this.tagName.toLowerCase()) { return; }
|
||||
|
||||
this._loadHash(location.hash);
|
||||
@@ -445,33 +447,33 @@
|
||||
return;
|
||||
}
|
||||
|
||||
var promises = [];
|
||||
const promises = [];
|
||||
|
||||
this._localPrefs = this.$.storage.getPreferences();
|
||||
promises.push(this._getDiffPreferences().then(function(prefs) {
|
||||
promises.push(this._getDiffPreferences().then(prefs => {
|
||||
this._prefs = prefs;
|
||||
}.bind(this)));
|
||||
}));
|
||||
|
||||
promises.push(this._getPreferences().then(function(prefs) {
|
||||
promises.push(this._getPreferences().then(prefs => {
|
||||
this._userPrefs = prefs;
|
||||
}.bind(this)));
|
||||
}));
|
||||
|
||||
promises.push(this._getChangeDetail(this._changeNum));
|
||||
|
||||
Promise.all(promises).then(function() {
|
||||
Promise.all(promises).then(() => {
|
||||
this._loading = false;
|
||||
this.$.diff.reload();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
this._loadCommentMap().then(function(commentMap) {
|
||||
this._loadCommentMap().then(commentMap => {
|
||||
this._commentMap = commentMap;
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* If the URL hash is a diff address then configure the diff cursor.
|
||||
*/
|
||||
_loadHash: function(hash) {
|
||||
_loadHash(hash) {
|
||||
hash = hash.replace(/^#/, '');
|
||||
if (!HASH_PATTERN.test(hash)) { return; }
|
||||
if (hash[0] === 'a' || hash[0] === 'b') {
|
||||
@@ -483,7 +485,7 @@
|
||||
this.$.cursor.initialLineNumber = parseInt(hash, 10);
|
||||
},
|
||||
|
||||
_pathChanged: function(path) {
|
||||
_pathChanged(path) {
|
||||
if (this._fileList.length == 0) { return; }
|
||||
|
||||
this.set('changeViewState.selectedFileIndex',
|
||||
@@ -494,17 +496,17 @@
|
||||
}
|
||||
},
|
||||
|
||||
_getDiffURL: function(changeNum, patchRange, path) {
|
||||
_getDiffURL(changeNum, patchRange, path) {
|
||||
return this.getBaseUrl() + '/c/' + changeNum + '/' +
|
||||
this._patchRangeStr(patchRange) + '/' + this.encodeURL(path, true);
|
||||
},
|
||||
|
||||
_computeDiffURL: function(changeNum, patchRangeRecord, path) {
|
||||
_computeDiffURL(changeNum, patchRangeRecord, path) {
|
||||
return this._getDiffURL(changeNum, patchRangeRecord.base, path);
|
||||
},
|
||||
|
||||
_patchRangeStr: function(patchRange) {
|
||||
var patchStr = patchRange.patchNum;
|
||||
_patchRangeStr(patchRange) {
|
||||
let patchStr = patchRange.patchNum;
|
||||
if (patchRange.basePatchNum != null &&
|
||||
patchRange.basePatchNum != 'PARENT') {
|
||||
patchStr = patchRange.basePatchNum + '..' + patchRange.patchNum;
|
||||
@@ -512,25 +514,25 @@
|
||||
return patchStr;
|
||||
},
|
||||
|
||||
_computeAvailablePatches: function(revisions) {
|
||||
var patchNums = [];
|
||||
for (var rev in revisions) {
|
||||
patchNums.push(revisions[rev]._number);
|
||||
_computeAvailablePatches(revisions) {
|
||||
const patchNums = [];
|
||||
for (const rev of Object.values(revisions)) {
|
||||
patchNums.push(rev._number);
|
||||
}
|
||||
return patchNums.sort(function(a, b) { return a - b; });
|
||||
return patchNums.sort((a, b) => { return a - b; });
|
||||
},
|
||||
|
||||
_getChangePath: function(changeNum, patchRange, revisions) {
|
||||
var base = this.getBaseUrl() + '/c/' + changeNum + '/';
|
||||
_getChangePath(changeNum, patchRange, revisions) {
|
||||
const base = this.getBaseUrl() + '/c/' + changeNum + '/';
|
||||
|
||||
// The change may not have loaded yet, making revisions unavailable.
|
||||
if (!revisions) {
|
||||
return base + this._patchRangeStr(patchRange);
|
||||
}
|
||||
|
||||
var latestPatchNum = -1;
|
||||
for (var rev in revisions) {
|
||||
latestPatchNum = Math.max(latestPatchNum, revisions[rev]._number);
|
||||
let latestPatchNum = -1;
|
||||
for (const rev of Object.values(revisions)) {
|
||||
latestPatchNum = Math.max(latestPatchNum, rev._number);
|
||||
}
|
||||
if (patchRange.basePatchNum !== 'PARENT' ||
|
||||
parseInt(patchRange.patchNum, 10) !== latestPatchNum) {
|
||||
@@ -540,11 +542,11 @@
|
||||
return base;
|
||||
},
|
||||
|
||||
_computeChangePath: function(changeNum, patchRangeRecord, revisions) {
|
||||
_computeChangePath(changeNum, patchRangeRecord, revisions) {
|
||||
return this._getChangePath(changeNum, patchRangeRecord.base, revisions);
|
||||
},
|
||||
|
||||
_computeFileDisplayName: function(path) {
|
||||
_computeFileDisplayName(path) {
|
||||
if (path === COMMIT_MESSAGE_PATH) {
|
||||
return 'Commit message';
|
||||
} else if (path === MERGE_LIST_PATH) {
|
||||
@@ -553,20 +555,20 @@
|
||||
return path;
|
||||
},
|
||||
|
||||
_computeTruncatedFileDisplayName: function(path) {
|
||||
_computeTruncatedFileDisplayName(path) {
|
||||
return util.truncatePath(this._computeFileDisplayName(path));
|
||||
},
|
||||
|
||||
_computeFileSelected: function(path, currentPath) {
|
||||
_computeFileSelected(path, currentPath) {
|
||||
return path == currentPath;
|
||||
},
|
||||
|
||||
_computePrefsButtonHidden: function(prefs, loggedIn) {
|
||||
_computePrefsButtonHidden(prefs, loggedIn) {
|
||||
return !loggedIn || !prefs;
|
||||
},
|
||||
|
||||
_computeKeyNav: function(path, selectedPath, fileList) {
|
||||
var selectedIndex = fileList.indexOf(selectedPath);
|
||||
_computeKeyNav(path, selectedPath, fileList) {
|
||||
const selectedIndex = fileList.indexOf(selectedPath);
|
||||
if (fileList.indexOf(path) == selectedIndex - 1) {
|
||||
return '[';
|
||||
}
|
||||
@@ -576,41 +578,41 @@
|
||||
return '';
|
||||
},
|
||||
|
||||
_handleFileTap: function(e) {
|
||||
_handleFileTap(e) {
|
||||
// async is needed so that that the click event is fired before the
|
||||
// dropdown closes (This was a bug for touch devices).
|
||||
this.async(function() {
|
||||
this.async(() => {
|
||||
this.$.dropdown.close();
|
||||
}, 1);
|
||||
},
|
||||
|
||||
_handleMobileSelectChange: function(e) {
|
||||
var path = Polymer.dom(e).rootTarget.value;
|
||||
_handleMobileSelectChange(e) {
|
||||
const path = Polymer.dom(e).rootTarget.value;
|
||||
page.show(this._getDiffURL(this._changeNum, this._patchRange, path));
|
||||
},
|
||||
|
||||
_showDropdownTapHandler: function(e) {
|
||||
_showDropdownTapHandler(e) {
|
||||
this.$.dropdown.open();
|
||||
},
|
||||
|
||||
_handlePrefsTap: function(e) {
|
||||
_handlePrefsTap(e) {
|
||||
e.preventDefault();
|
||||
this.$.diffPreferences.open();
|
||||
},
|
||||
|
||||
_handlePrefsSave: function(e) {
|
||||
_handlePrefsSave(e) {
|
||||
e.stopPropagation();
|
||||
var el = Polymer.dom(e).rootTarget;
|
||||
const el = Polymer.dom(e).rootTarget;
|
||||
el.disabled = true;
|
||||
this.$.storage.savePreferences(this._localPrefs);
|
||||
this._saveDiffPreferences().then(function(response) {
|
||||
this._saveDiffPreferences().then(response => {
|
||||
el.disabled = false;
|
||||
if (!response.ok) { return response; }
|
||||
|
||||
this.$.prefsOverlay.close();
|
||||
}.bind(this)).catch(function(err) {
|
||||
}).catch(err => {
|
||||
el.disabled = false;
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -627,7 +629,7 @@
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
_getDiffViewMode: function() {
|
||||
_getDiffViewMode() {
|
||||
if (this.changeViewState.diffMode) {
|
||||
return this.changeViewState.diffMode;
|
||||
} else if (this._userPrefs) {
|
||||
@@ -638,17 +640,17 @@
|
||||
}
|
||||
},
|
||||
|
||||
_computeModeSelectHidden: function() {
|
||||
_computeModeSelectHidden() {
|
||||
return this._isImageDiff;
|
||||
},
|
||||
|
||||
_onLineSelected: function(e, detail) {
|
||||
_onLineSelected(e, detail) {
|
||||
this.$.cursor.moveToLineNumber(detail.number, detail.side);
|
||||
history.replaceState(null, null, '#' + this.$.cursor.getAddress());
|
||||
},
|
||||
|
||||
_computeDownloadLink: function(changeNum, patchRange, path) {
|
||||
var url = this.changeBaseURL(changeNum, patchRange.patchNum);
|
||||
_computeDownloadLink(changeNum, patchRange, path) {
|
||||
let url = this.changeBaseURL(changeNum, patchRange.patchNum);
|
||||
url += '/patch?zip&path=' + encodeURIComponent(path);
|
||||
return url;
|
||||
},
|
||||
@@ -659,9 +661,9 @@
|
||||
* current patch range.
|
||||
* @return {Promise} A promise that yields a comment map object.
|
||||
*/
|
||||
_loadCommentMap: function() {
|
||||
function filterByRange(comment) {
|
||||
var patchNum = comment.patch_set + '';
|
||||
_loadCommentMap() {
|
||||
const filterByRange = comment => {
|
||||
const patchNum = comment.patch_set + '';
|
||||
return patchNum === this._patchRange.patchNum ||
|
||||
patchNum === this._patchRange.basePatchNum;
|
||||
};
|
||||
@@ -670,34 +672,34 @@
|
||||
this.$.restAPI.getDiffComments(this._changeNum),
|
||||
this._getDiffDrafts(),
|
||||
this.$.restAPI.getDiffRobotComments(this._changeNum),
|
||||
]).then(function(results) {
|
||||
var commentMap = {};
|
||||
results.forEach(function(response) {
|
||||
for (var path in response) {
|
||||
]).then(results => {
|
||||
const commentMap = {};
|
||||
for (const response of results) {
|
||||
for (const path in response) {
|
||||
if (response.hasOwnProperty(path) &&
|
||||
response[path].filter(filterByRange.bind(this)).length) {
|
||||
response[path].filter(filterByRange).length) {
|
||||
commentMap[path] = true;
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
return commentMap;
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
_getDiffDrafts: function() {
|
||||
return this._getLoggedIn().then(function(loggedIn) {
|
||||
_getDiffDrafts() {
|
||||
return this._getLoggedIn().then(loggedIn => {
|
||||
if (!loggedIn) { return Promise.resolve({}); }
|
||||
return this.$.restAPI.getDiffDrafts(this._changeNum);
|
||||
}.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
_computeCommentSkips: function(commentMap, fileList, path) {
|
||||
var skips = {previous: null, next: null};
|
||||
_computeCommentSkips(commentMap, fileList, path) {
|
||||
const skips = {previous: null, next: null};
|
||||
if (!fileList.length) { return skips; }
|
||||
var pathIndex = fileList.indexOf(path);
|
||||
const pathIndex = fileList.indexOf(path);
|
||||
|
||||
// Scan backward for the previous file.
|
||||
for (var i = pathIndex - 1; i >= 0; i--) {
|
||||
for (let i = pathIndex - 1; i >= 0; i--) {
|
||||
if (commentMap[fileList[i]]) {
|
||||
skips.previous = fileList[i];
|
||||
break;
|
||||
@@ -705,7 +707,7 @@
|
||||
}
|
||||
|
||||
// Scan forward for the next file.
|
||||
for (i = pathIndex + 1; i < fileList.length; i++) {
|
||||
for (let i = pathIndex + 1; i < fileList.length; i++) {
|
||||
if (commentMap[fileList[i]]) {
|
||||
skips.next = fileList[i];
|
||||
break;
|
||||
|
@@ -41,34 +41,34 @@ limitations under the License.
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
suite('gr-diff-view tests', function() {
|
||||
var element;
|
||||
var sandbox;
|
||||
suite('gr-diff-view tests', () => {
|
||||
let element;
|
||||
let sandbox;
|
||||
|
||||
setup(function() {
|
||||
setup(() => {
|
||||
sandbox = sinon.sandbox.create();
|
||||
|
||||
stub('gr-rest-api-interface', {
|
||||
getLoggedIn: function() { return Promise.resolve(false); },
|
||||
getProjectConfig: function() { return Promise.resolve({}); },
|
||||
getDiffChangeDetail: function() { return Promise.resolve(null); },
|
||||
getChangeFiles: function() { return Promise.resolve({}); },
|
||||
saveFileReviewed: function() { return Promise.resolve(); },
|
||||
getLoggedIn() { return Promise.resolve(false); },
|
||||
getProjectConfig() { return Promise.resolve({}); },
|
||||
getDiffChangeDetail() { return Promise.resolve(null); },
|
||||
getChangeFiles() { return Promise.resolve({}); },
|
||||
saveFileReviewed() { return Promise.resolve(); },
|
||||
});
|
||||
element = fixture('basic');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
teardown(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('toggle left diff with a hotkey', function() {
|
||||
var toggleLeftDiffStub = sandbox.stub(element.$.diff, 'toggleLeftDiff');
|
||||
test('toggle left diff with a hotkey', () => {
|
||||
const toggleLeftDiffStub = sandbox.stub(element.$.diff, 'toggleLeftDiff');
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 65, 'shift', 'a');
|
||||
assert.isTrue(toggleLeftDiffStub.calledOnce);
|
||||
});
|
||||
|
||||
test('keyboard shortcuts', function() {
|
||||
test('keyboard shortcuts', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: 'PARENT',
|
||||
@@ -83,7 +83,7 @@ limitations under the License.
|
||||
element._path = 'glados.txt';
|
||||
element.changeViewState.selectedFileIndex = 1;
|
||||
|
||||
var showStub = sandbox.stub(page, 'show');
|
||||
const showStub = sandbox.stub(page, 'show');
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 85, null, 'u');
|
||||
assert(showStub.lastCall.calledWithExactly('/c/42/'),
|
||||
'Should navigate to /c/42/');
|
||||
@@ -111,13 +111,14 @@ limitations under the License.
|
||||
'Should navigate to /c/42/');
|
||||
assert.equal(element.changeViewState.selectedFileIndex, 0);
|
||||
|
||||
var showPrefsStub = sandbox.stub(element.$.diffPreferences.$.prefsOverlay,
|
||||
'open', function() { return Promise.resolve({}); });
|
||||
const showPrefsStub =
|
||||
sandbox.stub(element.$.diffPreferences.$.prefsOverlay, 'open',
|
||||
() => Promise.resolve());
|
||||
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 188, null, ',');
|
||||
assert(showPrefsStub.calledOnce);
|
||||
|
||||
var scrollStub = sandbox.stub(element.$.cursor, 'moveToNextChunk');
|
||||
let scrollStub = sandbox.stub(element.$.cursor, 'moveToNextChunk');
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 78, null, 'n');
|
||||
assert(scrollStub.calledOnce);
|
||||
|
||||
@@ -134,7 +135,7 @@ limitations under the License.
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 80, 'shift', 'p');
|
||||
assert(scrollStub.calledOnce);
|
||||
|
||||
var computeContainerClassStub = sandbox.stub(element.$.diff,
|
||||
const computeContainerClassStub = sandbox.stub(element.$.diff,
|
||||
'_computeContainerClass');
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 74, null, 'j');
|
||||
assert(computeContainerClassStub.lastCall.calledWithExactly(
|
||||
@@ -145,7 +146,7 @@ limitations under the License.
|
||||
false, 'SIDE_BY_SIDE', false));
|
||||
});
|
||||
|
||||
test('keyboard shortcuts with patch range', function() {
|
||||
test('keyboard shortcuts with patch range', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: '5',
|
||||
@@ -159,7 +160,7 @@ limitations under the License.
|
||||
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
||||
element._path = 'glados.txt';
|
||||
|
||||
var showStub = sandbox.stub(page, 'show');
|
||||
const showStub = sandbox.stub(page, 'show');
|
||||
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 65, null, 'a');
|
||||
assert.isTrue(showStub.notCalled, 'The `a` keyboard shortcut should ' +
|
||||
@@ -198,7 +199,7 @@ limitations under the License.
|
||||
'Should navigate to /c/42/5..10');
|
||||
});
|
||||
|
||||
test('keyboard shortcuts with old patch number', function() {
|
||||
test('keyboard shortcuts with old patch number', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: 'PARENT',
|
||||
@@ -213,7 +214,7 @@ limitations under the License.
|
||||
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
||||
element._path = 'glados.txt';
|
||||
|
||||
var showStub = sandbox.stub(page, 'show');
|
||||
const showStub = sandbox.stub(page, 'show');
|
||||
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 65, null, 'a');
|
||||
assert.isTrue(showStub.notCalled, 'The `a` keyboard shortcut should ' +
|
||||
@@ -252,8 +253,7 @@ limitations under the License.
|
||||
'Should navigate to /c/42/1');
|
||||
});
|
||||
|
||||
test('Diff preferences hidden when no prefs or logged out',
|
||||
function() {
|
||||
test('Diff preferences hidden when no prefs or logged out', () => {
|
||||
element._loggedIn = false;
|
||||
flushAsynchronousOperations();
|
||||
assert.isTrue(element.$.diffPrefsContainer.hidden);
|
||||
@@ -263,7 +263,7 @@ limitations under the License.
|
||||
assert.isTrue(element.$.diffPrefsContainer.hidden);
|
||||
|
||||
element._loggedIn = false;
|
||||
element._prefs = {'font_size': '12'};
|
||||
element._prefs = {font_size: '12'};
|
||||
flushAsynchronousOperations();
|
||||
assert.isTrue(element.$.diffPrefsContainer.hidden);
|
||||
|
||||
@@ -272,11 +272,12 @@ limitations under the License.
|
||||
assert.isFalse(element.$.diffPrefsContainer.hidden);
|
||||
});
|
||||
|
||||
test('prefsButton opens gr-diff-preferences', function() {
|
||||
var handlePrefsTapSpy = sandbox.spy(element, '_handlePrefsTap');
|
||||
var overlayOpenStub = sandbox.stub(element.$.diffPreferences,
|
||||
test('prefsButton opens gr-diff-preferences', () => {
|
||||
const handlePrefsTapSpy = sandbox.spy(element, '_handlePrefsTap');
|
||||
const overlayOpenStub = sandbox.stub(element.$.diffPreferences,
|
||||
'open');
|
||||
var prefsButton = Polymer.dom(element.root).querySelector('.prefsButton');
|
||||
const prefsButton =
|
||||
Polymer.dom(element.root).querySelector('.prefsButton');
|
||||
|
||||
MockInteractions.tap(prefsButton);
|
||||
|
||||
@@ -284,7 +285,7 @@ limitations under the License.
|
||||
assert.isTrue(overlayOpenStub.called);
|
||||
});
|
||||
|
||||
test('go up to change via kb without change loaded', function() {
|
||||
test('go up to change via kb without change loaded', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: 'PARENT',
|
||||
@@ -294,7 +295,7 @@ limitations under the License.
|
||||
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
||||
element._path = 'glados.txt';
|
||||
|
||||
var showStub = sandbox.stub(page, 'show');
|
||||
const showStub = sandbox.stub(page, 'show');
|
||||
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 65, null, 'a');
|
||||
assert.isTrue(showStub.notCalled, 'The `a` keyboard shortcut should ' +
|
||||
@@ -333,7 +334,7 @@ limitations under the License.
|
||||
'Should navigate to /c/42/1');
|
||||
});
|
||||
|
||||
test('jump to file dropdown', function() {
|
||||
test('jump to file dropdown', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: 'PARENT',
|
||||
@@ -342,7 +343,7 @@ limitations under the License.
|
||||
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
||||
element._path = 'glados.txt';
|
||||
flushAsynchronousOperations();
|
||||
var linkEls =
|
||||
const linkEls =
|
||||
Polymer.dom(element.root).querySelectorAll('.dropdown-content > a');
|
||||
assert.equal(linkEls.length, 3);
|
||||
assert.isFalse(linkEls[0].hasAttribute('selected'));
|
||||
@@ -363,7 +364,7 @@ limitations under the License.
|
||||
'Merge list');
|
||||
});
|
||||
|
||||
test('jump to file dropdown with patch range', function() {
|
||||
test('jump to file dropdown with patch range', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: '5',
|
||||
@@ -372,7 +373,7 @@ limitations under the License.
|
||||
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
||||
element._path = 'glados.txt';
|
||||
flushAsynchronousOperations();
|
||||
var linkEls =
|
||||
const linkEls =
|
||||
Polymer.dom(element.root).querySelectorAll('.dropdown-content > a');
|
||||
assert.equal(linkEls.length, 3);
|
||||
assert.isFalse(linkEls[0].hasAttribute('selected'));
|
||||
@@ -386,7 +387,7 @@ limitations under the License.
|
||||
assert.equal(linkEls[2].getAttribute('href'), '/c/42/5..10/wheatley.md');
|
||||
});
|
||||
|
||||
test('prev/up/next links', function() {
|
||||
test('prev/up/next links', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: 'PARENT',
|
||||
@@ -400,7 +401,7 @@ limitations under the License.
|
||||
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
||||
element._path = 'glados.txt';
|
||||
flushAsynchronousOperations();
|
||||
var linkEls = Polymer.dom(element.root).querySelectorAll('.navLink');
|
||||
const linkEls = Polymer.dom(element.root).querySelectorAll('.navLink');
|
||||
assert.equal(linkEls.length, 3);
|
||||
assert.equal(linkEls[0].getAttribute('href'), '/c/42/10/chell.go');
|
||||
assert.equal(linkEls[1].getAttribute('href'), '/c/42/');
|
||||
@@ -422,7 +423,7 @@ limitations under the License.
|
||||
assert.equal(linkEls[2].getAttribute('href'), '/c/42/10/chell.go');
|
||||
});
|
||||
|
||||
test('download link', function() {
|
||||
test('download link', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: 'PARENT',
|
||||
@@ -435,7 +436,7 @@ limitations under the License.
|
||||
'/changes/42/revisions/10/patch?zip&path=glados.txt');
|
||||
});
|
||||
|
||||
test('prev/up/next links with patch range', function() {
|
||||
test('prev/up/next links with patch range', () => {
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
basePatchNum: '5',
|
||||
@@ -450,7 +451,7 @@ limitations under the License.
|
||||
element._fileList = ['chell.go', 'glados.txt', 'wheatley.md'];
|
||||
element._path = 'glados.txt';
|
||||
flushAsynchronousOperations();
|
||||
var linkEls = Polymer.dom(element.root).querySelectorAll('.navLink');
|
||||
const linkEls = Polymer.dom(element.root).querySelectorAll('.navLink');
|
||||
assert.equal(linkEls.length, 3);
|
||||
assert.equal(linkEls[0].getAttribute('href'), '/c/42/5..10/chell.go');
|
||||
assert.equal(linkEls[1].getAttribute('href'), '/c/42/5..10');
|
||||
@@ -467,7 +468,7 @@ limitations under the License.
|
||||
assert.equal(linkEls[2].getAttribute('href'), '/c/42/5..10/glados.txt');
|
||||
});
|
||||
|
||||
test('file review status', function(done) {
|
||||
test('file review status', done => {
|
||||
element._loggedIn = true;
|
||||
element._changeNum = '42';
|
||||
element._patchRange = {
|
||||
@@ -476,11 +477,11 @@ limitations under the License.
|
||||
};
|
||||
element._fileList = ['/COMMIT_MSG'];
|
||||
element._path = '/COMMIT_MSG';
|
||||
var saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
||||
function() { return Promise.resolve(); });
|
||||
const saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
||||
() => Promise.resolve());
|
||||
|
||||
flush(function() {
|
||||
var commitMsg = Polymer.dom(element.root).querySelector(
|
||||
flush(() => {
|
||||
const commitMsg = Polymer.dom(element.root).querySelector(
|
||||
'input[type="checkbox"]');
|
||||
|
||||
assert.isTrue(commitMsg.checked);
|
||||
@@ -496,9 +497,9 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
|
||||
test('diff mode selector correctly toggles the diff', function() {
|
||||
var select = element.$.modeSelect;
|
||||
var diffDisplay = element.$.diff;
|
||||
test('diff mode selector correctly toggles the diff', () => {
|
||||
const select = element.$.modeSelect;
|
||||
const diffDisplay = element.$.diff;
|
||||
element._userPrefs = {default_diff_view: 'SIDE_BY_SIDE'};
|
||||
|
||||
// The mode selected in the view state reflects the selected option.
|
||||
@@ -509,7 +510,7 @@ limitations under the License.
|
||||
assert.equal(select.value, diffDisplay.viewMode);
|
||||
|
||||
// We will simulate a user change of the selected mode.
|
||||
var newMode = 'UNIFIED_DIFF';
|
||||
const newMode = 'UNIFIED_DIFF';
|
||||
// Set the actual value of the select, and simulate the change event.
|
||||
select.value = newMode;
|
||||
element.fire('change', {}, {node: select});
|
||||
@@ -520,17 +521,16 @@ limitations under the License.
|
||||
assert.equal(element._getDiffViewMode(), diffDisplay.viewMode);
|
||||
});
|
||||
|
||||
test('diff mode selector initializes from preferences', function() {
|
||||
var resolvePrefs;
|
||||
var prefsPromise = new Promise(function(resolve) {
|
||||
test('diff mode selector initializes from preferences', () => {
|
||||
let resolvePrefs;
|
||||
const prefsPromise = new Promise(resolve => {
|
||||
resolvePrefs = resolve;
|
||||
});
|
||||
var getPreferencesStub = sandbox.stub(element.$.restAPI, 'getPreferences',
|
||||
function() { return prefsPromise; });
|
||||
sandbox.stub(element.$.restAPI, 'getPreferences', () => prefsPromise);
|
||||
|
||||
// Attach a new gr-diff-view so we can intercept the preferences fetch.
|
||||
var view = document.createElement('gr-diff-view');
|
||||
var select = view.$.modeSelect;
|
||||
const view = document.createElement('gr-diff-view');
|
||||
const select = view.$.modeSelect;
|
||||
fixture('blank').appendChild(view);
|
||||
flushAsynchronousOperations();
|
||||
|
||||
@@ -543,7 +543,7 @@ limitations under the License.
|
||||
assert.equal(select.value, 'SIDE_BY_SIDE');
|
||||
});
|
||||
|
||||
test('_loadHash', function() {
|
||||
test('_loadHash', () => {
|
||||
assert.isNotOk(element.$.cursor.initialLineNumber);
|
||||
|
||||
// Ignores invalid hashes:
|
||||
@@ -566,32 +566,31 @@ limitations under the License.
|
||||
assert.equal(element.$.cursor.side, 'left');
|
||||
});
|
||||
|
||||
test('_shortenPath with long path should add ellipsis', function() {
|
||||
var path =
|
||||
'level1/level2/level3/level4/file.js';
|
||||
var shortenedPath = util.truncatePath(path);
|
||||
test('_shortenPath with long path should add ellipsis', () => {
|
||||
let path = 'level1/level2/level3/level4/file.js';
|
||||
let shortenedPath = util.truncatePath(path);
|
||||
// The expected path is truncated with an ellipsis.
|
||||
var expectedPath = '\u2026/file.js';
|
||||
const expectedPath = '\u2026/file.js';
|
||||
assert.equal(shortenedPath, expectedPath);
|
||||
|
||||
var path = 'level2/file.js';
|
||||
var shortenedPath = util.truncatePath(path);
|
||||
path = 'level2/file.js';
|
||||
shortenedPath = util.truncatePath(path);
|
||||
assert.equal(shortenedPath, expectedPath);
|
||||
});
|
||||
|
||||
test('_shortenPath with short path should not add ellipsis', function() {
|
||||
var path = 'file.js';
|
||||
var expectedPath = 'file.js';
|
||||
var shortenedPath = util.truncatePath(path);
|
||||
test('_shortenPath with short path should not add ellipsis', () => {
|
||||
const path = 'file.js';
|
||||
const expectedPath = 'file.js';
|
||||
const shortenedPath = util.truncatePath(path);
|
||||
assert.equal(shortenedPath, expectedPath);
|
||||
});
|
||||
|
||||
test('_onLineSelected', function() {
|
||||
var replaceStateStub = sandbox.stub(history, 'replaceState');
|
||||
var moveStub = sandbox.stub(element.$.cursor, 'moveToLineNumber');
|
||||
test('_onLineSelected', () => {
|
||||
const replaceStateStub = sandbox.stub(history, 'replaceState');
|
||||
const moveStub = sandbox.stub(element.$.cursor, 'moveToLineNumber');
|
||||
|
||||
var e = {};
|
||||
var detail = {number: 123, side: 'right'};
|
||||
const e = {};
|
||||
const detail = {number: 123, side: 'right'};
|
||||
|
||||
element._onLineSelected(e, detail);
|
||||
|
||||
@@ -602,15 +601,15 @@ limitations under the License.
|
||||
assert.isTrue(replaceStateStub.called);
|
||||
});
|
||||
|
||||
test('_getDiffURL encodes special characters', function() {
|
||||
var changeNum = 123;
|
||||
var patchRange = {basePatchNum: 123, patchNum: 456};
|
||||
var path = 'c++/cpp.cpp';
|
||||
test('_getDiffURL encodes special characters', () => {
|
||||
const changeNum = 123;
|
||||
const patchRange = {basePatchNum: 123, patchNum: 456};
|
||||
const path = 'c++/cpp.cpp';
|
||||
assert.equal(element._getDiffURL(changeNum, patchRange, path),
|
||||
'/c/123/123..456/c%252B%252B/cpp.cpp');
|
||||
});
|
||||
|
||||
test('_getDiffViewMode', function() {
|
||||
test('_getDiffViewMode', () => {
|
||||
// No user prefs or change view state set.
|
||||
assert.equal(element._getDiffViewMode(), 'SIDE_BY_SIDE');
|
||||
|
||||
@@ -623,22 +622,22 @@ limitations under the License.
|
||||
assert.equal(element._getDiffViewMode(), 'SIDE_BY_SIDE');
|
||||
});
|
||||
|
||||
suite('_loadCommentMap', function() {
|
||||
test('empty', function(done) {
|
||||
suite('_loadCommentMap', () => {
|
||||
test('empty', done => {
|
||||
stub('gr-rest-api-interface', {
|
||||
getDiffRobotComments: function() { return Promise.resolve({}); },
|
||||
getDiffComments: function() { return Promise.resolve({}); },
|
||||
getDiffRobotComments() { return Promise.resolve({}); },
|
||||
getDiffComments() { return Promise.resolve({}); },
|
||||
});
|
||||
element._loadCommentMap().then(function(map) {
|
||||
element._loadCommentMap().then(map => {
|
||||
assert.equal(Object.keys(map).length, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('paths in patch range', function(done) {
|
||||
test('paths in patch range', done => {
|
||||
stub('gr-rest-api-interface', {
|
||||
getDiffRobotComments: function() { return Promise.resolve({}); },
|
||||
getDiffComments: function() {
|
||||
getDiffRobotComments() { return Promise.resolve({}); },
|
||||
getDiffComments() {
|
||||
return Promise.resolve({
|
||||
'path/to/file/one.cpp': [{patch_set: 3, message: 'lorem'}],
|
||||
'path-to/file/two.py': [{patch_set: 5, message: 'ipsum'}],
|
||||
@@ -650,17 +649,17 @@ limitations under the License.
|
||||
basePatchNum: '3',
|
||||
patchNum: '5',
|
||||
};
|
||||
element._loadCommentMap().then(function(map) {
|
||||
element._loadCommentMap().then(map => {
|
||||
assert.deepEqual(Object.keys(map),
|
||||
['path/to/file/one.cpp', 'path-to/file/two.py']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('empty for paths outside patch range', function(done) {
|
||||
test('empty for paths outside patch range', done => {
|
||||
stub('gr-rest-api-interface', {
|
||||
getDiffRobotComments: function() { return Promise.resolve({}); },
|
||||
getDiffComments: function() {
|
||||
getDiffRobotComments() { return Promise.resolve({}); },
|
||||
getDiffComments() {
|
||||
return Promise.resolve({
|
||||
'path/to/file/one.cpp': [{patch_set: 'PARENT', message: 'lorem'}],
|
||||
'path-to/file/two.py': [{patch_set: 2, message: 'ipsum'}],
|
||||
@@ -672,35 +671,35 @@ limitations under the License.
|
||||
basePatchNum: '3',
|
||||
patchNum: '5',
|
||||
};
|
||||
element._loadCommentMap().then(function(map) {
|
||||
element._loadCommentMap().then(map => {
|
||||
assert.equal(Object.keys(map).length, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('_computeCommentSkips', function() {
|
||||
test('empty file list', function() {
|
||||
var commentMap = {
|
||||
suite('_computeCommentSkips', () => {
|
||||
test('empty file list', () => {
|
||||
const commentMap = {
|
||||
'path/one.jpg': true,
|
||||
'path/three.wav': true,
|
||||
};
|
||||
var path = 'path/two.m4v';
|
||||
var fileList = [];
|
||||
var result = element._computeCommentSkips(commentMap, fileList, path);
|
||||
const path = 'path/two.m4v';
|
||||
const fileList = [];
|
||||
const result = element._computeCommentSkips(commentMap, fileList, path);
|
||||
assert.isNull(result.previous);
|
||||
assert.isNull(result.next);
|
||||
});
|
||||
|
||||
test('finds skips', function() {
|
||||
var fileList = ['path/one.jpg', 'path/two.m4v', 'path/three.wav'];
|
||||
var path = fileList[1];
|
||||
var commentMap = {};
|
||||
test('finds skips', () => {
|
||||
const fileList = ['path/one.jpg', 'path/two.m4v', 'path/three.wav'];
|
||||
let path = fileList[1];
|
||||
const commentMap = {};
|
||||
commentMap[fileList[0]] = true;
|
||||
commentMap[fileList[1]] = false;
|
||||
commentMap[fileList[2]] = true;
|
||||
|
||||
var result = element._computeCommentSkips(commentMap, fileList, path);
|
||||
let result = element._computeCommentSkips(commentMap, fileList, path);
|
||||
assert.equal(result.previous, fileList[0]);
|
||||
assert.equal(result.next, fileList[2]);
|
||||
|
||||
|
Reference in New Issue
Block a user