Merge lp:~wallyworld/launchpad/picker-unassign-link-803996 into lp:launchpad

Proposed by Ian Booth
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 13407
Proposed branch: lp:~wallyworld/launchpad/picker-unassign-link-803996
Merge into: lp:launchpad
Diff against target: 198 lines (+15/-149)
2 files modified
lib/lp/app/javascript/picker/picker.js (+1/-1)
lib/lp/app/javascript/picker/tests/test_personpicker.js (+14/-148)
To merge this branch: bzr merge lp:~wallyworld/launchpad/picker-unassign-link-803996
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+67710@code.launchpad.net

Commit message

[r=sinzui][bug=803996] Ensure picker assign/remove links are shown correctly after a search when the picker is reopened.

Description of the change

After using the person picker to perform a search and assign someone to a bug, the "Remove assignee" and "Assign Me" links would disappear. These links are supposed to disappear when a search is done and the results displayed. But they should reappear when the picker is closed after a result is selected.

== Implementation ==

Turned out to be a trivial fix. The picker _clear() function was doing this:
this.set(RESULTS, [{}]);

The results were "cleared" but the array still had a length of 1 . Hence the logic to show/hide the links thought the picker still was displaying results. The logic was changed to
this.set(RESULTS, []);

Also, there were a bunch of duplicate tests in test_personpicker, left over from a previous rollback. These were deleted since they live in test_pickerpatcher.js

== Tests ==

All picker related yui tests pass. A new test was added also for the specific bug: test_buttons_reappear
The picker was tested also by running lp locally.

== Lint ==

jslint: 2 files to lint.
jslint: No problem found in '/home/ian/projects/lp-branches/devel-sandbox/lib/lp/app/javascript/picker/picker.js'.

jslint: No problem found in '/home/ian/projects/lp-branches/devel-sandbox/lib/lp/app/javascript/picker/tests/test_personpicker.js'.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank your for this fix.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/javascript/picker/picker.js'
2--- lib/lp/app/javascript/picker/picker.js 2011-07-06 14:18:59 +0000
3+++ lib/lp/app/javascript/picker/picker.js 2011-07-12 14:37:48 +0000
4@@ -684,7 +684,7 @@
5 _clear: function() {
6 this.set(CURRENT_SEARCH_STRING, '');
7 this.set(ERROR, '');
8- this.set(RESULTS, [{}]);
9+ this.set(RESULTS, []);
10 this.set(BATCHES, null);
11 this.set(BATCH_COUNT, null);
12 this._search_input.set('value', '');
13
14=== modified file 'lib/lp/app/javascript/picker/tests/test_personpicker.js'
15--- lib/lp/app/javascript/picker/tests/test_personpicker.js 2011-07-08 06:29:36 +0000
16+++ lib/lp/app/javascript/picker/tests/test_personpicker.js 2011-07-12 14:37:48 +0000
17@@ -2,11 +2,7 @@
18 * GNU Affero General Public License version 3 (see the file LICENSE).
19 */
20
21-YUI({
22- base: '../../../../../canonical/launchpad/icing/yui/',
23- filter: 'raw', combine: false,
24- fetchCSS: false
25- }).use('test', 'console', 'plugin',
26+YUI().use('test', 'console', 'plugin',
27 'lazr.picker', 'lazr.person-picker', 'lp.app.picker',
28 'node-event-simulate', function(Y) {
29
30@@ -123,149 +119,6 @@
31 config);
32 },
33
34- _check_button_state: function(btn_class, is_visible) {
35- var assign_me_button = Y.one(btn_class);
36- Assert.isNotNull(assign_me_button);
37- if (is_visible) {
38- Assert.isFalse(
39- assign_me_button.hasClass('yui3-picker-hidden'),
40- btn_class + " should be visible but is hidden");
41- } else {
42- Assert.isTrue(
43- assign_me_button.hasClass('yui3-picker-hidden'),
44- btn_class + " should be hidden but is visible");
45- }
46- },
47-
48- _check_assign_me_button_state: function(is_visible) {
49- this._check_button_state('.yui-picker-assign-me-button', is_visible);
50- },
51-
52- _check_remove_button_state: function(is_visible) {
53- this._check_button_state('.yui-picker-remove-button', is_visible);
54- },
55-
56- test_render_with_links: function () {
57- // The extra buttons section exists when there are assign/remove links
58- this.create_picker(true, true);
59- this.picker.render();
60- this.picker.show();
61-
62- Y.Assert.isNotNull(Y.one('.extra-form-buttons'));
63- Y.Assert.isNotUndefined(this.picker.assign_me_button);
64- Y.Assert.isNotUndefined(this.picker.remove_button);
65- },
66-
67- test_render_without_links: function () {
68- // The extra buttons section doesn't exists when there no
69- // assign/remove links.
70- this.create_picker(false, false);
71- this.picker.render();
72- this.picker.show();
73-
74- Y.Assert.isNotNull(Y.one('.extra-form-buttons'));
75- Y.Assert.isUndefined(this.picker.remove_button);
76- Y.Assert.isUndefined(this.picker.assign_me_button);
77- },
78-
79- test_picker_assign_me_button_text: function() {
80- // The assign me button text is correct.
81- this.create_picker(true, true);
82- this.picker.render();
83- var assign_me_button = Y.one('.yui-picker-assign-me-button');
84- Assert.areEqual('Assign Moi', assign_me_button.get('innerHTML'));
85- },
86-
87- test_picker_remove_button_text: function() {
88- // The remove button text is correct.
89- this.create_picker(true, true);
90- this.picker.render();
91- var remove_button = Y.one('.yui-picker-remove-button');
92- Assert.areEqual('Remove someone', remove_button.get('innerHTML'));
93- },
94-
95- test_picker_has_assign_me_button: function() {
96- // The assign me button is shown.
97- this.create_picker(true, true);
98- this.picker.render();
99- this._check_assign_me_button_state(true);
100- },
101-
102- test_picker_no_assign_me_button_unless_configured: function() {
103- // The assign me button is only rendered if show_assign_me_button
104- // config setting is true.
105- this.create_picker(false, true);
106- this.picker.render();
107- Assert.isNull(Y.one('.yui-picker-assign-me-button'));
108- },
109-
110- test_picker_no_assign_me_button_if_value_is_me: function() {
111- // The assign me button is not shown if the picker is created for a
112- // field where the value is "me".
113- this.create_picker(true, true, this.ME);
114- this.picker.render();
115- this._check_assign_me_button_state(false);
116- },
117-
118- test_picker_assign_me_button_hide_on_save: function() {
119- // The assign me button is shown initially but hidden if the picker
120- // saves a value equal to 'me'.
121- this.create_picker(true, true);
122- this._check_assign_me_button_state(true);
123- this.picker.set('results', this.vocabulary);
124- this.picker.render();
125- simulate(
126- this.picker.get('boundingBox').one('.yui3-picker-results'),
127- 'li:nth-child(1)', 'click');
128- this._check_assign_me_button_state(false);
129- },
130-
131- test_picker_no_remove_button_if_null_value: function() {
132- // The remove button is not shown if the picker is created for a field
133- // which has a null value.
134- this.create_picker(true, true);
135- this.picker.render();
136- this._check_remove_button_state(false);
137- },
138-
139- test_picker_has_remove_button_if_value: function() {
140- // The remove button is shown if the picker is created for a field
141- // which has a value.
142- this.create_picker(true, true, this.ME);
143- this.picker.render();
144- this._check_remove_button_state(true);
145- },
146-
147- test_picker_no_remove_button_unless_configured: function() {
148- // The remove button is only rendered if show_remove_button setting is
149- // true.
150- this.create_picker(true, false, this.ME);
151- this.picker.render();
152- Assert.isNull(Y.one('.yui-picker-remove-button'));
153- },
154-
155- test_picker_remove_button_clicked: function() {
156- // The remove button is hidden once a picker value has been removed.
157- // And the assign me button is shown.
158- this.create_picker(true, true, this.ME);
159- this.picker.render();
160- var remove = Y.one('.yui-picker-remove-button');
161- remove.simulate('click');
162- this._check_remove_button_state(false);
163- this._check_assign_me_button_state(true);
164- },
165-
166- test_picker_assign_me_button_clicked: function() {
167- // The assign me button is hidden once it is clicked.
168- // And the remove button is shown.
169- this.create_picker(true, true);
170- this.picker.render();
171- var remove = Y.one('.yui-picker-assign-me-button');
172- remove.simulate('click');
173- this._check_remove_button_state(true);
174- this._check_assign_me_button_state(false);
175- },
176-
177 test_search_field_focus: function () {
178 // The search field has focus when the picker is shown.
179 this.create_picker();
180@@ -320,6 +173,19 @@
181
182 this._change_results(this.picker, true);
183 Y.Assert.isFalse(this.picker._extra_buttons.hasClass('unseen'));
184+ },
185+
186+ test_buttons_reappear: function () {
187+ // The assign/remove links are shown again after doing a search and
188+ // selecting a result. Doing a search hides the links so we need to
189+ // ensure they are made visible again.
190+ this.create_picker(true, true);
191+ this.picker.render();
192+ this._change_results(this.picker, false);
193+ Y.Assert.isTrue(this.picker._extra_buttons.hasClass('unseen'));
194+ simulate(
195+ this.picker.get('boundingBox'), '.yui3-picker-results li', 'click');
196+ Y.Assert.isFalse(this.picker._extra_buttons.hasClass('unseen'));
197 }
198 }));
199