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

Proposed by Richard Harding
Status: Merged
Approved by: j.c.sackett
Approved revision: no longer in the source branch.
Merged at revision: 15561
Proposed branch: lp:~rharding/launchpad/registry_yui35
Merge into: lp:launchpad
Diff against target: 2638 lines (+1221/-1226)
7 files modified
lib/lp/registry/javascript/distroseriesdifferences_details.js (+11/-7)
lib/lp/registry/javascript/team.js (+3/-3)
lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.html (+97/-5)
lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.js (+1025/-1108)
lib/lp/registry/javascript/tests/test_team.js (+9/-9)
lib/lp/registry/javascript/tests/test_team_mailinglists.html (+1/-1)
lib/lp/registry/javascript/tests/test_team_mailinglists.js (+75/-93)
To merge this branch: bzr merge lp:~rharding/launchpad/registry_yui35
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+113407@code.launchpad.net

Commit message

Update the registery JS tests for YUI 3.5

Description of the change

= Summary =

This updates the registry JS test files to pass in YUI 3.5.

Note that 98% of this is around the distroseriesdifferences_details.js as they
required some extra work. Once again I've got a giant branch diff, but a
significant portion is just moving the content around.

I've tried to list explicit points of changes made in the Implementation
notes.

== Implementation Notes ==

The changes in the other files were mostly just fixing quotes around selectors
using attributes.

test_distroseriesdifference_details notes

#8
The tests didn't mock out IO requests. This leads to distracting console
errors because ajax requests come back failed/etc and attempt to perform some
dom manipulation with a dom that's been emptied due to tearDown() methods.

In order to work correctly with MockIo this was tweaked. See comment in code.

#32
See above, this is due to the tweak in the namespace.io.

#136
There were some forms already built from the .html file using x-template, but
there were other large bits of the html constructed from JS. I moved all of
the large blocks of html into the .html file as x-template and adjusted setup
scripts accordingly. (See #335, #416, )

#1155
I moved all utility methods to the top of the file. I find that in order for
others to come along and reuse utility methods, it's best if they're at the
top of the file for visibility. If there's a helper 500 lines in between
tests, it'll never been seen/reused.

So anything that isn't a test is moved up to the top of the test file starting
here. This includes the code that pulls the html blocks from the x-template
sections (See #1213 onward)

#1235
Most of these tests had no tearDown method at all. The setup method was
calling Y.one('#placeholder').empty().append(). Teardown should do teardown
and so the .empty in all cases was moved to a tearDown method. In many cases
there were still things not torn down and I had to fight a lot of cross test
pollution. This also tears down the introduction of the mockio added.

#1546
There was a method assertWillBeFired that just failed and caused test
pollution. I honestly never got to the total bottom of what was up, but the
code is actually firing two events and so something was getting messed up. I
inlined the assertion and changed it to actually count that it got two hits
based on the html generated (two rows). This seems to have cleaned things up
at the expense of ditching the old assert method. This is used in the next
three tests.

#2470
These are just moved tests. I didn't change these up.

== LoC Qualification ==

It's a negative LoC change.

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

Looks good. Thanks Rick.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/javascript/distroseriesdifferences_details.js'
2--- lib/lp/registry/javascript/distroseriesdifferences_details.js 2011-08-30 13:22:03 +0000
3+++ lib/lp/registry/javascript/distroseriesdifferences_details.js 2012-07-05 17:22:27 +0000
4@@ -16,7 +16,12 @@
5 */
6 namespace.lp_client = new Y.lp.client.Launchpad();
7
8-namespace.io = Y.io;
9+// Our MockIo() needs to be called and then .io() called on it. To keep scope
10+// of this in the io() mock method we need to not just pass the method, but
11+// the object. In this way the call to namespace.io will be:
12+// Y.io()
13+// MockIo.io()
14+namespace.io = Y;
15
16 function ExpandableRowWidget(config) {
17 ExpandableRowWidget.superclass.constructor.apply(this, arguments);
18@@ -48,7 +53,7 @@
19 },
20
21 expander_handler: function(e) {
22- e.preventDefault();
23+ e.halt();
24 var parsed = this.parse_row_data();
25 this._toggle.toggleClass('treeCollapsed').toggleClass('treeExpanded');
26
27@@ -183,7 +188,7 @@
28 'source_name': source_name
29 }
30 };
31- namespace.io(uri, config);
32+ namespace.io.io(uri, config);
33
34 }
35 });
36@@ -351,11 +356,10 @@
37 */
38 blacklist_submit_handler: function(method_name, blacklist_all, comment,
39 target) {
40+ var self = this;
41 this.lock();
42-
43 var diff_rows = this.relatedRows;
44
45- var self = this;
46 var config = {
47 on: {
48 success: function(updated_entry, args) {
49@@ -854,7 +858,7 @@
50 */
51 namespace.get_number_of_packages = function() {
52 return Y.all(
53- 'input[name=field.selected_differences]').filter(':checked').size();
54+ 'input[name="field.selected_differences"]').filter(':checked').size();
55 };
56
57 /**
58@@ -890,7 +894,7 @@
59 */
60 namespace.get_packages_summary = function() {
61 var all_inputs = Y.all(
62- 'input[name=field.selected_differences]').filter(':checked');
63+ 'input[name="field.selected_differences"]').filter(':checked');
64 var nb_inputs = all_inputs.size();
65 var summary = Y.Node.create('<div><ul></ul></div>'),
66 summary_ul = summary.one('ul');
67
68=== modified file 'lib/lp/registry/javascript/team.js'
69--- lib/lp/registry/javascript/team.js 2012-06-05 22:08:17 +0000
70+++ lib/lp/registry/javascript/team.js 2012-07-05 17:22:27 +0000
71@@ -183,12 +183,12 @@
72 * @param visibility
73 */
74 module.visibility_changed_subscription = function(visibility) {
75- var widget_label = Y.one("[for=field.subscriptionpolicy]");
76+ var widget_label = Y.one("[for='field.subscriptionpolicy']");
77 if (!Y.Lang.isValue(widget_label)) {
78 return;
79 }
80 var widget = widget_label.ancestor('div').one('.radio-button-widget');
81- widget.all("td input[name=field.subscriptionpolicy]")
82+ widget.all("td input[name='field.subscriptionpolicy']")
83 .each(function(choice_node) {
84 var input_row = choice_node.ancestor('tr');
85 var help_row = input_row.next(function (node) {
86@@ -218,7 +218,7 @@
87 * @param visibility
88 */
89 module.visibility_changed_visibility = function(visibility) {
90- var widget_label = Y.one("[for=field.visibility]");
91+ var widget_label = Y.one("[for='field.visibility']");
92 if (!Y.Lang.isValue(widget_label)) {
93 return;
94 }
95
96=== modified file 'lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.html'
97--- lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.html 2012-03-14 04:41:36 +0000
98+++ lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.html 2012-07-05 17:22:27 +0000
99@@ -21,6 +21,10 @@
100
101 <script type="text/javascript"
102 src="../../../../../build/js/lp/app/testing/testrunner.js"></script>
103+ <script type="text/javascript"
104+ src="../../../../../build/js/lp/app/testing/helpers.js"></script>
105+ <script type="text/javascript"
106+ src="../../../../../build/js/lp/app/testing/mockio.js"></script>
107
108 <link rel="stylesheet" href="../../../app/javascript/testing/test.css" />
109
110@@ -47,8 +51,7 @@
111 </head>
112 <body class="yui3-skin-sam">
113 <ul id="suites">
114- <!-- <li>lp.large_indicator.test</li> -->
115- <li>lp.distroseriesdifferences_details.test</li>
116+ <li>lp.registry.distroseriesdifferences_details.test</li>
117 </ul>
118
119 <h1>Testing the DistroSeriesDifferenceDetails javascript</h1>
120@@ -56,8 +59,8 @@
121 <h2>Errors</h2>
122 <div id="errors"></div>
123
124- <div id="placeholder" style="display:none;">
125- </div>
126+ <table id="placeholder" style="display:none;">
127+ </table>
128
129 <script type="text/x-template" id="derivedtd-template">
130 <td id="derived_row">
131@@ -90,5 +93,94 @@
132 <td class="latest-comment-fragment"></td>
133 </tr>
134 </script>
135- </body>
136+
137+ <script type="text/x-template" id="blacklist_html">
138+ <div class="blacklist-options" style="float:left">
139+ <dl>
140+ <dt>Ignored:</dt>
141+ <dd>
142+ <form>
143+ <div>
144+ <div class="value">
145+ <label for="field.blacklist_options.0">
146+ <input type="radio" value="NONE"
147+ name="field.blacklist_options"
148+ id="field.blacklist_options.0" checked="checked"
149+ class="radioType">&nbsp;No</input>
150+ </label><br>
151+ <label for="field.blacklist_options.1">
152+ <input type="radio" value="BLACKLISTED_ALWAYS"
153+ name="field.blacklist_options"
154+ id="field.blacklist_options.1" class="radioType">
155+ &nbsp;All versions</input>
156+ </label><br>
157+ <label for="field.blacklist_options.2">
158+ <input type="radio" value="BLACKLISTED_CURRENT"
159+ name="field.blacklist_options"
160+ id="field.blacklist_options.2"
161+ class="radioType">&nbsp;These versions</input>
162+ </label>
163+ </div>
164+ <input type="hidden" value="1"
165+ name="field.blacklist_options-empty-marker" />
166+ </div>
167+ </form>
168+ </dd>
169+ </dl>
170+ </div>
171+ </script>
172+
173+ <script type="text/x-template" id="blacklist_extra_row">
174+ <tr id="extra_row">
175+ <td>
176+ <div class="diff-extra-container">
177+ <div>
178+ <dl>
179+ <dt class="package-diff-placeholder">
180+ <span class="package-diff-compute-request">
181+ <a class="js-action sprite add" href="">
182+ Compute differences from last common version:
183+ </a>
184+ </span></dt>
185+ <dd>
186+ <ul class="package-diff-status">
187+ <li>
188+ <span id="derived" class="PENDING">
189+ 1.2.1 to Derilucid version: 1.2.4
190+ </span>
191+ </li>
192+ <li>
193+ <span id="parent" class="request-derived-diff">
194+ 1.2.1 to Lucid version: 1.2.3
195+ </span>
196+ </li>
197+ </ul>
198+ </dd>
199+ </dl>
200+ </div>
201+ {blacklist_html}
202+ <div class="boardComment ">
203+ <div class="boardCommentDetails">
204+ <a class="sprite person" href="/~mark">Mark S.</a>
205+ wrote on 2010-06-26
206+ </div>
207+ <div class="boardCommentBody">Body</div>
208+ </div>
209+ <div class="add-comment-placeholder evolution">
210+ <a href="" class="widget-hd js-action sprite add">
211+ Add comment</a>
212+ </div>
213+ </div>
214+ </td>
215+ </tr>
216+ </script>
217+ <script type="text/x-template" id="blacklist_whole_table">
218+ <table class="listing">
219+ <tbody>
220+ {row}
221+ {extra_row}
222+ </tbody>
223+ </table>
224+ </script>
225+ </body>
226 </html>
227
228=== modified file 'lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.js'
229--- lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.js 2012-02-21 22:46:28 +0000
230+++ lib/lp/registry/javascript/tests/test_distroseriesdifferences_details.js 2012-07-05 17:22:27 +0000
231@@ -1,1110 +1,1027 @@
232-/* Copyright 2009-2012 Canonical Ltd. This software is licensed under the
233- GNU Affero General Public License version 3 (see the file LICENSE). */
234-
235-YUI().use(
236- 'lp.testing.runner', 'test', 'console', 'node-event-simulate',
237- 'lp.soyuz.base', "lp.anim", "lazr.formoverlay", "lazr.effects",
238- 'lp.soyuz.dynamic_dom_updater', 'event-simulate', "io-base",
239- 'lp.registry.distroseriesdifferences_details', function(Y) {
240-
241-var suite = new Y.Test.Suite("Distroseries differences Tests");
242-var dsd_details = Y.lp.registry.distroseriesdifferences_details;
243-var dsd_uri = '/duntu/dwarty/+source/evolution/+difference/ubuntu/warty';
244-
245-var row_html = Y.one('#localpackagediffs-template').getContent();
246-var derivedtd_html = Y.one('#derivedtd-template').getContent();
247-
248-/**
249- * Utility function to create a row of the diff pages.
250- *
251- * @param package_name {String} The name of the package for this row.
252- * @param parent_version {String} The version for the package in the parent
253- * series.
254- * @param derived_version {String} The version for the package in the derived
255- * series.
256- * @missing_row {Boolean} If false, generate a row of the +localpackagediffs
257- * page, if true, generate a row of te +missingpackages page.
258- */
259-var createRow = function(package_name, parent_version, derived_version,
260- missing_row) {
261- var derivedtd = '';
262- if (!missing_row) {
263- derivedtd = Y.substitute(
264- derivedtd_html,
265- {package_name: package_name,
266- derived_version: derived_version
267- });
268- }
269- return Y.substitute(
270- row_html,
271- {package_name: package_name,
272- parent_version: parent_version,
273- derived_version: derived_version,
274- derivedrow: derivedtd
275- });
276-};
277-
278-var row = createRow(
279- 'evolution', '2.0.9-1', '2.0.8-4', false);
280-
281-var testExpandableRowWidget = {
282-
283- name: 'expandable-row-widget',
284-
285- setUp: function() {
286- Y.one("#placeholder")
287- .empty()
288- .append(Y.Node.create(row));
289- this.toggle = Y.one('a.toggle-extra');
290- },
291-
292- test_initializer: function() {
293- var row = new dsd_details.ExpandableRowWidget({toggle: this.toggle});
294- Y.Assert.isTrue(this.toggle.hasClass('treeCollapsed'));
295- Y.Assert.isTrue(this.toggle.hasClass('sprite'));
296- },
297-
298- test_parse_row_data: function() {
299- var row = new dsd_details.ExpandableRowWidget({toggle: this.toggle});
300- var parsed = row.parse_row_data();
301- var res = {
302- source_name: 'evolution',
303- parent_series_name: 'warty',
304- parent_distro_name: 'ubuntu',
305- nb_columns: 7};
306- Y.ObjectAssert.areEqual(res, parsed);
307- },
308-
309- test_expander_handler_adds_new_row: function() {
310- var row = new dsd_details.ExpandableRowWidget({toggle: this.toggle});
311- row._toggle.simulate('click');
312- var new_row = row._row.next();
313- Y.Assert.isTrue(new_row.hasClass('evolution'));
314- Y.Assert.isTrue(new_row.hasClass('diff-extra'));
315- Y.Assert.areEqual(7, new_row.one('td').getAttribute('colspan'));
316- },
317-
318- test_expand_handler_toggles_hiding: function() {
319- var row = new dsd_details.ExpandableRowWidget({toggle: this.toggle});
320- Y.Assert.isTrue(row._toggle.hasClass('treeCollapsed'));
321- // First click opens up the new row.
322- row._toggle.simulate('click');
323- var new_row = row._row.next();
324- Y.Assert.isTrue(row._toggle.hasClass('treeExpanded'));
325- Y.Assert.isFalse(new_row.hasClass('unseen'));
326- Y.Assert.isTrue(new_row.one('div').hasClass('diff-extra-container'));
327- // Second click hides it.
328- row._toggle.simulate('click');
329- Y.Assert.isTrue(row._toggle.hasClass('treeCollapsed'));
330- Y.Assert.isTrue(new_row.hasClass('unseen'));
331- }
332-
333-};
334-
335-var blacklist_html = [
336- '<div class="blacklist-options" style="float:left">',
337- ' <dl>',
338- ' <dt>Ignored:</dt>',
339- ' <dd>',
340- ' <form>',
341- ' <div>',
342- ' <div class="value">',
343- ' <label for="field.blacklist_options.0">',
344- ' <input type="radio" value="NONE" ',
345- ' name="field.blacklist_options"',
346- ' id="field.blacklist_options.0" checked="checked" ',
347- ' class="radioType">&nbsp;No</input>',
348- ' </label><br>',
349- ' <label for="field.blacklist_options.1">',
350- ' <input type="radio" value="BLACKLISTED_ALWAYS" ',
351- ' name="field.blacklist_options"',
352- ' id="field.blacklist_options.1" class="radioType">',
353- ' &nbsp;All versions</input>',
354- ' </label><br>',
355- ' <label for="field.blacklist_options.2">',
356- ' <input type="radio" value="BLACKLISTED_CURRENT"',
357- ' name="field.blacklist_options"',
358- ' id="field.blacklist_options.2"',
359- ' class="radioType">&nbsp;These versions</input>',
360- ' </label>',
361- ' </div>',
362- ' <input type="hidden" value="1" ',
363- ' name="field.blacklist_options-empty-marker" />',
364- ' </div>',
365- ' </form>',
366- ' </dd>',
367- ' </dl>',
368- '</div>'
369- ].join('');
370-
371-var extra_row = [
372- '<tr id="extra_row">',
373- ' <td>',
374- ' <div class="diff-extra-container">',
375- ' <div>',
376- ' <dl>',
377- ' <dt class="package-diff-placeholder">',
378- ' <span class="package-diff-compute-request">',
379- ' <a class="js-action sprite add" href="">',
380- ' Compute differences from last common version:',
381- ' </a>',
382- ' </span></dt>',
383- ' <dd>',
384- ' <ul class="package-diff-status">',
385- ' <li>',
386- ' <span id="derived" class="PENDING">',
387- ' 1.2.1 to Derilucid version: 1.2.4',
388- ' </span>',
389- ' </li>',
390- ' <li>',
391- ' <span id="parent" class="request-derived-diff">',
392- ' 1.2.1 to Lucid version: 1.2.3',
393- ' </span>',
394- ' </li>',
395- ' </ul>',
396- ' </dd>',
397- ' </dl>',
398- ' </div>',
399- blacklist_html,
400- ' <div class="boardComment ">',
401- ' <div class="boardCommentDetails">',
402- ' <a class="sprite person" href="/~mark">Mark S.</a>',
403- ' wrote on 2010-06-26',
404- ' </div>',
405- ' <div class="boardCommentBody">Body</div>',
406- ' </div>',
407- ' <div class="add-comment-placeholder evolution">',
408- ' <a href="" class="widget-hd js-action sprite add">',
409- ' Add comment</a>',
410- ' </div>',
411- ' </div>',
412- ' </td>',
413- '</tr>'
414- ].join('');
415-
416-var whole_table = [
417- '<table class="listing"><tbody>',
418- row,
419- extra_row,
420- '</tbody></table>'
421- ].join('');
422-
423-var testPackageDiffUpdate = {
424-
425- name: 'package-diff',
426-
427- setUp: function() {
428- Y.one("#placeholder")
429- .empty()
430- .append(Y.Node.create(extra_row));
431- },
432-
433- test_vocabulary_helper: function() {
434- // The vocabulary helper extracts the selected item from a
435- // jsonified vocabulary.
436- var voc = [
437- {"token": "PENDING", "title": "Pending"},
438- {"token": "COMPLETED", "selected": true, "title": "Completed"},
439- {"token": "FAILED", "title": "Failed"}];
440- var res = dsd_details.get_selected(voc);
441- Y.Assert.areEqual('COMPLETED', res.token);
442- Y.Assert.areEqual('Completed', res.title);
443- var voc_nothing_selected = [
444- {"token": "PENDING", "title": "Pending"},
445- {"token": "COMPLETED", "title": "Completed"},
446- {"token": "FAILED", "title": "Failed"}];
447- Y.Assert.isUndefined(dsd_details.get_selected(voc_nothing_selected));
448- },
449-
450- test_add_msg_node: function() {
451- var msg_txt = 'Exemple text';
452- var msg_node = Y.Node.create(msg_txt);
453- placeholder = Y.one('#placeholder');
454- dsd_details.add_msg_node(placeholder, msg_node);
455- Y.Assert.areEqual(
456- placeholder.one('.package-diff-placeholder').get('innerHTML'),
457- msg_txt);
458- }
459-};
460-
461-var assertAllDisabled = function(node, selector) {
462- var all_input_status = node.all(selector).get('disabled');
463- Y.ArrayAssert.doesNotContain(false, all_input_status);
464-};
465-
466-var assertAllEnabled = function(node, selector) {
467- var all_input_status = node.all(selector).get('disabled');
468- Y.ArrayAssert.doesNotContain(true, all_input_status);
469-};
470-
471-function Comment() {}
472-
473-Comment.prototype.get = function(key) {
474- var data = {
475- comment_date: "2011-08-08T13:15:50.636269+00:00",
476- body_text: 'This is the comment',
477- self_link: ["https://lp.net/api/devel/u/d//+source/",
478- "evolution/+difference/ubuntu/warty/comments/6"
479- ].join(''),
480- web_link: ["https://lp.net/d/d/+source/evolution/",
481- "+difference/ubuntu/warty/comments/6"
482- ].join('')
483- };
484- return data[key];
485-};
486-
487-var testBlacklistWidget = {
488-
489- name: 'package-diff-update-interaction',
490-
491- setUp: function() {
492- Y.one("#placeholder")
493- .empty()
494- .append(Y.Node.create(whole_table));
495- this.node = Y.one('.blacklist-options');
496- this.commentWidget = null;
497- this.widget = new dsd_details.BlacklistWidget(
498- {srcNode: this.node,
499- sourceName: 'evolution',
500- dsdLink: '/a/link',
501- commentWidget: this.commentWidget
502- });
503- // Set the animation duration to 0.1 to avoid having to wait for its
504- // completion for too long.
505- this.widget.ANIM_DURATION = 0.1;
506- },
507-
508- test_initializer: function() {
509- Y.Assert.areEqual(this.node, this.widget.get('srcNode'));
510- Y.Assert.areEqual('evolution', this.widget.sourceName);
511- Y.Assert.areEqual('/a/link', this.widget.dsdLink);
512- Y.Assert.areEqual(
513- this.latestCommentContainer,
514- this.widget.latestCommentContainer);
515- Y.Assert.areEqual(this.commentWidget, this.widget.commentWidget);
516- },
517-
518- test_wire_blacklist_click: function() {
519- var input = Y.one(
520- 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
521- var fired = false;
522-
523- var show_comment_overlay = function(target) {
524- fired = true;
525- Y.Assert.areEqual(input, target);
526- };
527- this.widget.show_comment_overlay = show_comment_overlay;
528- input.simulate('click');
529-
530- Y.Assert.isTrue(fired);
531- },
532-
533- test_wire_blacklist_changed: function() {
534- var fired = false;
535-
536- var blacklist_submit_handler = function(arg1, arg2, arg3, arg4) {
537- fired = true;
538- Y.Assert.areEqual(1, arg1);
539- Y.Assert.areEqual(2, arg2);
540- Y.Assert.areEqual(3, arg3);
541- Y.Assert.areEqual(4, arg4);
542- };
543- this.widget.blacklist_submit_handler = blacklist_submit_handler;
544- this.widget.fire('blacklist_changed', 1, 2, 3, 4);
545-
546- Y.Assert.isTrue(fired);
547- },
548-
549- test_containing_rows: function() {
550- var expected = [Y.one('.evolution'), Y.one('#extra_row')];
551- Y.ArrayAssert.itemsAreEqual(expected, this.widget.relatedRows);
552- },
553-
554- test_show_comment_overlay_creates_overlay: function() {
555- var input = Y.one('div.blacklist-options input');
556- var overlay = this.widget.show_comment_overlay(input);
557- // Check overlay's structure.
558- Y.Assert.isInstanceOf(Y.lazr.FormOverlay, overlay);
559- Y.Assert.isNotNull(overlay.form_node.one('textarea'));
560- Y.Assert.areEqual(
561- 'OK',
562- overlay.form_node.one('button[type="submit"]').get('text'));
563- Y.Assert.areEqual(
564- 'Cancel',
565- overlay.form_node.one('button[type="button"]').get('text'));
566- Y.Assert.isTrue(overlay.get('visible'));
567- },
568-
569- test_show_comment_overlay_cancel_hides_overlay: function() {
570- var input = Y.one('div.blacklist-options input');
571- var overlay = this.widget.show_comment_overlay(input);
572- var cancel_button = overlay.form_node.one('button[type="button"]');
573- Y.Assert.isTrue(overlay.get('visible'));
574- cancel_button.simulate('click');
575- Y.Assert.isFalse(overlay.get('visible'));
576- },
577-
578- test_show_comment_overlay_ok_hides_overlay: function() {
579- var input = Y.one('div.blacklist-options input');
580- var overlay = this.widget.show_comment_overlay(input);
581- Y.Assert.isTrue(overlay.get('visible'));
582- overlay.form_node.one('button[type="submit"]').simulate('click');
583- Y.Assert.isFalse(overlay.get('visible'));
584- },
585-
586- test_show_comment_overlay_fires_event: function() {
587- var input = Y.one('div.blacklist-options input[value="NONE"]');
588- input.set('checked', true);
589- var overlay = this.widget.show_comment_overlay(input);
590- var event_fired = false;
591- var method = null;
592- var all = null;
593- var comment = null;
594- var target = null;
595-
596- var handleEvent = function(e, e_method, e_all, e_comment, e_target) {
597- event_fired = true;
598- method = e_method;
599- all = e_all;
600- comment = e_comment;
601- target = e_target;
602- };
603-
604- this.widget.on("blacklist_changed", handleEvent, this.widget);
605-
606- overlay.form_node.one('textarea').set('text', 'Test comment');
607- overlay.form_node.one('button[type="submit"]').simulate('click');
608-
609- Y.Assert.isTrue(event_fired);
610- Y.Assert.areEqual('unblacklist', method);
611- Y.Assert.areEqual(false, all);
612- Y.Assert.areEqual('Test comment', comment);
613- Y.Assert.areEqual(input, target);
614- },
615-
616- test_show_comment_overlay_fires_event_blacklist_all: function() {
617- var input = Y.one(
618- 'div.blacklist-options input[value="BLACKLISTED_ALWAYS"]');
619- input.set('checked', true);
620- var overlay = this.widget.show_comment_overlay(input);
621- var method = null;
622- var all = null;
623- var target = null;
624-
625- var handleEvent = function(e, e_method, e_all, e_comment, e_target) {
626- method = e_method;
627- all = e_all;
628- target = e_target;
629- };
630- this.widget.on("blacklist_changed", handleEvent, this.widget);
631- overlay.form_node.one('button[type="submit"]').simulate('click');
632-
633- Y.Assert.areEqual('blacklist', method);
634- Y.Assert.areEqual(true, all);
635- Y.Assert.areEqual(input, target);
636- },
637-
638- test_show_comment_overlay_fires_event_blacklist: function() {
639- var input = Y.one(
640- 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
641- input.set('checked', true);
642- var overlay = this.widget.show_comment_overlay(input);
643- var method = null;
644- var all = null;
645- var target = null;
646-
647- var handleEvent = function(e, e_method, e_all, e_comment, e_target) {
648- method = e_method;
649- all = e_all;
650- target = e_target;
651- };
652- this.widget.on("blacklist_changed", handleEvent, this.widget);
653- overlay.form_node.one('button[type="submit"]').simulate('click');
654-
655- Y.Assert.areEqual('blacklist', method);
656- Y.Assert.areEqual(false, all);
657- Y.Assert.areEqual(input, target);
658- },
659-
660- assertIsLocked: function() {
661- var node = this.widget.get('srcNode');
662- Y.Assert.isNotNull(node.one('img[src="/@@/spinner"]'));
663- assertAllDisabled(node, 'div.blacklist-options input');
664- },
665-
666- assertIsUnlocked: function() {
667- var node = this.widget.get('srcNode');
668- Y.Assert.isNull(node.one('img[src="/@@/spinner"]'));
669- assertAllEnabled(node, 'div.blacklist-options input');
670- },
671-
672- test_lock: function() {
673- this.widget.lock();
674- this.assertIsLocked();
675- },
676-
677- test_unlock: function() {
678- this.widget.unlock();
679- this.assertIsUnlocked();
680- },
681-
682- test_lock_unlock: function() {
683- this.widget.lock();
684- this.widget.unlock();
685- this.assertIsUnlocked();
686- },
687-
688- patchNamedPost: function(method_name, expected_parameters) {
689- var comment_entry = new Comment();
690- var self = this;
691- dsd_details.lp_client.named_post = function(url, func, config) {
692- Y.Assert.areEqual(func, method_name);
693- Y.ObjectAssert.areEqual(expected_parameters, config.parameters);
694- self.assertIsLocked();
695- config.on.success(comment_entry);
696- self.assertIsUnlocked();
697- };
698- },
699-
700- assertWillBeFired: function(event_name) {
701- var self = this;
702- this._fired = false;
703- var listener = function(e) {
704- // Only call resume if the test is waiting, this is
705- // required because we sometimes hit this code before
706- // we had the chance to call this.wait().
707- if (Y.Test.Runner._waiting) {
708- self.resume(function(){});
709- }
710- else {
711- self._fired = true;
712- }
713- };
714- this.widget.on(event_name, listener);
715- },
716-
717- test_blacklist_submit_handler_blacklist_simple: function() {
718- var mockCommentWidget = Y.Mock();
719- Y.Mock.expect(mockCommentWidget, {
720- method: "display_new_comment",
721- args: [Y.Mock.Value.Object]
722- });
723- this.widget.commentWidget = mockCommentWidget;
724-
725- this.patchNamedPost(
726- 'blacklist',
727- {comment: 'Test comment', all: false});
728- var input = Y.one(
729- 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
730- input.set('checked', false);
731-
732- this.assertWillBeFired('blacklisting_animation_ended');
733- this.widget.blacklist_submit_handler(
734- 'blacklist', false, "Test comment", input);
735-
736- Y.Assert.isTrue(input.get('checked'));
737- // Only wait for resume to happen if the event has not been fired
738- // yet.
739- if (!this._fired) {
740- this.wait(1000);
741- }
742- },
743-
744- test_blacklist_submit_handler_blacklist_null_comment_widget: function() {
745- // The widget can cope with a null commentWidget.
746- Y.Assert.isNull(this.widget.commentWidget);
747- var input = Y.one(
748- 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
749- this.widget.blacklist_submit_handler(
750- 'blacklist', false, "Test comment", input);
751- },
752-
753- test_blacklist_submit_handler_blacklist_all: function() {
754- var mockCommentWidget = Y.Mock();
755- Y.Mock.expect(mockCommentWidget, {
756- method: "display_new_comment",
757- args: [Y.Mock.Value.Object]
758- });
759- this.widget.commentWidget = mockCommentWidget;
760-
761- this.patchNamedPost(
762- 'blacklist',
763- {comment: 'Test comment', all: true});
764- var input = Y.one(
765- 'div.blacklist-options input[value="BLACKLISTED_ALWAYS"]');
766- input.set('checked', false);
767-
768- this.assertWillBeFired('blacklisting_animation_ended');
769- this.widget.blacklist_submit_handler(
770- 'blacklist', true, "Test comment", input);
771-
772- Y.Assert.isTrue(input.get('checked'));
773- // Only wait for resume to happen if the event has not been fired
774- // yet.
775- if (!this._fired) {
776- this.wait(1000);
777- }
778- },
779-
780- test_blacklist_submit_handler_unblacklist: function() {
781- var mockCommentWidget = Y.Mock();
782- Y.Mock.expect(mockCommentWidget, {
783- method: "display_new_comment",
784- args: [Y.Mock.Value.Object]
785- });
786- this.widget.commentWidget = mockCommentWidget;
787-
788- this.patchNamedPost(
789- 'unblacklist',
790- {comment: 'Test comment', all: true});
791- var input = Y.one('div.blacklist-options input[value="NONE"]');
792- input.set('checked', false);
793-
794- this.assertWillBeFired('blacklisting_animation_ended');
795- this.widget.blacklist_submit_handler(
796- 'unblacklist', true, "Test comment", input);
797-
798- Y.Assert.isTrue(input.get('checked'));
799- // Only wait for resume to happen if the event has not been fired
800- // yet.
801- if (!this._fired) {
802- this.wait(1000);
803- }
804- },
805-
806- test_blacklist_submit_handler_failure: function() {
807- var self = this;
808- dsd_details.lp_client.named_post = function(url, func, config) {
809- self.assertIsLocked();
810- config.on.failure();
811- self.assertIsUnlocked();
812- };
813- var input = Y.one('div.blacklist-options input');
814- input.set('checked', false);
815- this.widget.blacklist_submit_handler(
816- null, 'unblacklist', true, "Test comment", input);
817- }
818-};
819-
820-var testAddCommentWidget = {
821-
822- name: 'test-add-comment-widget',
823-
824- setUp: function() {
825- Y.one("#placeholder")
826- .empty()
827- .append(Y.Node.create(whole_table));
828- this.latestCommentContainer = Y.one('td.latest-comment-fragment');
829- this.addCommentPlaceholder = Y.one('div.add-comment-placeholder');
830- this.apiUri = '/testuri/';
831- this.widget = new dsd_details.AddCommentWidget({
832- srcNode: this.node,
833- apiUri: this.apiUri,
834- latestCommentContainer: this.latestCommentContainer,
835- addCommentPlaceholder: this.addCommentPlaceholder
836- });
837- this.widget.render(this.addCommentPlaceholder);
838- },
839-
840- tearDown: function() {
841- this.widget.destroy();
842- },
843-
844- test_initializer: function() {
845- Y.Assert.areEqual(
846- this.latestCommentContainer, this.widget.latestCommentContainer);
847- Y.Assert.areEqual(
848- this.addCommentPlaceholder, this.widget.addCommentPlaceholder);
849- Y.Assert.areEqual(
850- this.apiUri, this.widget.apiUri);
851- },
852-
853- test_comment_text_getter: function() {
854- this.widget.get('srcNode').one('textarea').set('value', 'Content');
855- Y.Assert.areEqual(
856- 'Content',
857- this.widget.get('comment_text'));
858- },
859-
860- test_comment_text_setter: function() {
861- this.widget.set('comment_text', 'Content');
862- Y.Assert.areEqual(
863- 'Content',
864- this.widget.get('srcNode').one('textarea').get('value'));
865- },
866-
867- test_slide_in: function() {
868- // 'Manually' open the widget.
869- var node = this.widget.get('srcNode');
870- node.one('div.widget-bd').setStyle('height', '1000px');
871- var self = this;
872- var listener = function(e) {
873- self.resume(function(){
874- fired = true;
875- });
876- };
877- this.widget.on('slid_in', listener);
878- this.widget.slide_in();
879- this.wait(1000);
880- },
881-
882- test_slide_out: function() {
883- var fired = false;
884- var self = this;
885- var listener = function(e) {
886- self.resume(function(){
887- fired = true;
888- });
889- };
890- this.widget.on('slid_out', listener);
891- this.widget.slide_out();
892- this.wait(1000);
893- },
894-
895- assertIsLocked: function() {
896- var node = this.widget.get('srcNode');
897- Y.Assert.isNotNull(node.one('img[src="/@@/spinner"]'));
898- assertAllDisabled(node, 'textarea, button');
899- },
900-
901- assertIsUnlocked: function() {
902- var node = this.widget.get('srcNode');
903- Y.Assert.isNull(node.one('img[src="/@@/spinner"]'));
904- assertAllEnabled(node, 'textarea, button');
905- },
906-
907- test_lock: function() {
908- this.widget.lock();
909- this.assertIsLocked();
910- },
911-
912- test_unlock: function() {
913- this.widget.unlock();
914- this.assertIsUnlocked();
915- },
916-
917- test_lock_unlock: function() {
918- this.widget.lock();
919- this.widget.unlock();
920- this.assertIsUnlocked();
921- },
922-
923- test_wire_click_add_comment_link: function() {
924- var fired = false;
925- var input = this.widget.get('srcNode').one('a.widget-hd');
926- var self = this;
927- var listener = function(e) {
928- self.resume(function(){
929- fired = true;
930- });
931- };
932- this.widget.on('slid_out', listener);
933- input.simulate('click');
934- this.wait();
935- },
936-
937- test_wire_comment_added_calls_display_new_comment: function() {
938- var fired = false;
939- var comment_entry = new Comment();
940-
941- var display_new_comment = function(entry) {
942- fired = true;
943- Y.ObjectAssert.areEqual(comment_entry, entry);
944- };
945- this.widget.display_new_comment = display_new_comment;
946- this.widget.fire('comment_added', comment_entry);
947-
948- Y.Assert.isTrue(fired);
949- },
950-
951- test_wire_click_button_calls_add_comment_handler: function() {
952- var input = this.widget.get('srcNode').one('button');
953- var fired = false;
954-
955- var add_comment_handler = function() {
956- fired = true;
957- };
958- this.widget.add_comment_handler = add_comment_handler;
959- input.simulate('click');
960-
961- Y.Assert.isTrue(fired);
962- },
963-
964- test_clean: function() {
965- var comment_text = 'Content';
966- this.widget.get('srcNode').one('textarea').set('value', comment_text);
967- var self = this;
968- var comment_entry = new Comment();
969- var post_called = false;
970- dsd_details.lp_client.named_post = function(url, method, config) {
971- post_called = true;
972- Y.Assert.areEqual('addComment', method);
973- Y.Assert.areEqual(comment_text, config.parameters.comment);
974- config.on.success(comment_entry);
975- };
976- // The event comment_added will be fired.
977- var event_fired = false;
978- event_handler = function(e) {
979- event_fired = true;
980- Y.ObjectAssert.areEqual(comment_entry, e.details[0]);
981- };
982- this.widget.on('comment_added', event_handler);
983-
984- this.widget.add_comment_handler();
985-
986- Y.Assert.areEqual('', this.widget.get('comment_text'));
987- Y.Assert.isTrue(post_called);
988- Y.Assert.isTrue(event_fired);
989- },
990-
991- test_display_new_comment_success: function() {
992- var comment_html = '<span id="new_comment">Comment content.</span>';
993- var self = this;
994- var comment_entry = new Comment();
995- var get_called = false;
996- dsd_details.lp_client.get = function(url, config) {
997- get_called = true;
998- config.on.success(comment_html);
999- };
1000- // The method update_latest_comment will be called with the right
1001- // arguments.
1002- var update_latest_called = false;
1003- dsd_details.update_latest_comment = function(entry, node) {
1004- update_latest_called = true;
1005- Y.ObjectAssert.areEqual(comment_entry, entry);
1006- Y.Assert.areEqual(self.widget.latestCommentContainer, node);
1007- };
1008- this.widget.display_new_comment(comment_entry);
1009-
1010- // The new comment has been added to the list of comments.
1011- Y.Assert.areEqual(
1012- 'Comment content.',
1013- this.widget.addCommentPlaceholder.previous().get('text'));
1014- Y.Assert.isTrue(get_called);
1015- Y.Assert.isTrue(update_latest_called);
1016- },
1017-
1018- test_display_new_comment_failure: function() {
1019- var comment_html = '<span id="new_comment">Comment content.</span>';
1020- var comment_entry = new Comment();
1021- var get_called = false;
1022- dsd_details.lp_client.get = function(url, config) {
1023- get_called = true;
1024- config.on.failure(comment_html);
1025- };
1026- // The method update_latest_comment won't.
1027- var update_latest_called = false;
1028- dsd_details.update_latest_comment = function(entry, node) {
1029- update_latest_called = true;
1030- };
1031- this.widget.display_new_comment(comment_entry);
1032-
1033- // The new comment has *not* been added to the list of comments.
1034- // The last existing comment is still displayed.
1035- Y.Assert.areEqual(
1036- 'Mark S.',
1037- this.widget.addCommentPlaceholder.previous().one(
1038- 'a.person').get('text'));
1039- Y.Assert.isTrue(get_called);
1040- Y.Assert.isFalse(update_latest_called);
1041- },
1042-
1043- test_add_comment_handler_success: function() {
1044- var comment_text = 'Content';
1045- this.widget.get('srcNode').one('textarea').set('value', comment_text);
1046- var comment_entry = new Comment();
1047- var post_called = false;
1048- dsd_details.lp_client.named_post = function(url, method, config) {
1049- post_called = true;
1050- Y.Assert.areEqual('addComment', method);
1051- Y.Assert.areEqual(comment_text, config.parameters.comment);
1052- config.on.success(comment_entry);
1053- };
1054- // The event comment_added will be fired.
1055- var event_fired = false;
1056- event_handler = function(e) {
1057- event_fired = true;
1058- Y.ObjectAssert.areEqual(comment_entry, e.details[0]);
1059- };
1060- this.widget.on('comment_added', event_handler);
1061-
1062- this.widget.add_comment_handler();
1063-
1064- Y.Assert.areEqual('', this.widget.get('comment_text'));
1065- Y.Assert.isTrue(post_called);
1066- Y.Assert.isTrue(event_fired);
1067- this.assertIsUnlocked();
1068- },
1069-
1070- test_add_comment_handler_failure: function() {
1071- var comment_text = 'Content';
1072- this.widget.get('srcNode').one('textarea').set('value', comment_text);
1073- var post_called = false;
1074- dsd_details.lp_client.named_post = function(url, method, config) {
1075- post_called = true;
1076- config.on.failure();
1077- };
1078- this.widget.add_comment_handler();
1079-
1080- // The content has not been cleaned.
1081- Y.Assert.areEqual('Content', this.widget.get('comment_text'));
1082- Y.Assert.isTrue(post_called);
1083- this.assertIsUnlocked();
1084- },
1085-
1086- test_add_comment_handler_empty: function() {
1087- // An empty comment is treated as a mistake.
1088- var comment_text = '';
1089- this.widget.get('srcNode').one('textarea').set('value', comment_text);
1090- var self = this;
1091- var comment_entry = new Comment();
1092- var post_called = false;
1093- dsd_details.lp_client.named_post = function(url, method, config) {
1094- post_called = true;
1095- };
1096- this.widget.add_comment_handler();
1097- Y.Assert.isFalse(post_called);
1098- }
1099-
1100-};
1101-
1102-var testPackageDiffUpdateInteraction = {
1103-
1104- name: 'package-diff-update-interaction',
1105-
1106- setUp: function() {
1107- Y.one("#placeholder")
1108- .empty()
1109- .append(Y.Node.create(whole_table));
1110- var first_poll = true;
1111- pending_voc = [
1112- {"token": "PENDING", "selected": true, "title": "Pending"},
1113- {"token": "COMPLETED", "title": "Completed"},
1114- {"token": "FAILED", "title": "Failed"}];
1115- completed_voc = [
1116- {"token": "PENDING", "title": "Pending"},
1117- {"token": "COMPLETED", "selected": true, "title": "Completed"},
1118- {"token": "FAILED", "title": "Failed"}];
1119-
1120- // Monkey patch request.
1121- dsd_details.lp_client.named_post = function(url, func, config) {
1122- config.on.success();};
1123- dsd_details.lp_client.named_get = function(url, func, config) {
1124- config.on.success();};
1125- dsd_details.lp_client.get = function(uri, config) {
1126- if (first_poll === true) {
1127- first_poll = false;
1128- config.on.success(pending_voc);
1129- }
1130- else {
1131- config.on.success(completed_voc);
1132- }
1133- };
1134- dsd_details.poll_interval = 100;
1135- },
1136-
1137- test_request_wrong_click: function() {
1138- // Click on the placeholder has no effect.
1139- // The listeners are on the link with class
1140- // '.package-diff-compute-request'.
1141- // bug=746277.
1142- var placeholder = Y.one('#placeholder');
1143- placeholder
1144- .one('#derived')
1145+/* Copyright (c) 2009-2012 Canonical Ltd. All rights reserved. */
1146+
1147+// XXX: rharding 2012-07-03 bug=1020671: The tests should be adjusted to not
1148+// require the 1000s wait waiting for the animation. We should allow a
1149+// skip_animation or some other method of allowing tests to run synchronously
1150+// without wait times.
1151+
1152+YUI.add('lp.registry.distroseriesdifferences_details.test', function (Y) {
1153+ var module = Y.lp.registry.distroseriesdifferences_details;
1154+
1155+ /**
1156+ * Utility function to create a row of the diff pages.
1157+ *
1158+ * @param package_name {String} The name of the package for this row.
1159+ * @param parent_version {String} The version for the package in the parent
1160+ * series.
1161+ * @param derived_version {String} The version for the package in the derived
1162+ * series.
1163+ * @missing_row {Boolean} If false, generate a row of the +localpackagediffs
1164+ * page, if true, generate a row of te +missingpackages page.
1165+ */
1166+ var create_row = function(package_name, parent_version, derived_version,
1167+ missing_row) {
1168+ var derivedtd = '';
1169+ if (!missing_row) {
1170+ derivedtd = Y.substitute(derivedtd_html, {
1171+ package_name: package_name,
1172+ derived_version: derived_version
1173+ });
1174+ }
1175+ return Y.substitute( row_html, {
1176+ package_name: package_name,
1177+ parent_version: parent_version,
1178+ derived_version: derived_version,
1179+ derivedrow: derivedtd
1180+ });
1181+ };
1182+
1183+ var assertAllDisabled = function(node, selector) {
1184+ var all_input_status = node.all(selector).get('disabled');
1185+ Y.ArrayAssert.doesNotContain(false, all_input_status);
1186+ };
1187+
1188+ var assertAllEnabled = function(node, selector) {
1189+ var all_input_status = node.all(selector).get('disabled');
1190+ Y.ArrayAssert.doesNotContain(true, all_input_status);
1191+ };
1192+
1193+ var Comment = function () {
1194+ this.data = {
1195+ comment_date: "2011-08-08T13:15:50.636269+00:00",
1196+ body_text: 'This is the comment',
1197+ self_link: ["https://lp.net/api/devel/u/d//+source/",
1198+ "evolution/+difference/ubuntu/warty/comments/6"
1199+ ].join(''),
1200+ web_link: ["https://lp.net/d/d/+source/evolution/",
1201+ "+difference/ubuntu/warty/comments/6"
1202+ ].join('')
1203+ };
1204+ this.get = function (key) {
1205+ return this.data[key];
1206+ };
1207+ };
1208+
1209+ var dsd_uri = '/duntu/dwarty/+source/evolution/+difference/ubuntu/warty';
1210+ var row_html = Y.one('#localpackagediffs-template').getContent();
1211+ var derivedtd_html = Y.one('#derivedtd-template').getContent();
1212+ var blacklist_html = Y.one('#blacklist_html').getContent();
1213+ var extra_row = Y.one('#blacklist_extra_row').getContent();
1214+ extra_row = Y.substitute(extra_row, {
1215+ blacklist_html: blacklist_html
1216+ });
1217+ var whole_table = Y.one('#blacklist_whole_table').getContent();
1218+ whole_table = Y.substitute(whole_table, {
1219+ row: create_row('evolution', '2.0.9-1', '2.0.8-4', false),
1220+ extra_row: extra_row
1221+ });
1222+
1223+ var tests = Y.namespace('lp.registry.distroseriesdifferences_details.test');
1224+ tests.suite = new Y.Test.Suite('lp.registry.distroseriesdifferences_details Tests');
1225+ tests.suite.add(new Y.Test.Case({
1226+ name: 'expandable-row-widget',
1227+ setUp: function() {
1228+ module.io = new Y.lp.testing.mockio.MockIo();
1229+ var row = create_row('evolution', '2.0.9-1', '2.0.8-4', false);
1230+ Y.one("#placeholder").append(Y.Node.create(row));
1231+ this.toggle = Y.one('a.toggle-extra');
1232+ },
1233+
1234+ tearDown: function () {
1235+ Y.one('#placeholder').empty();
1236+ delete this.toggle;
1237+ module.io = Y.io;
1238+ },
1239+
1240+ test_initializer: function() {
1241+ var row = new module.ExpandableRowWidget({toggle: this.toggle});
1242+ Y.Assert.isTrue(this.toggle.hasClass('treeCollapsed'));
1243+ Y.Assert.isTrue(this.toggle.hasClass('sprite'));
1244+ },
1245+
1246+ test_parse_row_data: function() {
1247+ var row = new module.ExpandableRowWidget({toggle: this.toggle});
1248+ var parsed = row.parse_row_data();
1249+ var res = {
1250+ source_name: 'evolution',
1251+ parent_series_name: 'warty',
1252+ parent_distro_name: 'ubuntu',
1253+ nb_columns: 7};
1254+ Y.ObjectAssert.areEqual(res, parsed);
1255+ },
1256+
1257+ test_expander_handler_adds_new_row: function() {
1258+ var row = new module.ExpandableRowWidget({toggle: this.toggle});
1259+ row._toggle.simulate('click');
1260+ var new_row = row._row.next();
1261+ Y.Assert.isTrue(new_row.hasClass('evolution'));
1262+ Y.Assert.isTrue(new_row.hasClass('diff-extra'));
1263+ Y.Assert.areEqual(7, new_row.one('td').getAttribute('colspan'));
1264+ },
1265+
1266+ test_expand_handler_toggles_hiding: function() {
1267+ var row = new module.ExpandableRowWidget({toggle: this.toggle});
1268+ Y.Assert.isTrue(row._toggle.hasClass('treeCollapsed'));
1269+ // First click opens up the new row.
1270+ row._toggle.simulate('click');
1271+ var new_row = row._row.next();
1272+ Y.Assert.isTrue(row._toggle.hasClass('treeExpanded'), 'is expanded');
1273+ Y.Assert.isFalse(new_row.hasClass('unseen'), 'not unseen');
1274+ Y.Assert.isTrue(new_row.one('div').hasClass('diff-extra-container'));
1275+ // Second click hides it.
1276+ row._toggle.simulate('click');
1277+ Y.Assert.isTrue(row._toggle.hasClass('treeCollapsed'), 'is collapsed');
1278+ Y.Assert.isTrue(new_row.hasClass('unseen'), 'is unseen');
1279+ }
1280+ }));
1281+
1282+ tests.suite.add(new Y.Test.Case({
1283+ name: 'package-diff',
1284+ setUp: function() {
1285+ Y.one("#placeholder").append(Y.Node.create(extra_row));
1286+ },
1287+
1288+ tearDown: function () {
1289+ Y.one('#placeholder').empty();
1290+ },
1291+
1292+ test_vocabulary_helper: function() {
1293+ // The vocabulary helper extracts the selected item from a
1294+ // jsonified vocabulary.
1295+ var voc = [
1296+ {"token": "PENDING", "title": "Pending"},
1297+ {"token": "COMPLETED", "selected": true, "title": "Completed"},
1298+ {"token": "FAILED", "title": "Failed"}];
1299+ var res = module.get_selected(voc);
1300+ Y.Assert.areEqual('COMPLETED', res.token);
1301+ Y.Assert.areEqual('Completed', res.title);
1302+ var voc_nothing_selected = [
1303+ {"token": "PENDING", "title": "Pending"},
1304+ {"token": "COMPLETED", "title": "Completed"},
1305+ {"token": "FAILED", "title": "Failed"}];
1306+ Y.Assert.isUndefined(module.get_selected(voc_nothing_selected));
1307+ },
1308+
1309+ test_add_msg_node: function() {
1310+ var msg_txt = 'Exemple text';
1311+ var msg_node = Y.Node.create(msg_txt);
1312+ placeholder = Y.one('#placeholder');
1313+ module.add_msg_node(placeholder, msg_node);
1314+ Y.Assert.areEqual(
1315+ placeholder.one('.package-diff-placeholder').get('innerHTML'),
1316+ msg_txt);
1317+ }
1318+ }));
1319+
1320+ tests.suite.add(new Y.Test.Case({
1321+ name: 'package-diff-update-interaction',
1322+ setUp: function() {
1323+ Y.one("#placeholder").append(Y.Node.create(whole_table));
1324+ this.node = Y.one('.blacklist-options');
1325+ this.commentWidget = null;
1326+ this.widget = new module.BlacklistWidget({
1327+ srcNode: this.node,
1328+ sourceName: 'evolution',
1329+ dsdLink: '/a/link',
1330+ commentWidget: this.commentWidget
1331+ });
1332+ // Set the animation duration to 0.1 to avoid having to wait for its
1333+ // completion for too long.
1334+ this.widget.ANIM_DURATION = 0.1;
1335+ },
1336+
1337+ tearDown: function () {
1338+ Y.one('#placeholder').empty();
1339+ delete this.widget;
1340+
1341+ if (!Y.Lang.isUndefined(this._fired)) {
1342+ delete this._fired;
1343+ }
1344+ },
1345+
1346+ assertIsLocked: function() {
1347+ var node = this.widget.get('srcNode');
1348+ Y.Assert.isNotNull(node.one('img[src="/@@/spinner"]'));
1349+ assertAllDisabled(node, 'div.blacklist-options input');
1350+ },
1351+
1352+ assertIsUnlocked: function() {
1353+ var node = this.widget.get('srcNode');
1354+ Y.Assert.isNull(node.one('img[src="/@@/spinner"]'));
1355+ assertAllEnabled(node, 'div.blacklist-options input');
1356+ },
1357+
1358+ test_lock: function() {
1359+ this.widget.lock();
1360+ this.assertIsLocked();
1361+ },
1362+
1363+ test_unlock: function() {
1364+ this.widget.unlock();
1365+ this.assertIsUnlocked();
1366+ },
1367+
1368+ test_lock_unlock: function() {
1369+ this.widget.lock();
1370+ this.widget.unlock();
1371+ this.assertIsUnlocked();
1372+ },
1373+
1374+ patchNamedPost: function(method_name, expected_parameters) {
1375+ var that = this;
1376+ var comment_entry = new Comment();
1377+ module.lp_client.named_post = function(url, func, config) {
1378+ Y.Assert.areEqual(func, method_name);
1379+ Y.ObjectAssert.areEqual(expected_parameters, config.parameters);
1380+ that.assertIsLocked();
1381+ config.on.success(comment_entry);
1382+ that.assertIsUnlocked();
1383+ };
1384+ },
1385+
1386+ test_initializer: function() {
1387+ Y.Assert.areEqual(this.node, this.widget.get('srcNode'));
1388+ Y.Assert.areEqual('evolution', this.widget.sourceName);
1389+ Y.Assert.areEqual('/a/link', this.widget.dsdLink);
1390+ Y.Assert.areEqual(
1391+ this.latestCommentContainer,
1392+ this.widget.latestCommentContainer);
1393+ Y.Assert.areEqual(this.commentWidget, this.widget.commentWidget);
1394+ },
1395+
1396+ test_wire_blacklist_click: function() {
1397+ var input = Y.one(
1398+ 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
1399+ var fired = false;
1400+
1401+ var show_comment_overlay = function(target) {
1402+ fired = true;
1403+ Y.Assert.areEqual(input, target);
1404+ };
1405+ this.widget.show_comment_overlay = show_comment_overlay;
1406+ input.simulate('click');
1407+
1408+ Y.Assert.isTrue(fired);
1409+ },
1410+
1411+ test_wire_blacklist_changed: function() {
1412+ var fired = false;
1413+
1414+ var blacklist_submit_handler = function(arg1, arg2, arg3, arg4) {
1415+ fired = true;
1416+ Y.Assert.areEqual(1, arg1);
1417+ Y.Assert.areEqual(2, arg2);
1418+ Y.Assert.areEqual(3, arg3);
1419+ Y.Assert.areEqual(4, arg4);
1420+ };
1421+ this.widget.blacklist_submit_handler = blacklist_submit_handler;
1422+ this.widget.fire('blacklist_changed', 1, 2, 3, 4);
1423+ Y.Assert.isTrue(fired);
1424+ },
1425+
1426+ test_containing_rows: function() {
1427+ var expected = [Y.one('.evolution'), Y.one('#extra_row')];
1428+ Y.ArrayAssert.itemsAreEqual(expected, this.widget.relatedRows);
1429+ },
1430+
1431+ test_show_comment_overlay_creates_overlay: function() {
1432+ var input = Y.one('div.blacklist-options input');
1433+ var overlay = this.widget.show_comment_overlay(input);
1434+ // Check overlay's structure.
1435+ Y.Assert.isInstanceOf(Y.lazr.FormOverlay, overlay);
1436+ Y.Assert.isNotNull(overlay.form_node.one('textarea'));
1437+ Y.Assert.areEqual(
1438+ 'OK',
1439+ overlay.form_node.one('button[type="submit"]').get('text'));
1440+ Y.Assert.areEqual(
1441+ 'Cancel',
1442+ overlay.form_node.one('button[type="button"]').get('text'));
1443+ Y.Assert.isTrue(overlay.get('visible'));
1444+ },
1445+
1446+ test_show_comment_overlay_cancel_hides_overlay: function() {
1447+ var input = Y.one('div.blacklist-options input');
1448+ var overlay = this.widget.show_comment_overlay(input);
1449+ var cancel_button = overlay.form_node.one('button[type="button"]');
1450+ Y.Assert.isTrue(overlay.get('visible'));
1451+ cancel_button.simulate('click');
1452+ Y.Assert.isFalse(overlay.get('visible'));
1453+ },
1454+
1455+ test_show_comment_overlay_ok_hides_overlay: function() {
1456+ var input = Y.one('div.blacklist-options input');
1457+ var overlay = this.widget.show_comment_overlay(input);
1458+ Y.Assert.isTrue(overlay.get('visible'));
1459+ overlay.form_node.one('button[type="submit"]').simulate('click');
1460+ Y.Assert.isFalse(overlay.get('visible'));
1461+ },
1462+
1463+ test_show_comment_overlay_fires_event: function() {
1464+ var input = Y.one('div.blacklist-options input[value="NONE"]');
1465+ input.set('checked', true);
1466+ var overlay = this.widget.show_comment_overlay(input);
1467+ var event_fired = false;
1468+ var method = null;
1469+ var all = null;
1470+ var comment = null;
1471+ var target = null;
1472+
1473+ var handleEvent = function(e, e_method, e_all, e_comment, e_target) {
1474+ event_fired = true;
1475+ method = e_method;
1476+ all = e_all;
1477+ comment = e_comment;
1478+ target = e_target;
1479+ };
1480+
1481+ this.widget.on("blacklist_changed", handleEvent, this.widget);
1482+
1483+ overlay.form_node.one('textarea').set('text', 'Test comment');
1484+ overlay.form_node.one('button[type="submit"]').simulate('click');
1485+
1486+ Y.Assert.isTrue(event_fired);
1487+ Y.Assert.areEqual('unblacklist', method);
1488+ Y.Assert.areEqual(false, all);
1489+ Y.Assert.areEqual('Test comment', comment);
1490+ Y.Assert.areEqual(input, target);
1491+ },
1492+
1493+ test_show_comment_overlay_fires_event_blacklist_all: function() {
1494+ var input = Y.one(
1495+ 'div.blacklist-options input[value="BLACKLISTED_ALWAYS"]');
1496+ input.set('checked', true);
1497+ var overlay = this.widget.show_comment_overlay(input);
1498+ var method = null;
1499+ var all = null;
1500+ var target = null;
1501+
1502+ var handleEvent = function(e, e_method, e_all, e_comment, e_target) {
1503+ method = e_method;
1504+ all = e_all;
1505+ target = e_target;
1506+ };
1507+ this.widget.on("blacklist_changed", handleEvent, this.widget);
1508+ overlay.form_node.one('button[type="submit"]').simulate('click');
1509+
1510+ Y.Assert.areEqual('blacklist', method);
1511+ Y.Assert.areEqual(true, all);
1512+ Y.Assert.areEqual(input, target);
1513+ },
1514+
1515+ test_show_comment_overlay_fires_event_blacklist: function() {
1516+ var input = Y.one(
1517+ 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
1518+ input.set('checked', true);
1519+ var overlay = this.widget.show_comment_overlay(input);
1520+ var method = null;
1521+ var all = null;
1522+ var target = null;
1523+
1524+ var handleEvent = function(e, e_method, e_all, e_comment, e_target) {
1525+ method = e_method;
1526+ all = e_all;
1527+ target = e_target;
1528+ };
1529+ this.widget.on("blacklist_changed", handleEvent, this.widget);
1530+ overlay.form_node.one('button[type="submit"]').simulate('click');
1531+
1532+ Y.Assert.areEqual('blacklist', method);
1533+ Y.Assert.areEqual(false, all);
1534+ Y.Assert.areEqual(input, target);
1535+ },
1536+
1537+ test_blacklist_submit_handler_blacklist_null_comment_widget: function() {
1538+ // The widget can cope with a null commentWidget.
1539+ Y.Assert.isNull(this.widget.commentWidget);
1540+ var input = Y.one(
1541+ 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
1542+ this.widget.blacklist_submit_handler(
1543+ 'blacklist', false, "Test comment", input);
1544+ },
1545+
1546+ test_blacklist_submit_handler_blacklist_simple: function() {
1547+ var mockCommentWidget = Y.Mock();
1548+ Y.Mock.expect(mockCommentWidget, {
1549+ method: "display_new_comment",
1550+ args: [Y.Mock.Value.Object]
1551+ });
1552+ this.widget.commentWidget = mockCommentWidget;
1553+
1554+ this.patchNamedPost(
1555+ 'blacklist',
1556+ {comment: 'Test comment', all: false});
1557+ var input = Y.one(
1558+ 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
1559+ input.set('checked', false);
1560+
1561+ var fired = 0;
1562+ var listener = function(e) {
1563+ // Only call resume if the test is waiting, this is
1564+ // required because we sometimes hit this code before
1565+ // we had the chance to call this.wait().
1566+ fired += 1;
1567+ };
1568+ this.widget.on('blacklisting_animation_ended', listener);
1569+ this.widget.blacklist_submit_handler(
1570+ 'blacklist', false, "Test comment", input);
1571+
1572+ Y.Assert.isTrue(input.get('checked'));
1573+
1574+ this.wait(function () {
1575+ // There are two rows that get worked across.
1576+ Y.Assert.areEqual(2, fired);
1577+ }, 1000);
1578+ },
1579+
1580+ test_blacklist_submit_handler_blacklist_all: function() {
1581+ var mockCommentWidget = Y.Mock();
1582+ Y.Mock.expect(mockCommentWidget, {
1583+ method: "display_new_comment",
1584+ args: [Y.Mock.Value.Object]
1585+ });
1586+ this.widget.commentWidget = mockCommentWidget;
1587+
1588+ this.patchNamedPost(
1589+ 'blacklist',
1590+ {comment: 'Test comment', all: true});
1591+ var input = Y.one(
1592+ 'div.blacklist-options input[value="BLACKLISTED_CURRENT"]');
1593+ input.set('checked', false);
1594+
1595+ var fired = 0;
1596+ var listener = function(e) {
1597+ // Only call resume if the test is waiting, this is
1598+ // required because we sometimes hit this code before
1599+ // we had the chance to call this.wait().
1600+ fired += 1;
1601+ };
1602+ this.widget.on('blacklisting_animation_ended', listener);
1603+ this.widget.blacklist_submit_handler(
1604+ 'blacklist', true, "Test comment", input);
1605+
1606+ Y.Assert.isTrue(input.get('checked'));
1607+
1608+ this.wait(function () {
1609+ // There are two rows that get worked across.
1610+ Y.Assert.areEqual(2, fired);
1611+ }, 1000);
1612+ },
1613+
1614+ test_blacklist_submit_handler_unblacklist: function() {
1615+ var fired = false;
1616+ var mockCommentWidget = Y.Mock();
1617+ Y.Mock.expect(mockCommentWidget, {
1618+ method: "display_new_comment",
1619+ args: [Y.Mock.Value.Object]
1620+ });
1621+ this.widget.commentWidget = mockCommentWidget;
1622+
1623+ this.patchNamedPost(
1624+ 'unblacklist', {
1625+ comment: 'Test comment',
1626+ all: true
1627+ });
1628+
1629+ var input = Y.one('div.blacklist-options input[value="NONE"]');
1630+ input.set('checked', false);
1631+
1632+ var listener = function (ev) {
1633+ fired = true;
1634+ };
1635+
1636+ this.widget.on('blacklisting_animation_ended', listener);
1637+ this.widget.blacklist_submit_handler(
1638+ 'unblacklist', true, "Test comment", input);
1639+
1640+ Y.Assert.isTrue(input.get('checked'));
1641+ this.wait(function () {
1642+ // There are two rows that get worked across.
1643+ Y.Assert.isTrue(fired);
1644+ }, 1000);
1645+ },
1646+
1647+ test_blacklist_submit_handler_failure: function() {
1648+ var that = this;
1649+ module.lp_client.named_post = function(url, func, config) {
1650+ that.assertIsLocked();
1651+ config.on.failure();
1652+ that.assertIsUnlocked();
1653+ };
1654+ var input = Y.one('div.blacklist-options input');
1655+ input.set('checked', false);
1656+ this.widget.blacklist_submit_handler(
1657+ null, 'unblacklist', true, "Test comment", input);
1658+ }
1659+ }));
1660+
1661+ tests.suite.add(new Y.Test.Case({
1662+ name: 'test-add-comment-widget',
1663+ setUp: function() {
1664+ Y.one("#placeholder").append(Y.Node.create(whole_table));
1665+ this.latestCommentContainer = Y.one('td.latest-comment-fragment');
1666+ this.addCommentPlaceholder = Y.one('div.add-comment-placeholder');
1667+ this.apiUri = '/testuri/';
1668+ this.widget = new module.AddCommentWidget({
1669+ srcNode: this.node,
1670+ apiUri: this.apiUri,
1671+ latestCommentContainer: this.latestCommentContainer,
1672+ addCommentPlaceholder: this.addCommentPlaceholder
1673+ });
1674+ this.widget.render(this.addCommentPlaceholder);
1675+ },
1676+
1677+ tearDown: function() {
1678+ this.widget.destroy();
1679+ Y.one('#placeholder').empty();
1680+ },
1681+
1682+ test_initializer: function() {
1683+ Y.Assert.areEqual(
1684+ this.latestCommentContainer, this.widget.latestCommentContainer);
1685+ Y.Assert.areEqual(
1686+ this.addCommentPlaceholder, this.widget.addCommentPlaceholder);
1687+ Y.Assert.areEqual(
1688+ this.apiUri, this.widget.apiUri);
1689+ },
1690+
1691+ test_comment_text_getter: function() {
1692+ this.widget.get('srcNode').one('textarea').set('value', 'Content');
1693+ Y.Assert.areEqual(
1694+ 'Content',
1695+ this.widget.get('comment_text'));
1696+ },
1697+
1698+ test_comment_text_setter: function() {
1699+ this.widget.set('comment_text', 'Content');
1700+ Y.Assert.areEqual(
1701+ 'Content',
1702+ this.widget.get('srcNode').one('textarea').get('value'));
1703+ },
1704+
1705+ test_slide_in: function() {
1706+ // 'Manually' open the widget.
1707+ var that = this;
1708+ var fired = false;
1709+ var node = this.widget.get('srcNode');
1710+ node.one('div.widget-bd').setStyle('height', '1000px');
1711+ var listener = function (e) {
1712+ fired = true;
1713+ that.resume();
1714+ };
1715+ this.widget.on('slid_in', listener);
1716+ this.widget.slide_in();
1717+ this.wait(function () {
1718+ Y.Assert.isTrue(fired);
1719+ }, 2000);
1720+ },
1721+
1722+ test_slide_out: function() {
1723+ var fired = false;
1724+ var that = this;
1725+ var listener = function(e) {
1726+ that.resume(function(){
1727+ fired = true;
1728+ });
1729+ };
1730+ this.widget.on('slid_out', listener);
1731+ this.widget.slide_out();
1732+ this.wait(1000);
1733+ },
1734+
1735+ assertIsLocked: function() {
1736+ var node = this.widget.get('srcNode');
1737+ Y.Assert.isNotNull(node.one('img[src="/@@/spinner"]'));
1738+ assertAllDisabled(node, 'textarea, button');
1739+ },
1740+
1741+ assertIsUnlocked: function() {
1742+ var node = this.widget.get('srcNode');
1743+ Y.Assert.isNull(node.one('img[src="/@@/spinner"]'));
1744+ assertAllEnabled(node, 'textarea, button');
1745+ },
1746+
1747+ test_lock: function() {
1748+ this.widget.lock();
1749+ this.assertIsLocked();
1750+ },
1751+
1752+ test_unlock: function() {
1753+ this.widget.unlock();
1754+ this.assertIsUnlocked();
1755+ },
1756+
1757+ test_lock_unlock: function() {
1758+ this.widget.lock();
1759+ this.widget.unlock();
1760+ this.assertIsUnlocked();
1761+ },
1762+
1763+ test_wire_click_add_comment_link: function() {
1764+ var fired = false;
1765+ var input = this.widget.get('srcNode').one('a.widget-hd');
1766+ var that = this;
1767+ var listener = function(e) {
1768+ that.resume(function(){
1769+ fired = true;
1770+ });
1771+ };
1772+ this.widget.on('slid_out', listener);
1773+ input.simulate('click');
1774+ this.wait();
1775+ },
1776+
1777+ test_wire_comment_added_calls_display_new_comment: function() {
1778+ var fired = false;
1779+ var comment_entry = new Comment();
1780+
1781+ var display_new_comment = function(entry) {
1782+ fired = true;
1783+ Y.ObjectAssert.areEqual(comment_entry, entry);
1784+ };
1785+ this.widget.display_new_comment = display_new_comment;
1786+ this.widget.fire('comment_added', comment_entry);
1787+
1788+ Y.Assert.isTrue(fired);
1789+ },
1790+
1791+ test_wire_click_button_calls_add_comment_handler: function() {
1792+ var input = this.widget.get('srcNode').one('button');
1793+ var fired = false;
1794+ var add_comment_handler = function() {
1795+ fired = true;
1796+ };
1797+ this.widget.add_comment_handler = add_comment_handler;
1798+ input.simulate('click');
1799+ Y.Assert.isTrue(fired);
1800+ },
1801+
1802+ test_clean: function() {
1803+ var that = this;
1804+ var comment_text = 'Content';
1805+ this.widget.get('srcNode').one('textarea').set('value', comment_text);
1806+ var comment_entry = new Comment();
1807+ var post_called = false;
1808+ module.lp_client.named_post = function(url, method, config) {
1809+ post_called = true;
1810+ Y.Assert.areEqual('addComment', method);
1811+ Y.Assert.areEqual(comment_text, config.parameters.comment);
1812+ config.on.success(comment_entry);
1813+ };
1814+ // The event comment_added will be fired.
1815+ var event_fired = false;
1816+ event_handler = function(e) {
1817+ event_fired = true;
1818+ Y.ObjectAssert.areEqual(comment_entry, e.details[0]);
1819+ };
1820+ this.widget.on('comment_added', event_handler);
1821+ this.widget.add_comment_handler();
1822+
1823+ Y.Assert.areEqual('', this.widget.get('comment_text'));
1824+ Y.Assert.isTrue(post_called);
1825+ Y.Assert.isTrue(event_fired);
1826+ },
1827+
1828+ test_display_new_comment_success: function() {
1829+ var that = this;
1830+ var comment_html = '<span id="new_comment">Comment content.</span>';
1831+ var comment_entry = new Comment();
1832+ var get_called = false;
1833+ module.lp_client.get = function(url, config) {
1834+ get_called = true;
1835+ config.on.success(comment_html);
1836+ };
1837+ // The method update_latest_comment will be called with the right
1838+ // arguments.
1839+ var update_latest_called = false;
1840+ module.update_latest_comment = function(entry, node) {
1841+ update_latest_called = true;
1842+ Y.ObjectAssert.areEqual(comment_entry, entry);
1843+ Y.Assert.areEqual(that.widget.latestCommentContainer, node);
1844+ };
1845+ this.widget.display_new_comment(comment_entry);
1846+
1847+ // The new comment has been added to the list of comments.
1848+ Y.Assert.areEqual(
1849+ 'Comment content.',
1850+ this.widget.addCommentPlaceholder.previous().get('text'));
1851+ Y.Assert.isTrue(get_called);
1852+ Y.Assert.isTrue(update_latest_called);
1853+ },
1854+
1855+ test_display_new_comment_failure: function() {
1856+ var comment_html = '<span id="new_comment">Comment content.</span>';
1857+ var comment_entry = new Comment();
1858+ var get_called = false;
1859+ module.lp_client.get = function(url, config) {
1860+ get_called = true;
1861+ config.on.failure(comment_html);
1862+ };
1863+ // The method update_latest_comment won't.
1864+ var update_latest_called = false;
1865+ module.update_latest_comment = function(entry, node) {
1866+ update_latest_called = true;
1867+ };
1868+ this.widget.display_new_comment(comment_entry);
1869+
1870+ // The new comment has *not* been added to the list of comments.
1871+ // The last existing comment is still displayed.
1872+ Y.Assert.areEqual(
1873+ 'Mark S.',
1874+ this.widget.addCommentPlaceholder.previous().one(
1875+ 'a.person').get('text'));
1876+ Y.Assert.isTrue(get_called);
1877+ Y.Assert.isFalse(update_latest_called);
1878+ },
1879+
1880+ test_add_comment_handler_success: function() {
1881+ var comment_text = 'Content';
1882+ this.widget.get('srcNode').one('textarea').set('value', comment_text);
1883+ var comment_entry = new Comment();
1884+ var post_called = false;
1885+ module.lp_client.named_post = function(url, method, config) {
1886+ post_called = true;
1887+ Y.Assert.areEqual('addComment', method);
1888+ Y.Assert.areEqual(comment_text, config.parameters.comment);
1889+ config.on.success(comment_entry);
1890+ };
1891+ // The event comment_added will be fired.
1892+ var event_fired = false;
1893+ event_handler = function(e) {
1894+ event_fired = true;
1895+ Y.ObjectAssert.areEqual(comment_entry, e.details[0]);
1896+ };
1897+ this.widget.on('comment_added', event_handler);
1898+
1899+ this.widget.add_comment_handler();
1900+
1901+ Y.Assert.areEqual('', this.widget.get('comment_text'));
1902+ Y.Assert.isTrue(post_called);
1903+ Y.Assert.isTrue(event_fired);
1904+ this.assertIsUnlocked();
1905+ },
1906+
1907+ test_add_comment_handler_failure: function() {
1908+ var comment_text = 'Content';
1909+ this.widget.get('srcNode').one('textarea').set('value', comment_text);
1910+ var post_called = false;
1911+ module.lp_client.named_post = function(url, method, config) {
1912+ post_called = true;
1913+ config.on.failure();
1914+ };
1915+ this.widget.add_comment_handler();
1916+
1917+ // The content has not been cleaned.
1918+ Y.Assert.areEqual('Content', this.widget.get('comment_text'));
1919+ Y.Assert.isTrue(post_called);
1920+ this.assertIsUnlocked();
1921+ },
1922+
1923+ test_add_comment_handler_empty: function() {
1924+ // An empty comment is treated as a mistake.
1925+ var that = this;
1926+ var comment_text = '';
1927+ this.widget.get('srcNode').one('textarea').set('value', comment_text);
1928+ var comment_entry = new Comment();
1929+ var post_called = false;
1930+ module.lp_client.named_post = function(url, method, config) {
1931+ post_called = true;
1932+ };
1933+ this.widget.add_comment_handler();
1934+ Y.Assert.isFalse(post_called);
1935+ }
1936+ }));
1937+
1938+ tests.suite.add(new Y.Test.Case({
1939+ name: 'test-add-comment-widget',
1940+
1941+ setUp: function() {
1942+ Y.one("#placeholder").append(Y.Node.create(whole_table));
1943+ var first_poll = true;
1944+ pending_voc = [
1945+ {"token": "PENDING", "selected": true, "title": "Pending"},
1946+ {"token": "COMPLETED", "title": "Completed"},
1947+ {"token": "FAILED", "title": "Failed"}];
1948+ completed_voc = [
1949+ {"token": "PENDING", "title": "Pending"},
1950+ {"token": "COMPLETED", "selected": true, "title": "Completed"},
1951+ {"token": "FAILED", "title": "Failed"}];
1952+
1953+ // Monkey patch request.
1954+ module.lp_client.named_post = function(url, func, config) {
1955+ config.on.success();};
1956+ module.lp_client.named_get = function(url, func, config) {
1957+ config.on.success();};
1958+ module.lp_client.get = function(uri, config) {
1959+ if (first_poll === true) {
1960+ first_poll = false;
1961+ config.on.success(pending_voc);
1962+ }
1963+ else {
1964+ config.on.success(completed_voc);
1965+ }
1966+ };
1967+ module.poll_interval = 100;
1968+ },
1969+
1970+ tearDown: function () {
1971+ Y.one('#placeholder').empty();
1972+ },
1973+
1974+ test_request_wrong_click: function() {
1975+ // Click on the placeholder has no effect.
1976+ // The listeners are on the link with class
1977+ // '.package-diff-compute-request'.
1978+ // bug=746277.
1979+ var placeholder = Y.one('#placeholder');
1980+ placeholder
1981+ .one('#derived')
1982+ .removeClass('PENDING')
1983+ .addClass('FAILED');
1984+ module.setup_packages_diff_states(
1985+ placeholder.one('.diff-extra-container'), dsd_uri);
1986+ var func_req;
1987+ module.lp_client.named_post = function(url, func, config) {
1988+ func_req = func;
1989+ config.on.success();
1990+ };
1991+ var wrong_button = placeholder.one('.package-diff-placeholder');
1992+ wrong_button.simulate('click');
1993+ var package_diff = Y.one('#parent');
1994+
1995+ // The request has not been triggered.
1996+ Y.Assert.isTrue(package_diff.hasClass('request-derived-diff'));
1997+ },
1998+
1999+ test_request_package_diff_computation: function() {
2000+ // A click on the button changes the package diff status and requests
2001+ // the package diffs computation via post.
2002+ var placeholder = Y.one('#placeholder');
2003+ placeholder
2004+ .one('#derived')
2005 .removeClass('PENDING')
2006- .addClass('FAILED');
2007- dsd_details.setup_packages_diff_states(
2008- placeholder.one('.diff-extra-container'), dsd_uri);
2009- var func_req;
2010- dsd_details.lp_client.named_post = function(url, func, config) {
2011- func_req = func;
2012- config.on.success();
2013- };
2014-
2015- var wrong_button = placeholder.one('.package-diff-placeholder');
2016-
2017- wrong_button.simulate('click');
2018- var package_diff = Y.one('#parent');
2019-
2020- // The request has not been triggered.
2021- Y.Assert.isTrue(package_diff.hasClass('request-derived-diff'));
2022- },
2023-
2024- test_request_package_diff_computation: function() {
2025- // A click on the button changes the package diff status and requests
2026- // the package diffs computation via post.
2027- var placeholder = Y.one('#placeholder');
2028- placeholder
2029- .one('#derived')
2030- .removeClass('PENDING')
2031- .addClass('FAILED');
2032- dsd_details.setup_packages_diff_states(
2033- placeholder.one('.diff-extra-container'), dsd_uri);
2034- var func_req;
2035- dsd_details.lp_client.named_post = function(url, func, config) {
2036- func_req = func;
2037- config.on.success();
2038- };
2039- var button = placeholder.one('.package-diff-compute-request');
2040-
2041- button.simulate('click');
2042- var package_diff = Y.one('#parent');
2043-
2044- Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2045- Y.Assert.isFalse(package_diff.hasClass('request-derived-diff'));
2046- Y.Assert.areEqual('requestPackageDiffs', func_req);
2047- Y.Assert.isNotUndefined(package_diff.updater);
2048-
2049- // Let the polling happen.
2050- this.wait(function() {
2051- Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2052- this.wait(function() {
2053- Y.Assert.isTrue(package_diff.hasClass('COMPLETED'));
2054- }, dsd_details.poll_interval);
2055- }, dsd_details.poll_interval);
2056- },
2057-
2058- test_polling_for_pending_items: function() {
2059- // The polling has started on the pending package diff. The
2060- // status is being updated.
2061- var placeholder = Y.one('#placeholder');
2062- dsd_details.setup_packages_diff_states(
2063- placeholder.one('.diff-extra-container'), dsd_uri);
2064- var package_diff = Y.one('#derived');
2065- Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2066- Y.Assert.isFalse(package_diff.hasClass('request-derived-diff'));
2067- this.wait(function() {
2068- Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2069- this.wait(function() {
2070- Y.Assert.isTrue(package_diff.hasClass('COMPLETED'));
2071- }, dsd_details.poll_interval);
2072- }, dsd_details.poll_interval);
2073- }
2074-};
2075-
2076-var testFormParsing = {
2077-
2078- name: 'form-parsing',
2079-
2080- createRows: function(missing_packages) {
2081- rows_data = [
2082- ['evolution', '2.0.9-1', '2.0.8-4', missing_packages],
2083- ['package', '2.0', '1.0', missing_packages],
2084- ['package2', '4.0.4', '0.0.2', missing_packages],
2085- ['package3', '3.0.4', '0.8.2', missing_packages],
2086- ['package4', '2.0.4', '1.0.2', missing_packages],
2087- ['package5', '1.0.4', '0.2.2', missing_packages]
2088- ];
2089-
2090- var placeholder = Y.one("#placeholder")
2091- .empty();
2092-
2093- var i;
2094- for (i=0; i<rows_data.length; i++) {
2095- var data = rows_data[i];
2096- var node = Y.Node.create(
2097- createRow(data[0], data[1], data[2], data[3]));
2098- placeholder.append(node);
2099- }
2100- },
2101-
2102- checkPackage: function(package_name) {
2103- var placeholder = Y.one("#placeholder");
2104- var checkbox = placeholder.one('.' + package_name).one('input');
2105- checkbox.set('checked', true);
2106- },
2107-
2108- checkAllPackages: function() {
2109- var placeholder = Y.one("#placeholder");
2110- var checkboxes = placeholder.all('input');
2111- checkboxes.set('checked', true);
2112- },
2113-
2114- test_get_confirmation_header_number_of_packages_1: function() {
2115- this.createRows(false);
2116- this.checkPackage('evolution');
2117-
2118- Y.Assert.areEqual(
2119- 1,
2120- dsd_details.get_number_of_packages());
2121- Y.Assert.areEqual(
2122- "You're about to sync 1 package. Continue?",
2123- dsd_details.get_confirmation_header_number_of_packages().get(
2124- 'text'));
2125- },
2126-
2127- test_get_confirmation_header_number_of_packages_x: function() {
2128- this.createRows(false);
2129- this.checkPackage('evolution');
2130- this.checkPackage('package');
2131-
2132- Y.Assert.areEqual(
2133- 2,
2134- dsd_details.get_number_of_packages());
2135- Y.Assert.areEqual(
2136- "You're about to sync 2 packages. Continue?",
2137- dsd_details.get_confirmation_header_number_of_packages().get(
2138- 'text'));
2139- },
2140-
2141- test_get_packages_summary: function() {
2142- // get_packages_summary parses row from the +localpackagediffs
2143- // page to create a summary of the packages to be synced.
2144- this.createRows(false);
2145- this.checkPackage('evolution');
2146- this.checkPackage('package2');
2147-
2148- Y.Assert.areEqual(
2149- ['<ul>',
2150- '<li><b>evolution</b>: 2.0.9-1 ',
2151- '→ 2.0.8-4</li>',
2152- '<li><b>package2</b>: 4.0.4 → 0.0.2</li>',
2153- '</ul>'
2154- ].join(''),
2155- dsd_details.get_packages_summary().get('innerHTML'));
2156- },
2157-
2158- test_get_packages_summary_croped: function() {
2159- // If more than MAX_PACKAGES are to be synced, the summary is
2160- // limited to MAX_PACKAGES and mentions 'and x more packages'.
2161- this.createRows(false);
2162- this.checkAllPackages();
2163- dsd_details.MAX_PACKAGES = 1;
2164-
2165- Y.Assert.areEqual(
2166- ['<ul>',
2167- '<li><b>evolution</b>: 2.0.9-1 ',
2168- '→ 2.0.8-4</li>',
2169- '</ul>',
2170- '... and 5 more packages.'
2171- ].join(''),
2172- dsd_details.get_packages_summary().get('innerHTML'));
2173- },
2174-
2175- test_get_packages_summary_missingpackages: function() {
2176- // get_packages_summary can also parse the row from +missingpackages
2177- // with no derived_series version of the packages.
2178- this.createRows(true);
2179- Y.one('#placeholder').all('input').set('checked', true);
2180- dsd_details.MAX_PACKAGES = 1;
2181-
2182- Y.Assert.areEqual(
2183- ['<ul>',
2184- '<li><b>evolution</b>: 2.0.9-1</li>',
2185- '</ul>',
2186- '... and 5 more packages.'
2187- ].join(''),
2188- dsd_details.get_packages_summary().get('innerHTML'));
2189- }
2190-};
2191-
2192-suite.add(new Y.Test.Case(testPackageDiffUpdate));
2193-suite.add(new Y.Test.Case(testExpandableRowWidget));
2194-suite.add(new Y.Test.Case(testBlacklistWidget));
2195-suite.add(new Y.Test.Case(testAddCommentWidget));
2196-suite.add(new Y.Test.Case(testPackageDiffUpdateInteraction));
2197-suite.add(new Y.Test.Case(testFormParsing));
2198-
2199-Y.lp.testing.Runner.run(suite);
2200-
2201+ .addClass('FAILED');
2202+ module.setup_packages_diff_states(
2203+ placeholder.one('.diff-extra-container'), dsd_uri);
2204+ var func_req;
2205+ module.lp_client.named_post = function(url, func, config) {
2206+ func_req = func;
2207+ config.on.success();
2208+ };
2209+ var button = placeholder.one('.package-diff-compute-request');
2210+
2211+ button.simulate('click');
2212+ var package_diff = Y.one('#parent');
2213+
2214+ Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2215+ Y.Assert.isFalse(package_diff.hasClass('request-derived-diff'));
2216+ Y.Assert.areEqual('requestPackageDiffs', func_req);
2217+ Y.Assert.isNotUndefined(package_diff.updater);
2218+
2219+ // Let the polling happen.
2220+ this.wait(function() {
2221+ Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2222+ this.wait(function() {
2223+ Y.Assert.isTrue(package_diff.hasClass('COMPLETED'));
2224+ }, module.poll_interval);
2225+ }, module.poll_interval);
2226+ },
2227+
2228+ test_polling_for_pending_items: function() {
2229+ // The polling has started on the pending package diff. The
2230+ // status is being updated.
2231+ var placeholder = Y.one('#placeholder');
2232+ module.setup_packages_diff_states(
2233+ placeholder.one('.diff-extra-container'), dsd_uri);
2234+ var package_diff = Y.one('#derived');
2235+ Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2236+ Y.Assert.isFalse(package_diff.hasClass('request-derived-diff'));
2237+ this.wait(function() {
2238+ Y.Assert.isTrue(package_diff.hasClass('PENDING'));
2239+ this.wait(function() {
2240+ Y.Assert.isTrue(package_diff.hasClass('COMPLETED'));
2241+ }, module.poll_interval);
2242+ }, module.poll_interval);
2243+ }
2244+ }));
2245+
2246+ tests.suite.add(new Y.Test.Case({
2247+ name: 'form-parsing',
2248+ tearDown: function () {
2249+ Y.one('#placeholder').empty();
2250+ },
2251+
2252+ create_rows: function(missing_packages) {
2253+ var placeholder = Y.one("#placeholder");
2254+ rows_data = [
2255+ ['evolution', '2.0.9-1', '2.0.8-4', missing_packages],
2256+ ['package', '2.0', '1.0', missing_packages],
2257+ ['package2', '4.0.4', '0.0.2', missing_packages],
2258+ ['package3', '3.0.4', '0.8.2', missing_packages],
2259+ ['package4', '2.0.4', '1.0.2', missing_packages],
2260+ ['package5', '1.0.4', '0.2.2', missing_packages]
2261+ ];
2262+
2263+ var i;
2264+ for (i=0; i<rows_data.length; i++) {
2265+ var data = rows_data[i];
2266+ var node = Y.Node.create(
2267+ create_row(data[0], data[1], data[2], data[3]));
2268+ placeholder.append(node);
2269+ }
2270+ },
2271+
2272+ checkPackage: function(package_name) {
2273+ var placeholder = Y.one("#placeholder");
2274+ var checkbox = placeholder.one('.' + package_name).one('input');
2275+ checkbox.set('checked', true);
2276+ },
2277+
2278+ checkAllPackages: function() {
2279+ var placeholder = Y.one("#placeholder");
2280+ var checkboxes = placeholder.all('input');
2281+ checkboxes.set('checked', true);
2282+ },
2283+
2284+ test_get_confirmation_header_number_of_packages_1: function() {
2285+ this.create_rows(false);
2286+ this.checkPackage('evolution');
2287+
2288+ Y.Assert.areEqual(
2289+ 1,
2290+ module.get_number_of_packages());
2291+ Y.Assert.areEqual(
2292+ "You're about to sync 1 package. Continue?",
2293+ module.get_confirmation_header_number_of_packages().get(
2294+ 'text'));
2295+ },
2296+
2297+ test_get_confirmation_header_number_of_packages_x: function() {
2298+ this.create_rows(false);
2299+ this.checkPackage('evolution');
2300+ this.checkPackage('package');
2301+
2302+ Y.Assert.areEqual(
2303+ 2,
2304+ module.get_number_of_packages());
2305+ Y.Assert.areEqual(
2306+ "You're about to sync 2 packages. Continue?",
2307+ module.get_confirmation_header_number_of_packages().get(
2308+ 'text'));
2309+ },
2310+
2311+ test_get_packages_summary: function() {
2312+ // get_packages_summary parses row from the +localpackagediffs
2313+ // page to create a summary of the packages to be synced.
2314+ this.create_rows(false);
2315+ this.checkPackage('evolution');
2316+ this.checkPackage('package2');
2317+
2318+ Y.Assert.areEqual(
2319+ ['<ul>',
2320+ '<li><b>evolution</b>: 2.0.9-1 ',
2321+ '→ 2.0.8-4</li>',
2322+ '<li><b>package2</b>: 4.0.4 → 0.0.2</li>',
2323+ '</ul>'
2324+ ].join(''),
2325+ module.get_packages_summary().get('innerHTML'));
2326+ },
2327+
2328+ test_get_packages_summary_croped: function() {
2329+ // If more than MAX_PACKAGES are to be synced, the summary is
2330+ // limited to MAX_PACKAGES and mentions 'and x more packages'.
2331+ this.create_rows(false);
2332+ this.checkAllPackages();
2333+ module.MAX_PACKAGES = 1;
2334+
2335+ Y.Assert.areEqual(
2336+ ['<ul>',
2337+ '<li><b>evolution</b>: 2.0.9-1 ',
2338+ '→ 2.0.8-4</li>',
2339+ '</ul>',
2340+ '... and 5 more packages.'
2341+ ].join(''),
2342+ module.get_packages_summary().get('innerHTML'));
2343+ },
2344+
2345+ test_get_packages_summary_missingpackages: function() {
2346+ // get_packages_summary can also parse the row from +missingpackages
2347+ // with no derived_series version of the packages.
2348+ this.create_rows(true);
2349+ Y.one('#placeholder').all('input').set('checked', true);
2350+ module.MAX_PACKAGES = 1;
2351+
2352+ Y.Assert.areEqual(
2353+ ['<ul>',
2354+ '<li><b>evolution</b>: 2.0.9-1</li>',
2355+ '</ul>',
2356+ '... and 5 more packages.'
2357+ ].join(''),
2358+ module.get_packages_summary().get('innerHTML'));
2359+ }
2360+ }));
2361+}, '0.1', {
2362+ requires: ['test', 'lp.testing.helpers', 'lp.testing.mockio', 'console',
2363+ 'lp.registry.distroseriesdifferences_details', 'node-event-simulate',
2364+ 'lp.soyuz.base', 'lp.anim', 'lazr.formoverlay', 'lazr.effects',
2365+ 'lp.soyuz.dynamic_dom_updater', 'event-simulate', 'io-base']
2366 });
2367
2368=== modified file 'lib/lp/registry/javascript/tests/test_team.js'
2369--- lib/lp/registry/javascript/tests/test_team.js 2012-04-06 17:28:25 +0000
2370+++ lib/lp/registry/javascript/tests/test_team.js 2012-07-05 17:22:27 +0000
2371@@ -50,7 +50,7 @@
2372 visibility_changed_called = true;
2373 };
2374 Y.Assert.isFalse(visibility_changed_called);
2375- var visibility_field = Y.one('[name=field.visibility]');
2376+ var visibility_field = Y.one('[name="field.visibility"]');
2377 visibility_field.set('value', 'PRIVATE');
2378 visibility_field.simulate('change');
2379 Y.Assert.isTrue(visibility_changed_called);
2380@@ -63,7 +63,7 @@
2381 test_visibility_change_private: function() {
2382 namespace.visibility_changed('PRIVATE');
2383 var nr_radio_buttons = 0;
2384- Y.all('input[type=radio]').each(function(radio_button) {
2385+ Y.all('input[type="radio"]').each(function(radio_button) {
2386 if (radio_button.ancestor('tr').hasClass('unseen')
2387 || !radio_button.get('checked')) {
2388 return;
2389@@ -77,7 +77,7 @@
2390 nr_radio_buttons++;
2391 });
2392 Y.Assert.isTrue(nr_radio_buttons === 1);
2393- var extra_help = Y.one('[for=field.subscriptionpolicy]')
2394+ var extra_help = Y.one('[for="field.subscriptionpolicy"]')
2395 .ancestor('div').one('.info');
2396 Y.Assert.areEqual(
2397 'Private teams must have a restricted subscription '+
2398@@ -94,7 +94,7 @@
2399 // are visible again.
2400 test_visibility_change_public: function() {
2401 namespace.visibility_changed('PRIVATE');
2402- var extra_help = Y.one('[for=field.subscriptionpolicy]')
2403+ var extra_help = Y.one('[for="field.subscriptionpolicy"]')
2404 .ancestor('div').one('.info');
2405 Y.Assert.areEqual(
2406 'Private teams must have a restricted subscription '+
2407@@ -103,7 +103,7 @@
2408
2409 namespace.visibility_changed('PUBLIC');
2410 var nr_radio_buttons = 0;
2411- Y.all('input[type=radio]').each(function(radio_button) {
2412+ Y.all('input[type="radio"]').each(function(radio_button) {
2413 Y.Assert.isFalse(
2414 radio_button.ancestor('tr').hasClass('unseen'));
2415 var help_row = radio_button.ancestor('tr')
2416@@ -114,7 +114,7 @@
2417 nr_radio_buttons++;
2418 });
2419 Y.Assert.isTrue(nr_radio_buttons === 4);
2420- extra_help = Y.one('[for=field.subscriptionpolicy]')
2421+ extra_help = Y.one('[for="field.subscriptionpolicy"]')
2422 .ancestor('div').one('.info');
2423 Y.Assert.isNull(extra_help);
2424 var extra_visibility_help = Y.one('#visibility-extra-help');
2425@@ -124,7 +124,7 @@
2426 // When the subscription policy changes to private and back to public,
2427 // any original extra help text that was there is restored.
2428 test_visibility_change_public_restores_extra_help: function() {
2429- var widget = Y.one('[for=field.subscriptionpolicy]')
2430+ var widget = Y.one('[for="field.subscriptionpolicy"]')
2431 .ancestor('div').one('.radio-button-widget');
2432 var extra_help = Y.Node.create('<div>Help Me</div>')
2433 .addClass('sprite')
2434@@ -132,7 +132,7 @@
2435 widget.insert(extra_help, 'before');
2436
2437 namespace.visibility_changed('PRIVATE');
2438- extra_help = Y.one('[for=field.subscriptionpolicy]')
2439+ extra_help = Y.one('[for="field.subscriptionpolicy"]')
2440 .ancestor('div').one('.info');
2441 Y.Assert.areEqual(
2442 'Private teams must have a restricted subscription '+
2443@@ -140,7 +140,7 @@
2444 extra_help.get('text'));
2445
2446 namespace.visibility_changed('PUBLIC');
2447- extra_help = Y.one('[for=field.subscriptionpolicy]')
2448+ extra_help = Y.one('[for="field.subscriptionpolicy"]')
2449 .ancestor('div').one('.info');
2450 Y.Assert.areEqual('Help Me', extra_help.get('text'));
2451 }
2452
2453=== modified file 'lib/lp/registry/javascript/tests/test_team_mailinglists.html'
2454--- lib/lp/registry/javascript/tests/test_team_mailinglists.html 2012-03-14 04:41:36 +0000
2455+++ lib/lp/registry/javascript/tests/test_team_mailinglists.html 2012-07-05 17:22:27 +0000
2456@@ -41,7 +41,7 @@
2457 <body class="yui3-skin-sam">
2458 <ul id="suites">
2459 <!-- <li>lp.large_indicator.test</li> -->
2460- <li>lp.team_mailinglists.test</li>
2461+ <li>lp.registry.team.mailinglists.test</li>
2462 </ul>
2463
2464 <!-- The example markup required by the script to run -->
2465
2466=== modified file 'lib/lp/registry/javascript/tests/test_team_mailinglists.js'
2467--- lib/lp/registry/javascript/tests/test_team_mailinglists.js 2012-02-03 16:28:14 +0000
2468+++ lib/lp/registry/javascript/tests/test_team_mailinglists.js 2012-07-05 17:22:27 +0000
2469@@ -1,94 +1,76 @@
2470-/* Copyright (c) 2012, Canonical Ltd. All rights reserved. */
2471-YUI({
2472- base: '../../../../canonical/launchpad/icing/yui/',
2473- filter: 'raw',
2474- combine: false,
2475- fetchCSS: false
2476-}).use('event', 'lp.mustache', 'node', 'node-event-simulate', 'test',
2477- 'widget-stack', 'console', 'lp.registry.team.mailinglists',
2478- function(Y) {
2479-
2480-// Local aliases
2481-var Assert = Y.Assert,
2482- ArrayAssert = Y.ArrayAssert;
2483-var team_mailinglists = Y.lp.registry.team.mailinglists;
2484-var suite = new Y.Test.Suite("team.mailinglists Tests");
2485-
2486-suite.add(new Y.Test.Case({
2487-
2488- name: 'Team Mailinglists',
2489-
2490- setUp: function() {
2491- window.LP = {
2492- links: {},
2493- cache: {}
2494- };
2495- },
2496-
2497- tearDown: function() {
2498- },
2499-
2500- test_render_message: function () {
2501- var config = {
2502- messages: [
2503- {
2504- 'message_id': 3,
2505- 'headers': {
2506- 'Subject': 'Please stop breaking things',
2507- 'To': 'the_list@example.hu',
2508- 'From': 'someone@else.com',
2509- 'Date': '2011-10-13'
2510- },
2511- 'nested_messages': [],
2512- 'attachments': []
2513- }
2514- ],
2515- container: Y.one('#messagelist'),
2516- forwards_navigation: Y.all('.last,.next'),
2517- backwards_navigation: Y.all('.first,.previous')
2518- };
2519- var message_list = new Y.lp.registry.team.mailinglists.MessageList(
2520- config);
2521- message_list.display_messages();
2522- var message = Y.one("#message-3");
2523- Assert.areEqual(message.get('text'), 'Please stop breaking things');
2524- },
2525-
2526- test_nav: function () {
2527- var config = {
2528- messages: [],
2529- container: Y.one('#messagelist'),
2530- forwards_navigation: Y.all('.last,.next'),
2531- backwards_navigation: Y.all('.first,.previous')
2532- };
2533- var message_list = new Y.lp.registry.team.mailinglists.MessageList(
2534- config);
2535-
2536- var fired = false;
2537- Y.on('messageList:backwards', function () {
2538- fired = true;
2539- });
2540-
2541- var nav_link = Y.one('.first');
2542- nav_link.simulate('click');
2543- Assert.isTrue(fired);
2544- }
2545-}));
2546-
2547-
2548-var handle_complete = function(data) {
2549- window.status = '::::' + JSON.stringify(data);
2550- };
2551-Y.Test.Runner.on('complete', handle_complete);
2552-Y.Test.Runner.add(suite);
2553-
2554-var yconsole = new Y.Console({
2555- newestOnTop: false
2556-});
2557-yconsole.render('#log');
2558-
2559-Y.on('domready', function() {
2560- Y.Test.Runner.run();
2561-});
2562-
2563+/* Copyright (c) 2012 Canonical Ltd. All rights reserved. */
2564+
2565+YUI.add('lp.registry.team.mailinglists.test', function (Y) {
2566+ // Local aliases.
2567+ var Assert = Y.Assert,
2568+ ArrayAssert = Y.ArrayAssert;
2569+ var team_mailinglists = Y.lp.registry.team.mailinglists;
2570+
2571+ var tests = Y.namespace('lp.registry.team.mailinglists.test');
2572+ tests.suite = new Y.Test.Suite('lp.registry.team.mailinglists Tests');
2573+ tests.suite.add(new Y.Test.Case({
2574+
2575+ name: 'Team Mailinglists',
2576+
2577+ setUp: function() {
2578+ window.LP = {
2579+ links: {},
2580+ cache: {}
2581+ };
2582+ },
2583+
2584+ tearDown: function() {
2585+ },
2586+
2587+ test_render_message: function () {
2588+ var config = {
2589+ messages: [
2590+ {
2591+ 'message_id': 3,
2592+ 'headers': {
2593+ 'Subject': 'Please stop breaking things',
2594+ 'To': 'the_list@example.hu',
2595+ 'From': 'someone@else.com',
2596+ 'Date': '2011-10-13'
2597+ },
2598+ 'nested_messages': [],
2599+ 'attachments': []
2600+ }
2601+ ],
2602+ container: Y.one('#messagelist'),
2603+ forwards_navigation: Y.all('.last,.next'),
2604+ backwards_navigation: Y.all('.first,.previous')
2605+ };
2606+ var message_list = new Y.lp.registry.team.mailinglists.MessageList(
2607+ config);
2608+ message_list.display_messages();
2609+ var message = Y.one("#message-3");
2610+ Assert.areEqual(message.get('text'), 'Please stop breaking things');
2611+ },
2612+
2613+ test_nav: function () {
2614+ var config = {
2615+ messages: [],
2616+ container: Y.one('#messagelist'),
2617+ forwards_navigation: Y.all('.last,.next'),
2618+ backwards_navigation: Y.all('.first,.previous')
2619+ };
2620+ var message_list = new Y.lp.registry.team.mailinglists.MessageList(
2621+ config);
2622+
2623+ var fired = false;
2624+ Y.on('messageList:backwards', function () {
2625+ fired = true;
2626+ });
2627+
2628+ var nav_link = Y.one('.first');
2629+ nav_link.simulate('click');
2630+ Assert.isTrue(fired);
2631+ }
2632+ }));
2633+
2634+}, '0.1', {
2635+ requires: ['test', 'lp.testing.helpers', 'console',
2636+ 'lp.registry.team.mailinglists', 'lp.mustache',
2637+ 'node-event-simulate', 'widget-stack', 'event']
2638 });