ES6ify /gr-diff-comment-thread/*
Bug: Issue 6179 Change-Id: Ib850e99830ff4a750a57e404d069d7bf364469fe
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var UNRESOLVED_EXPAND_COUNT = 5;
|
||||
var NEWLINE_PATTERN = /\n/g;
|
||||
const UNRESOLVED_EXPAND_COUNT = 5;
|
||||
const NEWLINE_PATTERN = /\n/g;
|
||||
|
||||
Polymer({
|
||||
is: 'gr-diff-comment-thread',
|
||||
@@ -30,12 +30,12 @@
|
||||
changeNum: String,
|
||||
comments: {
|
||||
type: Array,
|
||||
value: function() { return []; },
|
||||
value() { return []; },
|
||||
},
|
||||
locationRange: String,
|
||||
keyEventTarget: {
|
||||
type: Object,
|
||||
value: function() { return document.body; },
|
||||
value() { return document.body; },
|
||||
},
|
||||
commentSide: String,
|
||||
patchNum: String,
|
||||
@@ -71,17 +71,17 @@
|
||||
'e shift+e': '_handleEKey',
|
||||
},
|
||||
|
||||
attached: function() {
|
||||
this._getLoggedIn().then(function(loggedIn) {
|
||||
attached() {
|
||||
this._getLoggedIn().then(loggedIn => {
|
||||
this._showActions = loggedIn;
|
||||
}.bind(this));
|
||||
});
|
||||
this._setInitialExpandedState();
|
||||
},
|
||||
|
||||
addOrEditDraft: function(opt_lineNum, opt_range) {
|
||||
var lastComment = this.comments[this.comments.length - 1] || {};
|
||||
addOrEditDraft(opt_lineNum, opt_range) {
|
||||
const lastComment = this.comments[this.comments.length - 1] || {};
|
||||
if (lastComment.__draft) {
|
||||
var commentEl = this._commentElWithDraftID(
|
||||
const commentEl = this._commentElWithDraftID(
|
||||
lastComment.id || lastComment.__draftID);
|
||||
commentEl.editing = true;
|
||||
|
||||
@@ -89,25 +89,25 @@
|
||||
// actions are available.
|
||||
commentEl.collapsed = false;
|
||||
} else {
|
||||
var range = opt_range ? opt_range :
|
||||
const range = opt_range ? opt_range :
|
||||
lastComment ? lastComment.range : undefined;
|
||||
var unresolved = lastComment ? lastComment.unresolved : undefined;
|
||||
const unresolved = lastComment ? lastComment.unresolved : undefined;
|
||||
this.addDraft(opt_lineNum, range, unresolved);
|
||||
}
|
||||
},
|
||||
|
||||
addDraft: function(opt_lineNum, opt_range, opt_unresolved) {
|
||||
var draft = this._newDraft(opt_lineNum, opt_range);
|
||||
addDraft(opt_lineNum, opt_range, opt_unresolved) {
|
||||
const draft = this._newDraft(opt_lineNum, opt_range);
|
||||
draft.__editing = true;
|
||||
draft.unresolved = opt_unresolved === false ? opt_unresolved : true;
|
||||
this.push('comments', draft);
|
||||
},
|
||||
|
||||
_getLoggedIn: function() {
|
||||
_getLoggedIn() {
|
||||
return this.$.restAPI.getLoggedIn();
|
||||
},
|
||||
|
||||
_commentsChanged: function(changeRecord) {
|
||||
_commentsChanged(changeRecord) {
|
||||
this._orderedComments = this._sortedComments(this.comments);
|
||||
if (this._orderedComments.length) {
|
||||
this._lastComment = this._getLastComment();
|
||||
@@ -115,15 +115,15 @@
|
||||
}
|
||||
},
|
||||
|
||||
_hideActions: function(_showActions, _lastComment) {
|
||||
_hideActions(_showActions, _lastComment) {
|
||||
return !_showActions || !_lastComment || !!_lastComment.__draft;
|
||||
},
|
||||
|
||||
_getLastComment: function() {
|
||||
_getLastComment() {
|
||||
return this._orderedComments[this._orderedComments.length - 1] || {};
|
||||
},
|
||||
|
||||
_handleEKey: function(e) {
|
||||
_handleEKey(e) {
|
||||
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
||||
|
||||
// Don’t preventDefault in this case because it will render the event
|
||||
@@ -136,12 +136,12 @@
|
||||
}
|
||||
},
|
||||
|
||||
_expandCollapseComments: function(actionIsCollapse) {
|
||||
var comments =
|
||||
_expandCollapseComments(actionIsCollapse) {
|
||||
const comments =
|
||||
Polymer.dom(this.root).querySelectorAll('gr-diff-comment');
|
||||
comments.forEach(function(comment) {
|
||||
for (const comment of comments) {
|
||||
comment.collapsed = actionIsCollapse;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -149,33 +149,32 @@
|
||||
* {UNRESOLVED_EXPAND_COUNT} comments expanded by default if the
|
||||
* thread is unresolved.
|
||||
*/
|
||||
_setInitialExpandedState: function() {
|
||||
var comment;
|
||||
_setInitialExpandedState() {
|
||||
let comment;
|
||||
if (this._orderedComments) {
|
||||
for (var i = 0; i < this._orderedComments.length; i++) {
|
||||
for (let i = 0; i < this._orderedComments.length; i++) {
|
||||
comment = this._orderedComments[i];
|
||||
comment.collapsed =
|
||||
this._orderedComments.length - i - 1 >= UNRESOLVED_EXPAND_COUNT ||
|
||||
!this._unresolved;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_sortedComments: function(comments) {
|
||||
return comments.slice().sort(function(c1, c2) {
|
||||
var c1Date = c1.__date || util.parseDate(c1.updated);
|
||||
var c2Date = c2.__date || util.parseDate(c2.updated);
|
||||
var dateCompare = c1Date - c2Date;
|
||||
_sortedComments(comments) {
|
||||
return comments.slice().sort((c1, c2) => {
|
||||
const c1Date = c1.__date || util.parseDate(c1.updated);
|
||||
const c2Date = c2.__date || util.parseDate(c2.updated);
|
||||
const dateCompare = c1Date - c2Date;
|
||||
if (!c1.id || !c1.id.localeCompare) { return 0; }
|
||||
// If same date, fall back to sorting by id.
|
||||
return dateCompare ? dateCompare : c1.id.localeCompare(c2.id);
|
||||
});
|
||||
},
|
||||
|
||||
_createReplyComment: function(parent, content, opt_isEditing,
|
||||
_createReplyComment(parent, content, opt_isEditing,
|
||||
opt_unresolved) {
|
||||
var reply = this._newReply(
|
||||
const reply = this._newReply(
|
||||
this._orderedComments[this._orderedComments.length - 1].id,
|
||||
parent.line,
|
||||
content,
|
||||
@@ -184,7 +183,7 @@
|
||||
|
||||
// If there is currently a comment in an editing state, add an attribute
|
||||
// so that the gr-diff-comment knows not to populate the draft text.
|
||||
for (var i = 0; i < this.comments.length; i++) {
|
||||
for (let i = 0; i < this.comments.length; i++) {
|
||||
if (this.comments[i].__editing) {
|
||||
reply.__otherEditing = true;
|
||||
break;
|
||||
@@ -199,62 +198,62 @@
|
||||
|
||||
if (!opt_isEditing) {
|
||||
// Allow the reply to render in the dom-repeat.
|
||||
this.async(function() {
|
||||
var commentEl = this._commentElWithDraftID(reply.__draftID);
|
||||
this.async(() => {
|
||||
const commentEl = this._commentElWithDraftID(reply.__draftID);
|
||||
commentEl.save();
|
||||
}, 1);
|
||||
}
|
||||
},
|
||||
|
||||
_processCommentReply: function(opt_quote) {
|
||||
var comment = this._lastComment;
|
||||
var quoteStr;
|
||||
_processCommentReply(opt_quote) {
|
||||
const comment = this._lastComment;
|
||||
let quoteStr;
|
||||
if (opt_quote) {
|
||||
var msg = comment.message;
|
||||
const msg = comment.message;
|
||||
quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
|
||||
}
|
||||
this._createReplyComment(comment, quoteStr, true, comment.unresolved);
|
||||
},
|
||||
|
||||
_handleCommentReply: function(e) {
|
||||
_handleCommentReply(e) {
|
||||
this._processCommentReply();
|
||||
},
|
||||
|
||||
_handleCommentQuote: function(e) {
|
||||
_handleCommentQuote(e) {
|
||||
this._processCommentReply(true);
|
||||
},
|
||||
|
||||
_handleCommentAck: function(e) {
|
||||
var comment = this._lastComment;
|
||||
_handleCommentAck(e) {
|
||||
const comment = this._lastComment;
|
||||
this._createReplyComment(comment, 'Ack', false, false);
|
||||
},
|
||||
|
||||
_handleCommentDone: function(e) {
|
||||
var comment = this._lastComment;
|
||||
_handleCommentDone(e) {
|
||||
const comment = this._lastComment;
|
||||
this._createReplyComment(comment, 'Done', false, false);
|
||||
},
|
||||
|
||||
_handleCommentFix: function(e) {
|
||||
var comment = e.detail.comment;
|
||||
var msg = comment.message;
|
||||
var quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
|
||||
var response = quoteStr + 'Please Fix';
|
||||
_handleCommentFix(e) {
|
||||
const comment = e.detail.comment;
|
||||
const msg = comment.message;
|
||||
const quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
|
||||
const response = quoteStr + 'Please Fix';
|
||||
this._createReplyComment(comment, response, false, true);
|
||||
},
|
||||
|
||||
_commentElWithDraftID: function(id) {
|
||||
var els = Polymer.dom(this.root).querySelectorAll('gr-diff-comment');
|
||||
for (var i = 0; i < els.length; i++) {
|
||||
if (els[i].comment.id === id || els[i].comment.__draftID === id) {
|
||||
return els[i];
|
||||
_commentElWithDraftID(id) {
|
||||
const els = Polymer.dom(this.root).querySelectorAll('gr-diff-comment');
|
||||
for (const el of els) {
|
||||
if (el.comment.id === id || el.comment.__draftID === id) {
|
||||
return el;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
_newReply: function(inReplyTo, opt_lineNum, opt_message, opt_unresolved,
|
||||
opt_range) {
|
||||
var d = this._newDraft(opt_lineNum);
|
||||
_newReply(inReplyTo, opt_lineNum, opt_message, opt_unresolved,
|
||||
opt_range) {
|
||||
const d = this._newDraft(opt_lineNum);
|
||||
d.in_reply_to = inReplyTo;
|
||||
d.range = opt_range;
|
||||
if (opt_message != null) {
|
||||
@@ -266,8 +265,8 @@
|
||||
return d;
|
||||
},
|
||||
|
||||
_newDraft: function(opt_lineNum, opt_range) {
|
||||
var d = {
|
||||
_newDraft(opt_lineNum, opt_range) {
|
||||
const d = {
|
||||
__draft: true,
|
||||
__draftID: Math.random().toString(36),
|
||||
__date: new Date(),
|
||||
@@ -290,15 +289,15 @@
|
||||
return d;
|
||||
},
|
||||
|
||||
_getSide: function(isOnParent) {
|
||||
_getSide(isOnParent) {
|
||||
if (isOnParent) { return 'PARENT'; }
|
||||
return 'REVISION';
|
||||
},
|
||||
|
||||
_handleCommentDiscard: function(e) {
|
||||
var diffCommentEl = Polymer.dom(e).rootTarget;
|
||||
var comment = diffCommentEl.comment;
|
||||
var idx = this._indexOf(comment, this.comments);
|
||||
_handleCommentDiscard(e) {
|
||||
const diffCommentEl = Polymer.dom(e).rootTarget;
|
||||
const comment = diffCommentEl.comment;
|
||||
const idx = this._indexOf(comment, this.comments);
|
||||
if (idx == -1) {
|
||||
throw Error('Cannot find comment ' +
|
||||
JSON.stringify(diffCommentEl.comment));
|
||||
@@ -310,23 +309,23 @@
|
||||
|
||||
// Check to see if there are any other open comments getting edited and
|
||||
// set the local storage value to its message value.
|
||||
for (var i = 0; i < this.comments.length; i++) {
|
||||
if (this.comments[i].__editing) {
|
||||
var commentLocation = {
|
||||
for (const changeComment of this.comments) {
|
||||
if (changeComment.__editing) {
|
||||
const commentLocation = {
|
||||
changeNum: this.changeNum,
|
||||
patchNum: this.patchNum,
|
||||
path: this.comments[i].path,
|
||||
line: this.comments[i].line,
|
||||
path: changeComment.path,
|
||||
line: changeComment.line,
|
||||
};
|
||||
return this.$.storage.setDraftComment(commentLocation,
|
||||
this.comments[i].message);
|
||||
changeComment.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_handleCommentUpdate: function(e) {
|
||||
var comment = e.detail.comment;
|
||||
var index = this._indexOf(comment, this.comments);
|
||||
_handleCommentUpdate(e) {
|
||||
const comment = e.detail.comment;
|
||||
const index = this._indexOf(comment, this.comments);
|
||||
if (index === -1) {
|
||||
// This should never happen: comment belongs to another thread.
|
||||
console.warn('Comment update for another comment thread.');
|
||||
@@ -335,9 +334,9 @@
|
||||
this.set(['comments', index], comment);
|
||||
},
|
||||
|
||||
_indexOf: function(comment, arr) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var c = arr[i];
|
||||
_indexOf(comment, arr) {
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const c = arr[i];
|
||||
if ((c.__draftID != null && c.__draftID == comment.__draftID) ||
|
||||
(c.id != null && c.id == comment.id)) {
|
||||
return i;
|
||||
@@ -346,7 +345,7 @@
|
||||
return -1;
|
||||
},
|
||||
|
||||
_computeHostClass: function(unresolved) {
|
||||
_computeHostClass(unresolved) {
|
||||
return unresolved ? 'unresolved' : '';
|
||||
},
|
||||
});
|
||||
|
||||
@@ -40,25 +40,25 @@ limitations under the License.
|
||||
</test-fixture>
|
||||
|
||||
<script>
|
||||
suite('gr-diff-comment-thread tests', function() {
|
||||
var element;
|
||||
var sandbox;
|
||||
suite('gr-diff-comment-thread 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); },
|
||||
});
|
||||
sandbox = sinon.sandbox.create();
|
||||
element = fixture('basic');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
teardown(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('comments are sorted correctly', function() {
|
||||
var comments = [
|
||||
test('comments are sorted correctly', () => {
|
||||
const comments = [
|
||||
{
|
||||
id: 'jacks_reply',
|
||||
message: 'i like you, too',
|
||||
@@ -86,9 +86,9 @@ limitations under the License.
|
||||
id: 'sallys_mission',
|
||||
message: 'i have to find santa',
|
||||
updated: '2015-12-24 15:00:20.396000000',
|
||||
}
|
||||
},
|
||||
];
|
||||
var results = element._sortedComments(comments);
|
||||
const results = element._sortedComments(comments);
|
||||
assert.deepEqual(results, [
|
||||
{
|
||||
id: 'sally_to_dr_finklestein',
|
||||
@@ -117,11 +117,11 @@ limitations under the License.
|
||||
message: 'i like you, too',
|
||||
in_reply_to: 'sallys_confession',
|
||||
updated: '2015-12-25 15:00:20.396000000',
|
||||
}
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('addOrEditDraft w/ edit draft', function() {
|
||||
test('addOrEditDraft w/ edit draft', () => {
|
||||
element.comments = [{
|
||||
id: 'jacks_reply',
|
||||
message: 'i like you, too',
|
||||
@@ -129,9 +129,9 @@ limitations under the License.
|
||||
updated: '2015-12-25 15:00:20.396000000',
|
||||
__draft: true,
|
||||
}];
|
||||
var commentElStub = sandbox.stub(element, '_commentElWithDraftID',
|
||||
function() { return {}; });
|
||||
var addDraftStub = sandbox.stub(element, 'addDraft');
|
||||
const commentElStub = sandbox.stub(element, '_commentElWithDraftID',
|
||||
() => { return {}; });
|
||||
const addDraftStub = sandbox.stub(element, 'addDraft');
|
||||
|
||||
element.addOrEditDraft(123);
|
||||
|
||||
@@ -139,11 +139,11 @@ limitations under the License.
|
||||
assert.isFalse(addDraftStub.called);
|
||||
});
|
||||
|
||||
test('addOrEditDraft w/o edit draft', function() {
|
||||
test('addOrEditDraft w/o edit draft', () => {
|
||||
element.comments = [];
|
||||
var commentElStub = sandbox.stub(element, '_commentElWithDraftID',
|
||||
function() { return {}; });
|
||||
var addDraftStub = sandbox.stub(element, 'addDraft');
|
||||
const commentElStub = sandbox.stub(element, '_commentElWithDraftID',
|
||||
() => { return {}; });
|
||||
const addDraftStub = sandbox.stub(element, 'addDraft');
|
||||
|
||||
element.addOrEditDraft(123);
|
||||
|
||||
@@ -151,40 +151,41 @@ limitations under the License.
|
||||
assert.isTrue(addDraftStub.called);
|
||||
});
|
||||
|
||||
test('_hideActions', function() {
|
||||
var showActions = true;
|
||||
var lastComment = {};
|
||||
test('_hideActions', () => {
|
||||
let showActions = true;
|
||||
const lastComment = {};
|
||||
assert.equal(element._hideActions(showActions, lastComment), false);
|
||||
showActions = false;
|
||||
assert.equal(element._hideActions(showActions, lastComment), true);
|
||||
var showActions = true;
|
||||
showActions = true;
|
||||
lastComment.__draft = true;
|
||||
assert.equal(element._hideActions(showActions, lastComment), true);
|
||||
});
|
||||
});
|
||||
|
||||
suite('comment action tests', function() {
|
||||
var element;
|
||||
suite('comment action tests', () => {
|
||||
let element;
|
||||
|
||||
setup(function() {
|
||||
setup(() => {
|
||||
stub('gr-rest-api-interface', {
|
||||
getLoggedIn: function() { return Promise.resolve(false); },
|
||||
saveDiffDraft: function() {
|
||||
getLoggedIn() { return Promise.resolve(false); },
|
||||
saveDiffDraft() {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
text: function() { return Promise.resolve(')]}\'\n' +
|
||||
JSON.stringify({
|
||||
id: '7afa4931_de3d65bd',
|
||||
path: '/path/to/file.txt',
|
||||
line: 5,
|
||||
in_reply_to: 'baf0414d_60047215',
|
||||
updated: '2015-12-21 02:01:10.850000000',
|
||||
message: 'Done',
|
||||
}));
|
||||
text() {
|
||||
return Promise.resolve(')]}\'\n' +
|
||||
JSON.stringify({
|
||||
id: '7afa4931_de3d65bd',
|
||||
path: '/path/to/file.txt',
|
||||
line: 5,
|
||||
in_reply_to: 'baf0414d_60047215',
|
||||
updated: '2015-12-21 02:01:10.850000000',
|
||||
message: 'Done',
|
||||
}));
|
||||
},
|
||||
});
|
||||
},
|
||||
deleteDiffDraft: function() { return Promise.resolve({ok: true}); },
|
||||
deleteDiffDraft() { return Promise.resolve({ok: true}); },
|
||||
});
|
||||
element = fixture('withComment');
|
||||
element.comments = [{
|
||||
@@ -200,15 +201,15 @@ limitations under the License.
|
||||
flushAsynchronousOperations();
|
||||
});
|
||||
|
||||
test('reply', function(done) {
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
test('reply', done => {
|
||||
const commentEl = element.$$('gr-diff-comment');
|
||||
assert.ok(commentEl);
|
||||
|
||||
var replyBtn = element.$.replyBtn;
|
||||
const replyBtn = element.$.replyBtn;
|
||||
MockInteractions.tap(replyBtn);
|
||||
flushAsynchronousOperations();
|
||||
|
||||
var drafts = element._orderedComments.filter(function(c) {
|
||||
const drafts = element._orderedComments.filter(c => {
|
||||
return c.__draft == true;
|
||||
});
|
||||
assert.equal(drafts.length, 1);
|
||||
@@ -217,16 +218,16 @@ limitations under the License.
|
||||
done();
|
||||
});
|
||||
|
||||
test('quote reply', function(done) {
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
test('quote reply', done => {
|
||||
const commentEl = element.$$('gr-diff-comment');
|
||||
assert.ok(commentEl);
|
||||
|
||||
var quoteBtn = element.$.quoteBtn;
|
||||
const quoteBtn = element.$.quoteBtn;
|
||||
MockInteractions.tap(quoteBtn);
|
||||
flushAsynchronousOperations();
|
||||
|
||||
var drafts = element._orderedComments.filter(function(c) {
|
||||
return c.__draft == true;
|
||||
const drafts = element._orderedComments.filter(c => {
|
||||
return c.__draft == true;
|
||||
});
|
||||
assert.equal(drafts.length, 1);
|
||||
assert.equal(drafts[0].message, '> is this a crossover episode!?\n\n');
|
||||
@@ -234,7 +235,7 @@ limitations under the License.
|
||||
done();
|
||||
});
|
||||
|
||||
test('quote reply multiline', function(done) {
|
||||
test('quote reply multiline', done => {
|
||||
element.comments = [{
|
||||
author: {
|
||||
name: 'Mr. Peanutbutter',
|
||||
@@ -247,14 +248,14 @@ limitations under the License.
|
||||
}];
|
||||
flushAsynchronousOperations();
|
||||
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
const commentEl = element.$$('gr-diff-comment');
|
||||
assert.ok(commentEl);
|
||||
|
||||
var quoteBtn = element.$.quoteBtn;
|
||||
const quoteBtn = element.$.quoteBtn;
|
||||
MockInteractions.tap(quoteBtn);
|
||||
flushAsynchronousOperations();
|
||||
|
||||
var drafts = element._orderedComments.filter(function(c) {
|
||||
const drafts = element._orderedComments.filter(c => {
|
||||
return c.__draft == true;
|
||||
});
|
||||
assert.equal(drafts.length, 1);
|
||||
@@ -264,17 +265,17 @@ limitations under the License.
|
||||
done();
|
||||
});
|
||||
|
||||
test('ack', function(done) {
|
||||
test('ack', done => {
|
||||
element.changeNum = '42';
|
||||
element.patchNum = '1';
|
||||
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
const commentEl = element.$$('gr-diff-comment');
|
||||
assert.ok(commentEl);
|
||||
|
||||
var ackBtn = element.$.ackBtn;
|
||||
const ackBtn = element.$.ackBtn;
|
||||
MockInteractions.tap(ackBtn);
|
||||
flush(function() {
|
||||
var drafts = element.comments.filter(function(c) {
|
||||
flush(() => {
|
||||
const drafts = element.comments.filter(c => {
|
||||
return c.__draft == true;
|
||||
});
|
||||
assert.equal(drafts.length, 1);
|
||||
@@ -285,16 +286,16 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
|
||||
test('done', function(done) {
|
||||
test('done', done => {
|
||||
element.changeNum = '42';
|
||||
element.patchNum = '1';
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
const commentEl = element.$$('gr-diff-comment');
|
||||
assert.ok(commentEl);
|
||||
|
||||
var doneBtn = element.$.doneBtn;
|
||||
const doneBtn = element.$.doneBtn;
|
||||
MockInteractions.tap(doneBtn);
|
||||
flush(function() {
|
||||
var drafts = element.comments.filter(function(c) {
|
||||
flush(() => {
|
||||
const drafts = element.comments.filter(c => {
|
||||
return c.__draft == true;
|
||||
});
|
||||
assert.equal(drafts.length, 1);
|
||||
@@ -305,13 +306,13 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
|
||||
test('please fix', function(done) {
|
||||
test('please fix', done => {
|
||||
element.changeNum = '42';
|
||||
element.patchNum = '1';
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
const commentEl = element.$$('gr-diff-comment');
|
||||
assert.ok(commentEl);
|
||||
commentEl.addEventListener('create-fix-comment', function() {
|
||||
var drafts = element._orderedComments.filter(function(c) {
|
||||
commentEl.addEventListener('create-fix-comment', () => {
|
||||
const drafts = element._orderedComments.filter(c => {
|
||||
return c.__draft == true;
|
||||
});
|
||||
assert.equal(drafts.length, 1);
|
||||
@@ -325,21 +326,21 @@ limitations under the License.
|
||||
{bubbles: false});
|
||||
});
|
||||
|
||||
test('discard', function(done) {
|
||||
test('discard', done => {
|
||||
element.changeNum = '42';
|
||||
element.patchNum = '1';
|
||||
element.push('comments', element._newReply(
|
||||
element.comments[0].id,
|
||||
element.comments[0].line,
|
||||
element.comments[0].path,
|
||||
'it’s pronouced jiff, not giff'));
|
||||
element.comments[0].id,
|
||||
element.comments[0].line,
|
||||
element.comments[0].path,
|
||||
'it’s pronouced jiff, not giff'));
|
||||
flushAsynchronousOperations();
|
||||
|
||||
var draftEl =
|
||||
const draftEl =
|
||||
Polymer.dom(element.root).querySelectorAll('gr-diff-comment')[1];
|
||||
assert.ok(draftEl);
|
||||
draftEl.addEventListener('comment-discard', function() {
|
||||
var drafts = element.comments.filter(function(c) {
|
||||
draftEl.addEventListener('comment-discard', () => {
|
||||
const drafts = element.comments.filter(c => {
|
||||
return c.__draft == true;
|
||||
});
|
||||
assert.equal(drafts.length, 0);
|
||||
@@ -348,9 +349,7 @@ limitations under the License.
|
||||
draftEl.fire('comment-discard', null, {bubbles: false});
|
||||
});
|
||||
|
||||
test('first editing comment does not add __otherEditing attribute',
|
||||
function() {
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
test('first editing comment does not add __otherEditing attribute', () => {
|
||||
element.comments = [{
|
||||
author: {
|
||||
name: 'Mr. Peanutbutter',
|
||||
@@ -363,19 +362,19 @@ limitations under the License.
|
||||
__draft: true,
|
||||
}];
|
||||
|
||||
var replyBtn = element.$.replyBtn;
|
||||
const replyBtn = element.$.replyBtn;
|
||||
MockInteractions.tap(replyBtn);
|
||||
flushAsynchronousOperations();
|
||||
|
||||
var editing = element._orderedComments.filter(function(c) {
|
||||
const editing = element._orderedComments.filter(c => {
|
||||
return c.__editing == true;
|
||||
});
|
||||
assert.equal(editing.length, 1);
|
||||
assert.equal(!!editing[0].__otherEditing, false);
|
||||
});
|
||||
|
||||
test('When not editing other comments, local storage not set after discard',
|
||||
function(done) {
|
||||
test('When not editing other comments, local storage not set' +
|
||||
' after discard', done => {
|
||||
element.changeNum = '42';
|
||||
element.patchNum = '1';
|
||||
element.comments = [{
|
||||
@@ -413,13 +412,13 @@ limitations under the License.
|
||||
updated: '2015-12-08 19:48:33.843000000',
|
||||
__draft: true,
|
||||
}];
|
||||
var storageStub = sinon.stub(element.$.storage, 'setDraftComment');
|
||||
const storageStub = sinon.stub(element.$.storage, 'setDraftComment');
|
||||
flushAsynchronousOperations();
|
||||
|
||||
var draftEl =
|
||||
Polymer.dom(element.root).querySelectorAll('gr-diff-comment')[1];
|
||||
const draftEl =
|
||||
Polymer.dom(element.root).querySelectorAll('gr-diff-comment')[1];
|
||||
assert.ok(draftEl);
|
||||
draftEl.addEventListener('comment-discard', function() {
|
||||
draftEl.addEventListener('comment-discard', () => {
|
||||
assert.isFalse(storageStub.called);
|
||||
storageStub.restore();
|
||||
done();
|
||||
@@ -427,9 +426,9 @@ limitations under the License.
|
||||
draftEl.fire('comment-discard', null, {bubbles: false});
|
||||
});
|
||||
|
||||
test('comment-update', function() {
|
||||
var commentEl = element.$$('gr-diff-comment');
|
||||
var updatedComment = {
|
||||
test('comment-update', () => {
|
||||
const commentEl = element.$$('gr-diff-comment');
|
||||
const updatedComment = {
|
||||
id: element.comments[0].id,
|
||||
foo: 'bar',
|
||||
};
|
||||
@@ -437,88 +436,81 @@ limitations under the License.
|
||||
assert.strictEqual(element.comments[0], updatedComment);
|
||||
});
|
||||
|
||||
suite('jack and sally comment data test consolidation', function() {
|
||||
var getComments = function() {
|
||||
return Polymer.dom(element.root).querySelectorAll('gr-diff-comment');
|
||||
};
|
||||
|
||||
setup(function() {
|
||||
suite('jack and sally comment data test consolidation', () => {
|
||||
setup(() => {
|
||||
element.comments = [
|
||||
{
|
||||
id: 'jacks_reply',
|
||||
message: 'i like you, too',
|
||||
in_reply_to: 'sallys_confession',
|
||||
updated: '2015-12-25 15:00:20.396000000',
|
||||
unresolved: false,
|
||||
}, {
|
||||
id: 'sallys_confession',
|
||||
in_reply_to: 'nonexistent_comment',
|
||||
message: 'i like you, jack',
|
||||
updated: '2015-12-24 15:00:20.396000000',
|
||||
}, {
|
||||
id: 'sally_to_dr_finklestein',
|
||||
in_reply_to: 'nonexistent_comment',
|
||||
message: 'i’m running away',
|
||||
updated: '2015-10-31 09:00:20.396000000',
|
||||
}, {
|
||||
id: 'sallys_defiance',
|
||||
message: 'i will poison you so i can get away',
|
||||
updated: '2015-10-31 15:00:20.396000000',
|
||||
}];
|
||||
{
|
||||
id: 'jacks_reply',
|
||||
message: 'i like you, too',
|
||||
in_reply_to: 'sallys_confession',
|
||||
updated: '2015-12-25 15:00:20.396000000',
|
||||
unresolved: false,
|
||||
}, {
|
||||
id: 'sallys_confession',
|
||||
in_reply_to: 'nonexistent_comment',
|
||||
message: 'i like you, jack',
|
||||
updated: '2015-12-24 15:00:20.396000000',
|
||||
}, {
|
||||
id: 'sally_to_dr_finklestein',
|
||||
in_reply_to: 'nonexistent_comment',
|
||||
message: 'i’m running away',
|
||||
updated: '2015-10-31 09:00:20.396000000',
|
||||
}, {
|
||||
id: 'sallys_defiance',
|
||||
message: 'i will poison you so i can get away',
|
||||
updated: '2015-10-31 15:00:20.396000000',
|
||||
}];
|
||||
});
|
||||
|
||||
test('orphan replies', function() {
|
||||
test('orphan replies', () => {
|
||||
assert.equal(4, element._orderedComments.length);
|
||||
});
|
||||
|
||||
test('keyboard shortcuts', function() {
|
||||
var expandCollapseStub = sinon.stub(element, '_expandCollapseComments');
|
||||
test('keyboard shortcuts', () => {
|
||||
const expandCollapseStub =
|
||||
sinon.stub(element, '_expandCollapseComments');
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 69, null, 'e');
|
||||
assert.isTrue(expandCollapseStub.lastCall.calledWith(false));
|
||||
|
||||
MockInteractions.pressAndReleaseKeyOn(element, 69, 'shift', 'e');
|
||||
assert.isTrue(expandCollapseStub.lastCall.calledWith(true));
|
||||
expandCollapseStub.restore();
|
||||
});
|
||||
|
||||
test('comment in_reply_to is either null or most recent comment id',
|
||||
function() {
|
||||
test('comment in_reply_to is either null or most recent comment', () => {
|
||||
element._createReplyComment(element.comments[3], 'dummy', true);
|
||||
flushAsynchronousOperations();
|
||||
assert.equal(element._orderedComments.length, 5);
|
||||
assert.equal(element._orderedComments[4].in_reply_to, 'jacks_reply');
|
||||
});
|
||||
|
||||
test('resolvable comments', function() {
|
||||
test('resolvable comments', () => {
|
||||
assert.isFalse(element._unresolved);
|
||||
element._createReplyComment(element.comments[3], 'dummy', true, true);
|
||||
flushAsynchronousOperations();
|
||||
assert.isTrue(element._unresolved);
|
||||
});
|
||||
|
||||
test('_setInitialExpandedState', function() {
|
||||
test('_setInitialExpandedState', () => {
|
||||
element._unresolved = true;
|
||||
element._setInitialExpandedState();
|
||||
var comments = getComments();
|
||||
for (var i = 0; i < element.comments.length; i++) {
|
||||
for (let i = 0; i < element.comments.length; i++) {
|
||||
assert.isFalse(element.comments[i].collapsed);
|
||||
}
|
||||
element._unresolved = false;
|
||||
element._setInitialExpandedState();
|
||||
var comments = getComments();
|
||||
for (var i = 0; i < element.comments.length; i++) {
|
||||
for (let i = 0; i < element.comments.length; i++) {
|
||||
assert.isTrue(element.comments[i].collapsed);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('_computeHostClass', function() {
|
||||
test('_computeHostClass', () => {
|
||||
assert.equal(element._computeHostClass(true), 'unresolved');
|
||||
assert.equal(element._computeHostClass(false), '');
|
||||
});
|
||||
|
||||
test('addDraft sets unresolved state correctly', function() {
|
||||
var unresolved = true;
|
||||
test('addDraft sets unresolved state correctly', () => {
|
||||
let unresolved = true;
|
||||
element.comments = [];
|
||||
element.addDraft(null, null, unresolved);
|
||||
assert.equal(element.comments[0].unresolved, true);
|
||||
@@ -533,15 +525,15 @@ limitations under the License.
|
||||
assert.equal(element.comments[0].unresolved, true);
|
||||
});
|
||||
|
||||
test('_newDraft', function() {
|
||||
test('_newDraft', () => {
|
||||
element.commentSide = 'left';
|
||||
element.patchNum = 3;
|
||||
var draft = element._newDraft();
|
||||
const draft = element._newDraft();
|
||||
assert.equal(draft.__commentSide, 'left');
|
||||
assert.equal(draft.patchNum, 3);
|
||||
});
|
||||
|
||||
test('new comment gets created', function() {
|
||||
test('new comment gets created', () => {
|
||||
element.comments = [];
|
||||
element.addOrEditDraft(1);
|
||||
assert.equal(element.comments.length, 1);
|
||||
@@ -552,7 +544,7 @@ limitations under the License.
|
||||
assert.equal(element.comments.length, 2);
|
||||
});
|
||||
|
||||
test('unresolved label', function() {
|
||||
test('unresolved label', () => {
|
||||
element._unresolved = false;
|
||||
assert.isTrue(element.$.unresolvedLabel.hasAttribute('hidden'));
|
||||
element._unresolved = true;
|
||||
|
||||
Reference in New Issue
Block a user