Merge lp:~benji/launchpad/ss-test-refactorings into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Gary Poster
Approved revision: no longer in the source branch.
Merged at revision: 12774
Proposed branch: lp:~benji/launchpad/ss-test-refactorings
Merge into: lp:launchpad
Diff against target: 168 lines (+75/-38)
1 file modified
lib/lp/registry/javascript/tests/test_structural_subscription.js (+75/-38)
To merge this branch: bzr merge lp:~benji/launchpad/ss-test-refactorings
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+56826@code.launchpad.net

Commit message

[r=gary][no-qa] Move some structural subscription test refactorings that have been applied to db-devel that we want on devel.

Description of the change

Move some structural subscription test refactorings that have been applied to db-devel that we want on devel.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

On IRC I pointed out 2 or 3 instances of "module._show_add_overlay(this.configuration);" that we didn't want. Otherwise, yay and thank you.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/registry/javascript/tests/test_structural_subscription.js'
--- lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-07 14:14:03 +0000
+++ lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-07 19:07:27 +0000
@@ -22,6 +22,10 @@
22 var content_box_name = 'ss-content-box';22 var content_box_name = 'ss-content-box';
23 var content_box_id = '#' + content_box_name;23 var content_box_id = '#' + content_box_name;
2424
25 // Listing node.
26 var subscription_listing_name = 'subscription-listing';
27 var subscription_listing_id = '#' + subscription_listing_name;
28
25 var target_link_class = '.menu-link-subscribe_to_bug_mail';29 var target_link_class = '.menu-link-subscribe_to_bug_mail';
2630
27 function array_compare(a,b) {31 function array_compare(a,b) {
@@ -36,10 +40,13 @@
36 return true;40 return true;
37 }41 }
3842
39 function create_test_node() {43 function create_test_node(include_listing) {
40 return Y.Node.create(44 return Y.Node.create(
41 '<div id="test-content">' +45 '<div id="test-content">' +
42 ' <div id="' + content_box_name + '"></div>' +46 ' <div id="' + content_box_name + '"></div>' +
47 (include_listing
48 ? (' <div id="' + subscription_listing_name + '"></div>')
49 : '') +
43 '</div>');50 '</div>');
44 }51 }
4552
@@ -58,6 +65,61 @@
58 return true;65 return true;
59 }66 }
6067
68 function monkeypatch_LP() {
69 // Monkeypatch LP to avoid network traffic and to allow
70 // insertion of test data.
71 var original_lp = window.LP
72 window.LP = {
73 links: {},
74 cache: {}
75 };
76
77 LP.cache.context = {
78 title: 'Test Project',
79 self_link: 'https://launchpad.dev/api/test_project'
80 };
81 LP.cache.administratedTeams = [];
82 LP.cache.importances = ['Unknown', 'Critical', 'High', 'Medium',
83 'Low', 'Wishlist', 'Undecided'];
84 LP.cache.statuses = ['New', 'Incomplete', 'Opinion',
85 'Invalid', 'Won\'t Fix', 'Expired',
86 'Confirmed', 'Triaged', 'In Progress',
87 'Fix Committed', 'Fix Released', 'Unknown'];
88 LP.links.me = 'https://launchpad.dev/api/~someone';
89 return original_lp;
90 }
91
92 function LPClient(){
93 if (!(this instanceof arguments.callee))
94 throw new Error("Constructor called as a function");
95 this.received = []
96 // We create new functions every time because we allow them to be
97 // configured.
98 this.named_post = function(url, func, config) {
99 this._call('named_post', config, arguments);
100 };
101 this.patch = function(bug_filter, data, config) {
102 this._call('patch', config, arguments);
103 }
104 };
105 LPClient.prototype._call = function(name, config, args) {
106 this.received.push(
107 [name, Array.prototype.slice.call(args)]);
108 if (!Y.Lang.isValue(args.callee.args))
109 throw new Error("Set call_args on "+name);
110 if (Y.Lang.isValue(args.callee.fail) && args.callee.fail) {
111 config.on.failure.apply(undefined, args.callee.args);
112 } else {
113 config.on.success.apply(undefined, args.callee.args);
114 }
115 };
116 // DELETE uses Y.io directly as of this writing, so we cannot stub it
117 // here.
118
119 function make_lp_client_stub() {
120 return new LPClient();
121 }
122
61 test_case = new Y.Test.Case({123 test_case = new Y.Test.Case({
62 name: 'structural_subscription_overlay',124 name: 'structural_subscription_overlay',
63125
@@ -481,28 +543,11 @@
481 setUp: function() {543 setUp: function() {
482 // Monkeypatch LP to avoid network traffic and to allow544 // Monkeypatch LP to avoid network traffic and to allow
483 // insertion of test data.545 // insertion of test data.
484 window.LP = {546 this.original_lp = monkeypatch_LP();
485 links: {},547
486 cache: {}
487 };
488
489 LP.cache.context = {
490 title: 'Test Project',
491 self_link: 'https://launchpad.dev/api/test_project'
492 };
493 LP.cache.administratedTeams = [];
494 LP.cache.importances = ['Unknown', 'Critical', 'High', 'Medium',
495 'Low', 'Wishlist', 'Undecided'];
496 LP.cache.statuses = ['New', 'Incomplete', 'Opinion',
497 'Invalid', 'Won\'t Fix', 'Expired',
498 'Confirmed', 'Triaged', 'In Progress',
499 'Fix Committed', 'Fix Released', 'Unknown'];
500 LP.links.me = 'https://launchpad.dev/api/~someone';
501
502 var lp_client = function() {};
503 this.configuration = {548 this.configuration = {
504 content_box: content_box_id,549 content_box: content_box_id,
505 lp_client: lp_client550 lp_client: make_lp_client_stub()
506 };551 };
507552
508 this.content_node = create_test_node();553 this.content_node = create_test_node();
@@ -510,17 +555,16 @@
510 },555 },
511556
512 tearDown: function() {557 tearDown: function() {
513 remove_test_node();558 window.LP = this.original_lp;
514 delete this.content_node;559 remove_test_node();
560 delete this.content_node;
515 },561 },
516562
517 test_overlay_error_handling_adding: function() {563 test_overlay_error_handling_adding: function() {
518 // Verify that errors generated during adding of a filter are564 // Verify that errors generated during adding of a filter are
519 // displayed to the user.565 // displayed to the user.
520 this.configuration.lp_client.named_post =566 this.configuration.lp_client.named_post.fail = true;
521 function(url, func, config) {567 this.configuration.lp_client.named_post.args = [true, true];
522 config.on.failure(true, true);
523 };
524 module.setup(this.configuration);568 module.setup(this.configuration);
525 module._show_add_overlay(this.configuration);569 module._show_add_overlay(this.configuration);
526 // After the setup the overlay should be in the DOM.570 // After the setup the overlay should be in the DOM.
@@ -540,17 +584,10 @@
540 // displayed to the user.584 // displayed to the user.
541 var original_delete_filter = module._delete_filter;585 var original_delete_filter = module._delete_filter;
542 module._delete_filter = function() {};586 module._delete_filter = function() {};
543 this.configuration.lp_client.patch =587 this.configuration.lp_client.patch.fail = true;
544 function(bug_filter, data, config) {588 this.configuration.lp_client.patch.args = [true, true];
545 config.on.failure(true, true);589 this.configuration.lp_client.named_post.args = [
546 };590 {'getAttrs': function() { return {}; }}];
547 var bug_filter = {
548 'getAttrs': function() { return {}; }
549 };
550 this.configuration.lp_client.named_post =
551 function(url, func, config) {
552 config.on.success(bug_filter);
553 };
554 module.setup(this.configuration);591 module.setup(this.configuration);
555 module._show_add_overlay(this.configuration);592 module._show_add_overlay(this.configuration);
556 // After the setup the overlay should be in the DOM.593 // After the setup the overlay should be in the DOM.