Merge lp:~cjohnston/launchpad/publish-ic-link into lp:launchpad

Proposed by Chris Johnston
Status: Merged
Merged at revision: 17011
Proposed branch: lp:~cjohnston/launchpad/publish-ic-link
Merge into: lp:launchpad
Diff against target: 91 lines (+58/-1)
3 files modified
lib/lp/code/javascript/branchmergeproposal.inlinecomments.js (+16/-0)
lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html (+2/-1)
lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js (+40/-0)
To merge this branch: bzr merge lp:~cjohnston/launchpad/publish-ic-link
Reviewer Review Type Date Requested Status
Celso Providelo (community) Needs Fixing
Review via email: mp+220103@code.launchpad.net

Commit message

Add link below diff to return back to the top of diff (Add comment section) via scrollers.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Please address the issues pointed as inline comments and we can have another review-round.

Revision history for this message
Celso Providelo (cprov) :
review: Needs Fixing
Revision history for this message
Celso Providelo (cprov) wrote :

Looks good, thanks Chris.

I just think we should verify that tests (and feature) work without recreating the scroller on updates. There is no reason why it shouldn't since the 'end'ing code checks for draft(s) in runtime.

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/javascript/branchmergeproposal.inlinecomments.js'
2--- lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-05-15 04:18:54 +0000
3+++ lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-05-19 22:41:25 +0000
4@@ -499,6 +499,22 @@
5 self._showPreviewDiff(previewdiff_id);
6 });
7 });
8+
9+ var rc_scroller = Y.one('.review-comment-scroller');
10+ if (rc_scroller !== null) {
11+ rc_scroller.remove(true);
12+ }
13+ rc_scroller = Y.Node.create('<a href="" />')
14+ .addClass('review-comment-scroller')
15+ .set('text', 'Back to top of diff');
16+ this.get('srcNode').append(rc_scroller);
17+ rc.link_scroller(rc_scroller, '#add-comment-form', function() {
18+ if (Y.all('.draft').size() > 0) {
19+ Y.one('#add-comment-form input[type=submit]').focus();
20+ } else {
21+ Y.one('#add-comment-form textarea').focus();
22+ }
23+ });
24 },
25
26 /**
27
28=== modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html'
29--- lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html 2014-05-14 20:03:00 +0000
30+++ lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.html 2014-05-19 22:41:25 +0000
31@@ -72,7 +72,8 @@
32 <li>lp.code.branchmergeproposal.inlinecomments.test</li>
33 </ul>
34
35- <div>
36+ <div id="add-comment-form">
37+ <textarea id="field.comment"></textarea>
38 <input id="field.review_type" type="text"></input>
39 <input id="field.actions.add" type="submit" value="Save"></input>
40 </div>
41
42=== modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js'
43--- lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-05-15 03:47:40 +0000
44+++ lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-05-19 22:41:25 +0000
45@@ -524,6 +524,46 @@
46 Y.Assert.areEqual(202, called_pd_id);
47 },
48
49+ test_diff_nav_publish_scroller: function() {
50+ // The Diff Navigator publish comment *scroller* allows
51+ // user to got from the bottom of the diff to the review
52+ // comment form and is updated according to the existence
53+ // of draft inline comments.
54+ this.diffnav.render();
55+ this.reply_previewdiffs();
56+ this.reply_diffcontent();
57+ var mockio = this.diffnav.get('lp_client').io_provider;
58+ Y.Assert.areEqual(2, mockio.requests.length);
59+ // We need to re-instrument the scroller in other to
60+ // instantly fire the 'end' event (which runs the code
61+ // that matters to us).
62+ scroller = Y.one('.review-comment-scroller');
63+ scroller.on('click', function() {
64+ var rc = Y.lp.code.branchmergeproposal.reviewcomment;
65+ rc.window_scroll_anim.fire('end');
66+ });
67+ scroller.simulate('click');
68+ // When there are no drafts, it scrolls to the form and focus
69+ // on the comment textarea.
70+ Y.Assert.areEqual(
71+ 'Back to top of diff', scroller.get('text'));
72+ Y.Assert.areEqual('field.comment', document.activeElement.id);
73+ // Create a draft inline comment and trigger an UI update.
74+ module.create_row({'line_number': '2', 'text': 'another'});
75+ Y.fire('inlinecomment.UPDATED');
76+ // See above ...
77+ scroller = Y.one('.review-comment-scroller');
78+ scroller.on('click', function() {
79+ var rc = Y.lp.code.branchmergeproposal.reviewcomment;
80+ rc.window_scroll_anim.fire('end');
81+ });
82+ scroller.simulate('click');
83+ // When there are draft, it scrolls to form and focus on the
84+ // submit button.
85+ Y.Assert.areEqual(
86+ 'field.actions.add', document.activeElement.id);
87+ },
88+
89 test_diff_nav_failed_diff_content: function() {
90 // An error message is presented when the Diff Navigator
91 // fails to fetch the selected diff contents.