Merge lp:~rharding/launchpad/bug_yui35_one into lp:launchpad

Proposed by Richard Harding on 2012-06-27
Status: Merged
Approved by: Richard Harding on 2012-06-27
Approved revision: no longer in the source branch.
Merged at revision: 15508
Proposed branch: lp:~rharding/launchpad/bug_yui35_one
Merge into: lp:launchpad
Diff against target: 344 lines (+63/-48)
10 files modified
lib/lp/app/javascript/choice.js (+4/-5)
lib/lp/app/javascript/testing/helpers.js (+24/-0)
lib/lp/app/javascript/tests/test_listing_navigator.html (+2/-0)
lib/lp/bugs/javascript/filebug.js (+4/-4)
lib/lp/bugs/javascript/tests/test_buglisting_utils.html (+2/-0)
lib/lp/bugs/javascript/tests/test_buglisting_utils.js (+7/-21)
lib/lp/bugs/javascript/tests/test_filebug.js (+16/-16)
lib/lp/bugs/javascript/tests/test_information_type_choice.js (+1/-1)
standard_test_template.html (+2/-0)
standard_test_template.js (+1/-1)
To merge this branch: bzr merge lp:~rharding/launchpad/bug_yui35_one
Reviewer Review Type Date Requested Status
Aaron Bentley (community) 2012-06-27 Approve on 2012-06-27
Review via email: mp+112399@code.launchpad.net

Commit Message

Start to work on YUI3.5 testing with the bug JS.

Description of the Change

= Summary =

Start to update issues found in testing Bug module code in YUI 3.5.

== Implementation Notes ==

We hit another case of needing to reset history so this creates a new testing module 'helpers' and the method is moved there. The helpers is added to the standard default files for JS testing.

One test was found to not be needed any longer.

Fixes a bunch of the missing quotes around selectors that require them.

Also does some misc linting for trailing spaces.

== Tests ==

./bin/test -x -cvv --layer=YUITestLayer

== Lint ==

Linting changed files:
  standard_test_template.html
  standard_test_template.js
  lib/lp/app/javascript/choice.js
  lib/lp/app/javascript/testing/helpers.js
  lib/lp/app/javascript/tests/test_listing_navigator.html
  lib/lp/bugs/javascript/filebug.js
  lib/lp/bugs/javascript/tests/test_buglisting_utils.html
  lib/lp/bugs/javascript/tests/test_buglisting_utils.js
  lib/lp/bugs/javascript/tests/test_filebug.js
  lib/lp/bugs/javascript/tests/test_information_type_choice.js

== LoC Qualification ==

There are two qualifications:

1. Fixing these tests reduces tech debt and eases maintenance.
2. Getting to YUI 3.5 will allow us to use the build in calendar widget and
will remove all of the YUI2 code from the code base which is aroud 12K LoC
(non-minified) and over 27K lines of total files.

To post a comment you must log in.
Aaron Bentley (abentley) wrote :

Looks good.

The LoC rationales you've listed require waivers. However, landing lp:~rharding/launchpad/lpnames_yui35 will give you sufficient credit, so I'll take that as the rationale.

The copyright date on test_buglisting_utils.js should be 2011-2012.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/javascript/choice.js'
2--- lib/lp/app/javascript/choice.js 2012-06-16 21:26:54 +0000
3+++ lib/lp/app/javascript/choice.js 2012-06-27 18:52:21 +0000
4@@ -126,7 +126,7 @@
5 * @param show_description
6 */
7 namespace.addPopupChoice = function(field_name, choices, show_description) {
8- var legacy_node = Y.one('[id=field.' + field_name + ']');
9+ var legacy_node = Y.one('[id="field.' + field_name + '"]');
10 if (!Y.Lang.isValue(legacy_node)) {
11 return;
12 }
13@@ -148,15 +148,14 @@
14 */
15 namespace.addPopupChoiceForRadioButtons = function(field_name, choices,
16 show_description) {
17-
18- var legacy_node = Y.one('[name=field.' + field_name + ']')
19+ var legacy_node = Y.one('[name="field.' + field_name + '"]')
20 .ancestor('table.radio-button-widget');
21 if (!Y.Lang.isValue(legacy_node)) {
22 return;
23 }
24 var get_fn = function(node) {
25 var field_value = choices[0].value;
26- node.all('input[name=field.' + field_name + ']').each(function(node) {
27+ node.all('input[name="field.' + field_name + '"]').each(function(node) {
28 if (node.get('checked')) {
29 field_value = node.get('value');
30 }
31@@ -164,7 +163,7 @@
32 return field_value;
33 };
34 var set_fn = function(node, value) {
35- node.all('input[name=field.' + field_name + ']')
36+ node.all('input[name="field.' + field_name + '"]')
37 .each(function(node) {
38 var node_selected = node.get('value') === value;
39 node.set('checked', node_selected);
40
41=== added file 'lib/lp/app/javascript/testing/helpers.js'
42--- lib/lp/app/javascript/testing/helpers.js 1970-01-01 00:00:00 +0000
43+++ lib/lp/app/javascript/testing/helpers.js 2012-06-27 18:52:21 +0000
44@@ -0,0 +1,24 @@
45+/* Copyright (c) 2011, Canonical Ltd. All rights reserved. */
46+
47+YUI.add('lp.testing.helpers', function(Y) {
48+
49+ var ns = Y.namespace('lp.testing.helpers');
50+
51+
52+ /**
53+ * Reset the window history state.
54+ *
55+ * Useful for tearDown for code that modifies and stores data into the
56+ * History.state.
57+ * @function
58+ */
59+ ns.reset_history = function () {
60+ var win = Y.config.win;
61+ var originalURL = (win && win.location.toString()) || '';
62+ win.history.replaceState(null, null, originalURL);
63+ };
64+
65+
66+}, '0.1', {
67+ 'requires': [ 'history']
68+});
69
70=== modified file 'lib/lp/app/javascript/tests/test_listing_navigator.html'
71--- lib/lp/app/javascript/tests/test_listing_navigator.html 2012-06-26 18:19:55 +0000
72+++ lib/lp/app/javascript/tests/test_listing_navigator.html 2012-06-27 18:52:21 +0000
73@@ -21,6 +21,8 @@
74
75 <script type="text/javascript"
76 src="../../../../../build/js/lp/app/testing/testrunner.js"></script>
77+ <script type="text/javascript"
78+ src="../../../../../build/js/lp/app/testing/helpers.js"></script>
79
80 <link rel="stylesheet" href="../../../app/javascript/testing/test.css" />
81
82
83=== modified file 'lib/lp/bugs/javascript/filebug.js'
84--- lib/lp/bugs/javascript/filebug.js 2012-06-20 05:25:44 +0000
85+++ lib/lp/bugs/javascript/filebug.js 2012-06-27 18:52:21 +0000
86@@ -55,13 +55,13 @@
87 };
88
89 if (LP.cache.show_userdata_as_private) {
90- info_type_descriptions.USERDATA = 'Private';
91+ info_type_descriptions.USERDATA = 'Private';
92 }
93- var text_template = "This report has {info_type} information." +
94+ var text_template = "This report has {info_type} information." +
95 " You can change the information type later.";
96 value = info_type_descriptions[value];
97 return Y.Lang.substitute(text_template, {'info_type': value});
98-}
99+};
100
101 var setup_information_type = function() {
102 var itypes_table = Y.one('.radio-button-widget');
103@@ -69,7 +69,7 @@
104 var banner_text = get_new_banner_text(this.get('value'));
105 var private_type = (Y.Array.indexOf(
106 LP.cache.private_types, this.get('value')) >= 0);
107-
108+
109 update_privacy_banner(private_type, banner_text);
110 }, "input[name='field.information_type']");
111 };
112
113=== modified file 'lib/lp/bugs/javascript/tests/test_buglisting_utils.html'
114--- lib/lp/bugs/javascript/tests/test_buglisting_utils.html 2012-03-14 04:41:36 +0000
115+++ lib/lp/bugs/javascript/tests/test_buglisting_utils.html 2012-06-27 18:52:21 +0000
116@@ -21,6 +21,8 @@
117
118 <script type="text/javascript"
119 src="../../../../../build/js/lp/app/testing/testrunner.js"></script>
120+ <script type="text/javascript"
121+ src="../../../../../build/js/lp/app/testing/helpers.js"></script>
122
123 <link rel="stylesheet" href="../../../app/javascript/testing/test.css" />
124
125
126=== modified file 'lib/lp/bugs/javascript/tests/test_buglisting_utils.js'
127--- lib/lp/bugs/javascript/tests/test_buglisting_utils.js 2011-12-19 19:52:50 +0000
128+++ lib/lp/bugs/javascript/tests/test_buglisting_utils.js 2012-06-27 18:52:21 +0000
129@@ -1,4 +1,4 @@
130-/* Copyright (c) 2011, Canonical Ltd. All rights reserved. */
131+/* Copyright (c) 2011-2012, Canonical Ltd. All rights reserved. */
132
133 YUI.add('lp.buglisting_utils.test', function(Y) {
134
135@@ -14,7 +14,7 @@
136 var running_in_webkit = function() {
137 // AppleWebKit/531 is the Lucid html5 test browser.
138 // AppleWebKit/535 is Chromium 13-17 in Lucid through Oneric.
139- return (/AppleWebKit.53[15]/).test(navigator.userAgent);
140+ return (/AppleWebKit.53[157]/).test(navigator.userAgent);
141 };
142
143
144@@ -86,6 +86,7 @@
145 if (running_in_webkit()){
146 Y.Cookie._setDoc(Y.config.doc);
147 }
148+ Y.lp.testing.helpers.reset_history();
149 },
150
151 /**
152@@ -121,22 +122,6 @@
153 Assert.areEqual(this.cookie_name, this.list_util.get('cookie_name'));
154 },
155
156- test_field_visibility_defaults_readonly: function() {
157- // field_visibility_defaults is a readOnly attribute,
158- // so field_visibility_defaults will always return the same
159- // as LP.cache.field_visibility_defaults.
160- this.list_util = new Y.lp.buglisting_utils.BugListingConfigUtil();
161- var attempted_defaults = {
162- foo: 'bar',
163- baz: 'bop'
164- };
165- this.list_util.get('model').set(
166- 'field_visibility_defaults', attempted_defaults);
167- ObjectAssert.areEqual(
168- this.list_util.get('field_visibility_defaults'),
169- this.defaults.field_visibility_defaults);
170- },
171-
172 test_field_visibility_form_reference: function() {
173 // The form created from field_visibility defaults is referenced
174 // via BugListingConfigUtil.get('form')
175@@ -549,6 +534,7 @@
176
177 buglisting_utils.suite = suite;
178
179-}, '0.1', {'requires': [
180- 'test', 'node-event-simulate', 'cookie', 'lp.buglisting_utils',
181- 'lp.ordering']});
182+}, '0.1', {
183+ 'requires': [ 'test', 'lp.testing.helpers', 'node-event-simulate',
184+ 'cookie', 'lp.buglisting_utils', 'lp.ordering']
185+});
186
187=== modified file 'lib/lp/bugs/javascript/tests/test_filebug.js'
188--- lib/lp/bugs/javascript/tests/test_filebug.js 2012-06-20 05:25:44 +0000
189+++ lib/lp/bugs/javascript/tests/test_filebug.js 2012-06-27 18:52:21 +0000
190@@ -79,7 +79,7 @@
191 Y.lp.bugs.filebug.setup_filebug(true);
192 var banner_hidden = Y.one('.yui3-privacybanner-hidden');
193 Y.Assert.isNotNull(banner_hidden);
194- Y.one('[id=field.information_type.2]').simulate('click');
195+ Y.one('[id="field.information_type.2"]').simulate('click');
196 banner_hidden = Y.one('.yui3-privacybanner-hidden');
197 Y.Assert.isNull(banner_hidden);
198 var banner_text = Y.one('.banner-text').get('text');
199@@ -93,10 +93,10 @@
200 test_legacy_select_public_info_type: function () {
201 window.LP.cache.bug_private_by_default = true;
202 Y.lp.bugs.filebug.setup_filebug(true);
203- Y.one('[id=field.information_type.2]').simulate('click');
204+ Y.one('[id="field.information_type.2"]').simulate('click');
205 var banner_hidden = Y.one('.yui3-privacybanner-hidden');
206 Y.Assert.isNull(banner_hidden);
207- Y.one('[id=field.information_type.0]').simulate('click');
208+ Y.one('[id="field.information_type.0"]').simulate('click');
209 banner_hidden = Y.one('.yui3-privacybanner-hidden');
210 Y.Assert.isNotNull(banner_hidden);
211 },
212@@ -131,7 +131,7 @@
213 Y.Assert.areEqual('New', status_node.get('text'));
214 var status_edit_node = Y.one('#status-content a.sprite.edit');
215 Y.Assert.isNotNull(status_edit_node);
216- var legacy_dropdown = Y.one('[id=field.status]');
217+ var legacy_dropdown = Y.one('[id="field.status"]');
218 Y.Assert.isTrue(legacy_dropdown.hasClass('unseen'));
219 },
220
221@@ -143,7 +143,7 @@
222 var importance_edit_node =
223 Y.one('#importance-content a.sprite.edit');
224 Y.Assert.isNotNull(importance_edit_node);
225- var legacy_dropdown = Y.one('[id=field.importance]');
226+ var legacy_dropdown = Y.one('[id="field.importance"]');
227 Y.Assert.isTrue(legacy_dropdown.hasClass('unseen'));
228 },
229
230@@ -151,7 +151,7 @@
231 // This is so fields which the user does not have permission to see
232 // can be missing and everything still works as expected.
233 test_missing_fields: function () {
234- Y.one('[id=field.status]').remove(true);
235+ Y.one('[id="field.status"]').remove(true);
236 this.test_importance_setup();
237 },
238
239@@ -161,9 +161,9 @@
240 var status_popup = Y.one('#status-content a');
241 status_popup.simulate('click');
242 var status_choice = Y.one(
243- '.yui3-ichoicelist-content a[href=#Incomplete]');
244+ '.yui3-ichoicelist-content a[href="#Incomplete"]');
245 status_choice.simulate('click');
246- var legacy_dropdown = Y.one('[id=field.status]');
247+ var legacy_dropdown = Y.one('[id="field.status"]');
248 Y.Assert.areEqual('Incomplete', legacy_dropdown.get('value'));
249 },
250
251@@ -173,9 +173,9 @@
252 var status_popup = Y.one('#importance-content a');
253 status_popup.simulate('click');
254 var status_choice = Y.one(
255- '.yui3-ichoicelist-content a[href=#High]');
256+ '.yui3-ichoicelist-content a[href="#High"]');
257 status_choice.simulate('click');
258- var legacy_dropdown = Y.one('[id=field.importance]');
259+ var legacy_dropdown = Y.one('[id="field.importance"]');
260 Y.Assert.areEqual('High', legacy_dropdown.get('value'));
261 },
262
263@@ -198,9 +198,9 @@
264 var information_type_popup = Y.one('#information_type-content a');
265 information_type_popup.simulate('click');
266 var information_type_choice = Y.one(
267- '.yui3-ichoicelist-content a[href=#USERDATA]');
268+ '.yui3-ichoicelist-content a[href="#USERDATA"]');
269 information_type_choice.simulate('click');
270- var legacy_radio_button = Y.one('[id=field.information_type.3]');
271+ var legacy_radio_button = Y.one('[id="field.information_type.3"]');
272 Y.Assert.isTrue(legacy_radio_button.get('checked'));
273 },
274
275@@ -213,7 +213,7 @@
276 var information_type_popup = Y.one('#information_type-content a');
277 information_type_popup.simulate('click');
278 var information_type_choice = Y.one(
279- '.yui3-ichoicelist-content a[href=#USERDATA]');
280+ '.yui3-ichoicelist-content a[href="#USERDATA"]');
281 information_type_choice.simulate('click');
282 banner_hidden = Y.one('.yui3-privacybanner-hidden');
283 Y.Assert.isNull(banner_hidden);
284@@ -231,7 +231,7 @@
285 var information_type_popup = Y.one('#information_type-content a');
286 information_type_popup.simulate('click');
287 var information_type_choice = Y.one(
288- '.yui3-ichoicelist-content a[href=#USERDATA]');
289+ '.yui3-ichoicelist-content a[href="#USERDATA"]');
290 information_type_choice.simulate('click');
291 banner_hidden = Y.one('.yui3-privacybanner-hidden');
292 Y.Assert.isNull(banner_hidden);
293@@ -248,13 +248,13 @@
294 var information_type_popup = Y.one('#information_type-content a');
295 information_type_popup.simulate('click');
296 var information_type_choice = Y.one(
297- '.yui3-ichoicelist-content a[href=#USERDATA]');
298+ '.yui3-ichoicelist-content a[href="#USERDATA"]');
299 information_type_choice.simulate('click');
300 var banner_hidden = Y.one('.yui3-privacybanner-hidden');
301 Y.Assert.isNull(banner_hidden);
302 information_type_popup.simulate('click');
303 information_type_choice = Y.one(
304- '.yui3-ichoicelist-content a[href=#PUBLIC]');
305+ '.yui3-ichoicelist-content a[href="#PUBLIC"]');
306 information_type_choice.simulate('click');
307 banner_hidden = Y.one('.yui3-privacybanner-hidden');
308 Y.Assert.isNotNull(banner_hidden);
309
310=== modified file 'lib/lp/bugs/javascript/tests/test_information_type_choice.js'
311--- lib/lp/bugs/javascript/tests/test_information_type_choice.js 2012-06-20 05:25:44 +0000
312+++ lib/lp/bugs/javascript/tests/test_information_type_choice.js 2012-06-27 18:52:21 +0000
313@@ -126,7 +126,7 @@
314 var privacy_link = Y.one('#privacy-link');
315 privacy_link.simulate('click');
316 var private_choice = Y.one(
317- '.yui3-ichoicelist-content a[href=#Private]');
318+ '.yui3-ichoicelist-content a[href="#Private"]');
319 var orig_save_information_type = ns.save_information_type;
320 var function_called = false;
321 ns.save_information_type = function(widget, value, lp_client) {
322
323=== modified file 'standard_test_template.html'
324--- standard_test_template.html 2012-03-14 04:41:36 +0000
325+++ standard_test_template.html 2012-06-27 18:52:21 +0000
326@@ -21,6 +21,8 @@
327
328 <script type="text/javascript"
329 src="../../../../../../build/js/lp/app/testing/testrunner.js"></script>
330+ <script type="text/javascript"
331+ src="../../../../../build/js/lp/app/testing/helpers.js"></script>
332
333 <link rel="stylesheet" href="../../../../app/javascript/testing/test.css" />
334
335
336=== modified file 'standard_test_template.js'
337--- standard_test_template.js 2012-04-06 17:28:25 +0000
338+++ standard_test_template.js 2012-06-27 18:52:21 +0000
339@@ -18,4 +18,4 @@
340
341 }));
342
343-}, '0.1', {'requires': ['test', 'console', 'lp.${LIBRARY}']});
344+}, '0.1', {'requires': ['test', 'lp.testing.helpers', 'console', 'lp.${LIBRARY}']});