Fix draft comment in wrong spot

There was an issue with the sort function that returned 0 sometimes when
it should not have. This change adds an additional condition so that the
correct comparison is made.

Bug: Issue 7813
Change-Id: I5b405ae431edc0b37cef09c53a2e8bb786fdeeed
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js
index 11d0403..e6779a5 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread.js
@@ -173,7 +173,7 @@
         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 (dateCompare === 0 && (!c1.id || !c1.id.localeCompare)) { return 0; }
         // If same date, fall back to sorting by id.
         return dateCompare ? dateCompare : c1.id.localeCompare(c2.id);
       });
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread_test.html b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread_test.html
index c96c031..5a5fc06 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment-thread/gr-diff-comment-thread_test.html
@@ -60,10 +60,9 @@
     test('comments are sorted correctly', () => {
       const comments = [
         {
-          id: 'jacks_reply',
           message: 'i like you, too',
           in_reply_to: 'sallys_confession',
-          updated: '2015-12-25 15:00:20.396000000',
+          __date: new Date('2015-12-25'),
         }, {
           id: 'sallys_confession',
           message: 'i like you, jack',
@@ -113,10 +112,9 @@
           message: 'i have to find santa',
           updated: '2015-12-24 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',
+          __date: new Date('2015-12-25'),
         },
       ]);
     });