Merge lp:~jcsackett/launchpad/hidden-comment-count-error into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 15599
Proposed branch: lp:~jcsackett/launchpad/hidden-comment-count-error
Merge into: lp:launchpad
Diff against target: 96 lines (+67/-1)
2 files modified
lib/lp/bugs/browser/bugtask.py (+6/-1)
lib/lp/bugs/browser/tests/test_bugtask.py (+61/-0)
To merge this branch: bzr merge lp:~jcsackett/launchpad/hidden-comment-count-error
Reviewer Review Type Date Requested Status
Richard Harding (community) Approve
Review via email: mp+114219@code.launchpad.net

Commit message

Fixes calculation of the number of hidden comments in the collapsed comment widget.

Description of the change

Summary
=======
There are two problems with the current hidden comment/activity collapse
display; it can claim there are more hidden comments are hidden then there
are, and it can claim negative comments. Both of these have to do with the
arrangement of comment indices.

This fixes up some math in the figuring of hidden comments and adds tests to
the display of the collapsed comments.

Preimp
======
Spoke with Curtis Hovey.

Implementation
==============
The original calculation was broken by design. When a break in visible
comments was detected, it determined the number missing was the difference
between the previous visible comment's index and the current one. But:

1) indices can occasionally be in reverse order, owing to mail messages.
2) The number of items between two items isn't the difference of their
indices. It's one less than that difference. (There is one number between 1
and 3, not 2).

To correct these, we can just get one less than the absolute difference
between the two visible comments.

Tests
=====
bin/test -vvct TestCommentCollapseVisibility

QA
==
Go play with hiding some comments and make sure the numbers are correct on
page load without all comments showing.

LoC
===
This is part of the already resourced disclore arc. Plus, after this we can
remove some feature flags which reduces LoC.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/bugs/browser/tests/test_bugtask.py
  lib/lp/bugs/browser/bugtask.py

To post a comment you must log in.
Revision history for this message
Richard Harding (rharding) wrote :

Works for me so long as the log files goes away. Thanks for the fix.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugtask.py'
2--- lib/lp/bugs/browser/bugtask.py 2012-07-04 11:07:57 +0000
3+++ lib/lp/bugs/browser/bugtask.py 2012-07-10 16:06:21 +0000
4@@ -945,9 +945,14 @@
5 continue
6 if prev_comment.index + 1 != comment.index:
7 # There is a gap here, record it.
8+
9+ # The number of items between two items is one less than
10+ # their difference. There is one number between 1 and 3,
11+ # not 2 (their difference).
12+ num_hidden = abs(comment.index - prev_comment.index) - 1
13 separator = {
14 'date': prev_comment.datecreated,
15- 'num_hidden': comment.index - prev_comment.index,
16+ 'num_hidden': num_hidden,
17 }
18 events.insert(index, separator)
19 index += 1
20
21=== modified file 'lib/lp/bugs/browser/tests/test_bugtask.py'
22--- lib/lp/bugs/browser/tests/test_bugtask.py 2012-07-04 11:07:57 +0000
23+++ lib/lp/bugs/browser/tests/test_bugtask.py 2012-07-10 16:06:21 +0000
24@@ -1757,6 +1757,66 @@
25 BugActivityItem(bug.activity[-1]).change_details)
26
27
28+class TestCommentCollapseVisibility(TestCaseWithFactory):
29+ """Test for the conditions around display of collapsed/hidden comments."""
30+
31+ layer = LaunchpadFunctionalLayer
32+
33+ def makeBugWithComments(self, num_comments):
34+ """Create and return a bug with a lot of comments and activity."""
35+ bug = self.factory.makeBug()
36+ with person_logged_in(bug.owner):
37+ for i in range(num_comments):
38+ msg = self.factory.makeMessage(
39+ owner=bug.owner, content="Message %i." % i)
40+ bug.linkMessage(msg, user=bug.owner)
41+ return bug
42+
43+ def test_comments_hidden_message_truncation_only(self):
44+ bug = self.makeBugWithComments(20)
45+ url = canonical_url(bug.default_bugtask)
46+ browser = self.getUserBrowser(url=url)
47+ contents = browser.contents
48+ self.assertTrue("10 comments hidden" in contents)
49+ self.assertEqual(1, contents.count('comments hidden'))
50+
51+ def test_comments_hidden_message_truncation_and_hidden(self):
52+ bug = self.makeBugWithComments(20)
53+ url = canonical_url(bug.default_bugtask)
54+
55+ #Hide a comment
56+ comments = list(bug.messages)
57+ removeSecurityProxy(comments[-5]).visible = False
58+
59+ browser = self.getUserBrowser(url=url)
60+ contents = browser.contents
61+ self.assertTrue("10 comments hidden" in browser.contents)
62+ self.assertTrue("1 comments hidden" in browser.contents)
63+ self.assertEqual(2, contents.count('comments hidden'))
64+
65+ def test_comments_hidden_message_truncation_and_hidden_out_of_order(self):
66+ bug = self.makeBugWithComments(20)
67+ url = canonical_url(bug.default_bugtask)
68+
69+ #Hide a comment
70+ comments = list(bug.messages)
71+ hidden_comment = comments[-5]
72+ removeSecurityProxy(hidden_comment).visible = False
73+
74+ #Mess with ordering. This requires a transaction since the view will
75+ #re-fetch the comments.
76+ last_comment = comments[-1]
77+ removeSecurityProxy(hidden_comment).datecreated += timedelta(1)
78+ removeSecurityProxy(last_comment).datecreated += timedelta(2)
79+ transaction.commit()
80+
81+ browser = self.getUserBrowser(url=url)
82+ contents = browser.contents
83+ self.assertTrue("10 comments hidden" in browser.contents)
84+ self.assertTrue("1 comments hidden" in browser.contents)
85+ self.assertEqual(2, contents.count('comments hidden'))
86+
87+
88 class TestBugTaskBatchedCommentsAndActivityView(TestCaseWithFactory):
89 """Tests for the BugTaskBatchedCommentsAndActivityView class."""
90
91@@ -1875,6 +1935,7 @@
92 unbatched_view.activity_and_comments[4:],
93 batched_view.activity_and_comments)
94
95+
96 no_target_specified = object()
97
98