Merge "Move tests for comment utils out of gr-diff-host"
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js
index dd2e307..ed9a8df 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.js
@@ -20,10 +20,9 @@
 import {GrDiffBuilderImage} from '../gr-diff-builder/gr-diff-builder-image.js';
 import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
 import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
-import {sortComments, createCommentThreads} from '../../../utils/comment-util.js';
+import {createCommentThreads} from '../../../utils/comment-util.js';
 import {Side, CommentSide} from '../../../constants/constants.js';
 import {createChange} from '../../../test/test-data-generators.js';
-import {FILE} from '../gr-diff/gr-diff-line.js';
 import {CoverageType} from '../../../types/types.js';
 import {addListenerForTest, stubRestApi} from '../../../test/test-utils.js';
 import {createDefaultDiffPrefs} from '../../../constants/constants.js';
@@ -956,156 +955,6 @@
     });
   });
 
-  test('comments sorting', () => {
-    const comments = [
-      {
-        id: 'new_draft',
-        message: 'i do not like either of you',
-        diffSide: Side.LEFT,
-        __draft: true,
-        updated: '2015-12-20 15:01:20.396000000',
-      },
-      {
-        id: 'sallys_confession',
-        message: 'i like you, jack',
-        updated: '2015-12-23 15:00:20.396000000',
-        line: 1,
-        diffSide: Side.LEFT,
-      }, {
-        id: 'jacks_reply',
-        message: 'i like you, too',
-        updated: '2015-12-24 15:01:20.396000000',
-        diffSide: Side.LEFT,
-        line: 1,
-        in_reply_to: 'sallys_confession',
-      },
-    ];
-    const sortedComments = sortComments(comments);
-    assert.equal(sortedComments[0], comments[1]);
-    assert.equal(sortedComments[1], comments[2]);
-    assert.equal(sortedComments[2], comments[0]);
-  });
-
-  test('_createThreads', () => {
-    const comments = [
-      {
-        id: 'sallys_confession',
-        message: 'i like you, jack',
-        updated: '2015-12-23 15:00:20.396000000',
-        line: 1,
-        patch_set: 1,
-        path: 'some/path',
-      }, {
-        id: 'jacks_reply',
-        message: 'i like you, too',
-        updated: '2015-12-24 15:01:20.396000000',
-        line: 1,
-        in_reply_to: 'sallys_confession',
-        patch_set: 1,
-        path: 'some/path',
-      },
-      {
-        id: 'new_draft',
-        message: 'i do not like either of you',
-        __draft: true,
-        updated: '2015-12-20 15:01:20.396000000',
-        patch_set: 1,
-        path: 'some/path',
-      },
-    ];
-
-    const actualThreads = createCommentThreads(comments,
-        {basePatchNum: 1, patchNum: 4});
-
-    assert.equal(actualThreads.length, 2);
-
-    assert.equal(actualThreads[0].diffSide, Side.LEFT);
-    assert.equal(actualThreads[0].comments.length, 2);
-    assert.deepEqual(actualThreads[0].comments[0], comments[0]);
-    assert.deepEqual(actualThreads[0].comments[1], comments[1]);
-    assert.equal(actualThreads[0].patchNum, 1);
-    assert.equal(actualThreads[0].line, 1);
-
-    assert.equal(actualThreads[1].diffSide, Side.LEFT);
-    assert.equal(actualThreads[1].comments.length, 1);
-    assert.deepEqual(actualThreads[1].comments[0], comments[2]);
-    assert.equal(actualThreads[1].patchNum, 1);
-    assert.equal(actualThreads[1].line, FILE);
-  });
-
-  test('_createThreads derives patchNum and range', () => {
-    const 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,
-      },
-      patch_set: 5,
-      path: '/p',
-      line: 1,
-    }];
-
-    const expectedThreads = [
-      {
-        diffSide: Side.LEFT,
-        commentSide: CommentSide.REVISION,
-        path: '/p',
-        rootId: 'betsys_confession',
-        mergeParentNum: undefined,
-        comments: [{
-          id: 'betsys_confession',
-          path: '/p',
-          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,
-          },
-          patch_set: 5,
-          line: 1,
-        }],
-        patchNum: 5,
-        range: {
-          start_line: 1,
-          start_character: 1,
-          end_line: 1,
-          end_character: 2,
-        },
-        line: 1,
-      },
-    ];
-
-    assert.deepEqual(
-        createCommentThreads(comments, {basePatchNum: 5, patchNum: 10}),
-        expectedThreads);
-  });
-
-  test('_createThreads does not thread unrelated comments at same location',
-      () => {
-        const comments = [
-          {
-            id: 'sallys_confession',
-            message: 'i like you, jack',
-            updated: '2015-12-23 15:00:20.396000000',
-            diffSide: Side.LEFT,
-            path: '/p',
-          }, {
-            id: 'jacks_reply',
-            message: 'i like you, too',
-            updated: '2015-12-24 15:01:20.396000000',
-            diffSide: Side.LEFT,
-            path: '/p',
-          },
-        ];
-        assert.equal(createCommentThreads(comments).length, 2);
-      });
-
   test('_getOrCreateThread', () => {
     const diffSide = Side.LEFT;
     const commentSide = CommentSide.PARENT;
diff --git a/polygerrit-ui/app/utils/comment-util_test.js b/polygerrit-ui/app/utils/comment-util_test.js
index 3b1c090..4ce95ef 100644
--- a/polygerrit-ui/app/utils/comment-util_test.js
+++ b/polygerrit-ui/app/utils/comment-util_test.js
@@ -17,10 +17,10 @@
 
 import '../test/common-test-setup-karma.js';
 import {
-  isUnresolved, getPatchRangeForCommentUrl,
+  isUnresolved, getPatchRangeForCommentUrl, createCommentThreads, sortComments,
 } from './comment-util.js';
 import {createComment} from '../test/test-data-generators.js';
-import {CommentSide} from '../constants/constants.js';
+import {CommentSide, Side} from '../constants/constants.js';
 import {ParentPatchSetNum} from '../types/common.js';
 
 suite('comment-util', () => {
@@ -52,4 +52,155 @@
           });
         });
   });
+
+  test('comments sorting', () => {
+    const comments = [
+      {
+        id: 'new_draft',
+        message: 'i do not like either of you',
+        diffSide: Side.LEFT,
+        __draft: true,
+        updated: '2015-12-20 15:01:20.396000000',
+      },
+      {
+        id: 'sallys_confession',
+        message: 'i like you, jack',
+        updated: '2015-12-23 15:00:20.396000000',
+        line: 1,
+        diffSide: Side.LEFT,
+      }, {
+        id: 'jacks_reply',
+        message: 'i like you, too',
+        updated: '2015-12-24 15:01:20.396000000',
+        diffSide: Side.LEFT,
+        line: 1,
+        in_reply_to: 'sallys_confession',
+      },
+    ];
+    const sortedComments = sortComments(comments);
+    assert.equal(sortedComments[0], comments[1]);
+    assert.equal(sortedComments[1], comments[2]);
+    assert.equal(sortedComments[2], comments[0]);
+  });
+
+  suite('createCommentThreads', () => {
+    test('creates threads from individual comments', () => {
+      const comments = [
+        {
+          id: 'sallys_confession',
+          message: 'i like you, jack',
+          updated: '2015-12-23 15:00:20.396000000',
+          line: 1,
+          patch_set: 1,
+          path: 'some/path',
+        }, {
+          id: 'jacks_reply',
+          message: 'i like you, too',
+          updated: '2015-12-24 15:01:20.396000000',
+          line: 1,
+          in_reply_to: 'sallys_confession',
+          patch_set: 1,
+          path: 'some/path',
+        },
+        {
+          id: 'new_draft',
+          message: 'i do not like either of you',
+          __draft: true,
+          updated: '2015-12-20 15:01:20.396000000',
+          patch_set: 1,
+          path: 'some/path',
+        },
+      ];
+
+      const actualThreads = createCommentThreads(comments,
+          {basePatchNum: 1, patchNum: 4});
+
+      assert.equal(actualThreads.length, 2);
+
+      assert.equal(actualThreads[0].diffSide, Side.LEFT);
+      assert.equal(actualThreads[0].comments.length, 2);
+      assert.deepEqual(actualThreads[0].comments[0], comments[0]);
+      assert.deepEqual(actualThreads[0].comments[1], comments[1]);
+      assert.equal(actualThreads[0].patchNum, 1);
+      assert.equal(actualThreads[0].line, 1);
+
+      assert.equal(actualThreads[1].diffSide, Side.LEFT);
+      assert.equal(actualThreads[1].comments.length, 1);
+      assert.deepEqual(actualThreads[1].comments[0], comments[2]);
+      assert.equal(actualThreads[1].patchNum, 1);
+      assert.equal(actualThreads[1].line, 'FILE');
+    });
+
+    test('derives patchNum and range', () => {
+      const 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,
+        },
+        patch_set: 5,
+        path: '/p',
+        line: 1,
+      }];
+
+      const expectedThreads = [
+        {
+          diffSide: Side.LEFT,
+          commentSide: CommentSide.REVISION,
+          path: '/p',
+          rootId: 'betsys_confession',
+          mergeParentNum: undefined,
+          comments: [{
+            id: 'betsys_confession',
+            path: '/p',
+            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,
+            },
+            patch_set: 5,
+            line: 1,
+          }],
+          patchNum: 5,
+          range: {
+            start_line: 1,
+            start_character: 1,
+            end_line: 1,
+            end_character: 2,
+          },
+          line: 1,
+        },
+      ];
+
+      assert.deepEqual(
+          createCommentThreads(comments, {basePatchNum: 5, patchNum: 10}),
+          expectedThreads);
+    });
+
+    test('does not thread unrelated comments at same location', () => {
+      const comments = [
+        {
+          id: 'sallys_confession',
+          message: 'i like you, jack',
+          updated: '2015-12-23 15:00:20.396000000',
+          diffSide: Side.LEFT,
+          path: '/p',
+        }, {
+          id: 'jacks_reply',
+          message: 'i like you, too',
+          updated: '2015-12-24 15:01:20.396000000',
+          diffSide: Side.LEFT,
+          path: '/p',
+        },
+      ];
+      assert.equal(createCommentThreads(comments).length, 2);
+    });
+  });
 });