ES6ify /gr-diff-comment-thread-group/*
Bug: Issue 6179
Change-Id: I2f25f8aeae703c3a3ee7b22103902773065d845c
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js
index df75d52..7899fc7 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group.js
@@ -21,7 +21,7 @@
changeNum: String,
comments: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
patchForNewThreads: String,
projectConfig: Object,
@@ -32,7 +32,7 @@
},
_threads: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
},
},
@@ -40,16 +40,16 @@
'_commentsChanged(comments.*)',
],
- addNewThread: function(locationRange) {
+ addNewThread(locationRange) {
this.push('_threads', {
comments: [],
- locationRange: locationRange,
+ locationRange,
patchNum: this.patchForNewThreads,
});
},
- removeThread: function(locationRange) {
- for (var i = 0; i < this._threads.length; i++) {
+ removeThread(locationRange) {
+ for (let i = 0; i < this._threads.length; i++) {
if (this._threads[i].locationRange === locationRange) {
this.splice('_threads', i, 1);
return;
@@ -57,10 +57,10 @@
}
},
- getThreadForRange: function(rangeToCheck) {
- var threads = [].filter.call(
+ getThreadForRange(rangeToCheck) {
+ const threads = [].filter.call(
Polymer.dom(this.root).querySelectorAll('gr-diff-comment-thread'),
- function(thread) {
+ thread => {
return thread.locationRange === rangeToCheck;
});
if (threads.length === 1) {
@@ -68,13 +68,13 @@
}
},
- _commentsChanged: function() {
+ _commentsChanged() {
this._threads = this._getThreadGroups(this.comments);
},
- _sortByDate: function(threadGroups) {
+ _sortByDate(threadGroups) {
if (!threadGroups.length) { return; }
- return threadGroups.sort(function(a, b) {
+ return threadGroups.sort((a, b) => {
// If a comment is a draft, it doesn't have a start_datetime yet.
// Assume it is newer than the comment it is being compared to.
if (!a.start_datetime) {
@@ -88,7 +88,7 @@
});
},
- _calculateLocationRange: function(range, comment) {
+ _calculateLocationRange(range, comment) {
return 'range-' + range.start_line + '-' +
range.start_character + '-' +
range.end_line + '-' +
@@ -102,15 +102,15 @@
* This is needed for switching between side-by-side and unified views when
* there are unsaved drafts.
*/
- _getPatchNum: function(comment) {
+ _getPatchNum(comment) {
return comment.patchNum || this.patchForNewThreads;
},
- _getThreadGroups: function(comments) {
- var threadGroups = {};
+ _getThreadGroups(comments) {
+ const threadGroups = {};
- comments.forEach(function(comment) {
- var locationRange;
+ for (const comment of comments) {
+ let locationRange;
if (!comment.range) {
locationRange = 'line-' + comment.__commentSide;
} else {
@@ -123,18 +123,18 @@
threadGroups[locationRange] = {
start_datetime: comment.updated,
comments: [comment],
- locationRange: locationRange,
+ locationRange,
commentSide: comment.__commentSide,
patchNum: this._getPatchNum(comment),
};
}
- }.bind(this));
+ }
- var threadGroupArr = [];
- var threadGroupKeys = Object.keys(threadGroups);
- threadGroupKeys.forEach(function(threadGroupKey) {
+ const threadGroupArr = [];
+ const threadGroupKeys = Object.keys(threadGroups);
+ for (const threadGroupKey of threadGroupKeys) {
threadGroupArr.push(threadGroups[threadGroupKey]);
- });
+ }
return this._sortByDate(threadGroupArr);
},
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html
index 53a8e81..056b74f 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html
@@ -34,25 +34,25 @@
</test-fixture>
<script>
- suite('gr-diff-comment-thread-group tests', function() {
- var element;
- var sandbox;
+ suite('gr-diff-comment-thread-group tests', () => {
+ let element;
+ let sandbox;
- setup(function() {
+ setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', {
- getLoggedIn: function() { return Promise.resolve(false); },
+ getLoggedIn() { return Promise.resolve(false); },
});
element = fixture('basic');
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
});
- test('_getThreadGroups', function() {
+ test('_getThreadGroups', () => {
element.patchForNewThreads = 3;
- var comments = [
+ const comments = [
{
id: 'sallys_confession',
message: 'i like you, jack',
@@ -66,23 +66,23 @@
},
];
- var expectedThreadGroups = [
+ let expectedThreadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
commentSide: 'left',
comments: [{
- id: 'sallys_confession',
- message: 'i like you, jack',
- updated: '2015-12-23 15:00:20.396000000',
- __commentSide: 'left',
- }, {
- id: 'jacks_reply',
- message: 'i like you, too',
- updated: '2015-12-24 15:00:20.396000000',
- __commentSide: 'left',
- }],
+ id: 'sallys_confession',
+ message: 'i like you, jack',
+ updated: '2015-12-23 15:00:20.396000000',
+ __commentSide: 'left',
+ }, {
+ id: 'jacks_reply',
+ message: 'i like you, too',
+ updated: '2015-12-24 15:00:20.396000000',
+ __commentSide: 'left',
+ }],
locationRange: 'line-left',
- patchNum: 3
+ patchNum: 3,
},
];
@@ -91,33 +91,33 @@
// Patch num should get inherited from comment rather
comments.push({
- id: 'betsys_confession',
- message: 'i like you, jack',
- updated: '2015-12-24 15:00:10.396000000',
- range: {
- start_line: 1,
- start_character: 1,
- end_line: 1,
- end_character: 2,
- },
- __commentSide: 'left',
- });
+ id: 'betsys_confession',
+ message: 'i like you, jack',
+ updated: '2015-12-24 15:00:10.396000000',
+ range: {
+ start_line: 1,
+ start_character: 1,
+ end_line: 1,
+ end_character: 2,
+ },
+ __commentSide: 'left',
+ });
expectedThreadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
commentSide: 'left',
comments: [{
- id: 'sallys_confession',
- message: 'i like you, jack',
- updated: '2015-12-23 15:00:20.396000000',
- __commentSide: 'left',
- }, {
- id: 'jacks_reply',
- message: 'i like you, too',
- updated: '2015-12-24 15:00:20.396000000',
- __commentSide: 'left',
- }],
+ id: 'sallys_confession',
+ message: 'i like you, jack',
+ updated: '2015-12-23 15:00:20.396000000',
+ __commentSide: 'left',
+ }, {
+ id: 'jacks_reply',
+ message: 'i like you, too',
+ updated: '2015-12-24 15:00:20.396000000',
+ __commentSide: 'left',
+ }],
patchNum: 3,
locationRange: 'line-left',
},
@@ -145,8 +145,8 @@
expectedThreadGroups);
});
- test('_sortByDate', function() {
- var threadGroups = [
+ test('_sortByDate', () => {
+ let threadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
@@ -159,12 +159,12 @@
},
];
- var expectedResult = [
+ let expectedResult = [
{
start_datetime: '2015-12-22 15:00:10.396000000',
comments: [],
locationRange: 'range-1-1-1-2',
- },{
+ }, {
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
locationRange: 'line',
@@ -175,7 +175,7 @@
// When a comment doesn't have a date, the one without the date should be
// last.
- var threadGroups = [
+ threadGroups = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
@@ -187,7 +187,7 @@
},
];
- var expectedResult = [
+ expectedResult = [
{
start_datetime: '2015-12-23 15:00:20.396000000',
comments: [],
@@ -198,22 +198,25 @@
locationRange: 'range-1-1-1-2',
},
];
+
+ assert.deepEqual(element._sortByDate(threadGroups), expectedResult);
});
- test('_calculateLocationRange', function() {
- var comment = {__commentSide: 'left'};
- var range = {
+ test('_calculateLocationRange', () => {
+ const comment = {__commentSide: 'left'};
+ const range = {
start_line: 1,
start_character: 2,
end_line: 3,
end_character: 4,
};
assert.equal(
- element._calculateLocationRange(range, comment), 'range-1-2-3-4-left');
+ element._calculateLocationRange(range, comment),
+ 'range-1-2-3-4-left');
});
- test('thread groups are updated when comments change', function() {
- var commentsChangedStub = sandbox.stub(element, '_commentsChanged');
+ test('thread groups are updated when comments change', () => {
+ const commentsChangedStub = sandbox.stub(element, '_commentsChanged');
element.comments = [];
element.comments.push({
id: 'sallys_confession',
@@ -223,16 +226,16 @@
assert(commentsChangedStub.called);
});
- test('addNewThread', function() {
- var locationRange = 'range-1-2-3-4';
+ test('addNewThread', () => {
+ const locationRange = 'range-1-2-3-4';
element._threads = [{locationRange: 'line'}];
element.addNewThread(locationRange);
assert(element._threads.length, 2);
});
- test('_getPatchNum', function() {
+ test('_getPatchNum', () => {
element.patchForNewThreads = 3;
- var comment = {
+ const comment = {
id: 'sallys_confession',
message: 'i like you, jack',
updated: '2015-12-23 15:00:20.396000000',
@@ -242,11 +245,11 @@
assert.equal(element._getPatchNum(comment), 4);
});
- test('removeThread', function() {
- var locationRange = 'range-1-2-3-4';
+ test('removeThread', () => {
+ const locationRange = 'range-1-2-3-4';
element._threads = [
{locationRange: 'range-1-2-3-4', comments: []},
- {locationRange: 'line', comments: []}
+ {locationRange: 'line', comments: []},
];
flushAsynchronousOperations();
element.removeThread(locationRange);