diff options
Diffstat (limited to 'polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html')
-rw-r--r-- | polygerrit-ui/app/elements/diff/gr-diff-comment-thread-group/gr-diff-comment-thread-group_test.html | 186 |
1 files changed, 79 insertions, 107 deletions
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 c2738460ab..1fb8136268 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 @@ -1,5 +1,6 @@ <!DOCTYPE html> <!-- +@license Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); @@ -50,99 +51,75 @@ limitations under the License. sandbox.restore(); }); - test('_getThreadGroups', () => { - element.patchForNewThreads = 3; - const 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', - }, - ]; - - 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', - }], - locationRange: 'line-left', - patchNum: 3, - }, - ]; - - assert.deepEqual(element._getThreadGroups(comments), - expectedThreadGroups); - - // 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', - }); - - expectedThreadGroups = [ + test('getThread', () => { + const range = { + start_line: 1, + start_character: 1, + end_line: 1, + end_character: 2, + }; + element.threads = [ { - start_datetime: '2015-12-23 15:00:20.396000000', + rootId: 'sallys_confession', 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', - }], - patchNum: 3, - locationRange: 'line-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:01:20.396000000', + __commentSide: 'left', + in_reply_to: 'sallys_confession', + }, { + id: 'new_draft', + message: 'i do not like either of you', + __commentSide: 'left', + __draft: true, + in_reply_to: 'sallys_confession', + updated: '2015-12-20 15:01:20.396000000', + }, + ], }, { - start_datetime: '2015-12-24 15:00:10.396000000', + rootId: 'right_side_comment', + commentSide: 'right', + comments: [ + { + id: 'right_side_comment', + message: 'right side comment', + __commentSide: 'right', + __draft: true, + updated: '2015-12-20 15:01:20.396000000', + }, + ], + }, { + rootId: 'betsys_confession', commentSide: 'left', - comments: [{ - 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, + range, + comments: [ + { + id: 'betsys_confession', + message: 'i like you more, jack', + updated: '2015-12-24 15:00:10.396000000', + range, + __commentSide: 'left', }, - __commentSide: 'left', - }], - patchNum: 3, - locationRange: 'range-1-1-1-2-left', + ], }, ]; - assert.deepEqual(element._getThreadGroups(comments), - expectedThreadGroups); + flushAsynchronousOperations(); + assert.deepEqual(element.getThread('right').rootId, 'right_side_comment'); + assert.deepEqual(element.getThread('right').comments.length, 1); + assert.deepEqual(element.getThread('left').rootId, 'sallys_confession'); + assert.deepEqual(element.getThread('left').comments.length, 3); + assert.deepEqual(element.getThread('left', range).rootId, + 'betsys_confession'); + assert.deepEqual(element.getThread('left', range).comments.length, 1); }); test('_sortByDate', () => { @@ -215,17 +192,6 @@ limitations under the License. 'range-1-2-3-4-left'); }); - test('thread groups are updated when comments change', () => { - const commentsChangedStub = sandbox.stub(element, '_commentsChanged'); - element.comments = []; - element.comments.push({ - id: 'sallys_confession', - message: 'i like you, jack', - updated: '2015-12-23 15:00:20.396000000', - }); - assert(commentsChangedStub.called); - }); - test('addNewThread', () => { const locationRange = 'range-1-2-3-4'; element._threads = [{locationRange: 'line'}]; @@ -233,18 +199,6 @@ limitations under the License. assert(element._threads.length, 2); }); - test('_getPatchNum', () => { - element.patchForNewThreads = 3; - const comment = { - id: 'sallys_confession', - message: 'i like you, jack', - updated: '2015-12-23 15:00:20.396000000', - }; - assert.equal(element._getPatchNum(comment), 3); - comment.patchNum = 4; - assert.equal(element._getPatchNum(comment), 4); - }); - test('removeThread', () => { const locationRange = 'range-1-2-3-4'; element._threads = [ @@ -256,5 +210,23 @@ limitations under the License. flushAsynchronousOperations(); assert(element._threads.length, 1); }); + + test('_rangesEqual', () => { + const range1 = + {startLine: 123, startChar: 345, endLine: 234, endChar: 456}; + const range2 = + {startLine: 1, startChar: 2, endLine: 3, endChar: 4}; + + assert.isTrue(element._rangesEqual(null, null)); + assert.isTrue(element._rangesEqual(null, undefined)); + assert.isTrue(element._rangesEqual(undefined, null)); + assert.isTrue(element._rangesEqual(undefined, undefined)); + + assert.isFalse(element._rangesEqual(range1, null)); + assert.isFalse(element._rangesEqual(null, range1)); + assert.isFalse(element._rangesEqual(range1, range2)); + + assert.isTrue(element._rangesEqual(range1, Object.assign({}, range1))); + }); }); </script> |