← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Benji York has proposed merging lp:~benji/launchpad/ss-test-refactorings into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~benji/launchpad/ss-test-refactorings/+merge/56826

Move some structural subscription test refactorings that have been applied to db-devel that we want on devel.
-- 
https://code.launchpad.net/~benji/launchpad/ss-test-refactorings/+merge/56826
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~benji/launchpad/ss-test-refactorings into lp:launchpad.
=== 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 18:54:12 +0000
@@ -22,6 +22,10 @@
     var content_box_name = 'ss-content-box';
     var content_box_id = '#' + content_box_name;
 
+    // Listing node.
+    var subscription_listing_name = 'subscription-listing';
+    var subscription_listing_id = '#' + subscription_listing_name;
+
     var target_link_class = '.menu-link-subscribe_to_bug_mail';
 
     function array_compare(a,b) {
@@ -36,10 +40,13 @@
         return true;
     }
 
-    function create_test_node() {
+    function create_test_node(include_listing) {
         return Y.Node.create(
                 '<div id="test-content">' +
                 '  <div id="' + content_box_name + '"></div>' +
+                (include_listing
+                 ? ('  <div id="' + subscription_listing_name + '"></div>')
+                 : '') +
                 '</div>');
     }
 
@@ -58,6 +65,61 @@
         return true;
     }
 
+    function monkeypatch_LP() {
+          // Monkeypatch LP to avoid network traffic and to allow
+          // insertion of test data.
+          var original_lp = window.LP
+          window.LP = {
+            links: {},
+            cache: {}
+          };
+
+          LP.cache.context = {
+            title: 'Test Project',
+            self_link: 'https://launchpad.dev/api/test_project'
+          };
+          LP.cache.administratedTeams = [];
+          LP.cache.importances = ['Unknown', 'Critical', 'High', 'Medium',
+                                  'Low', 'Wishlist', 'Undecided'];
+          LP.cache.statuses = ['New', 'Incomplete', 'Opinion',
+                               'Invalid', 'Won\'t Fix', 'Expired',
+                               'Confirmed', 'Triaged', 'In Progress',
+                               'Fix Committed', 'Fix Released', 'Unknown'];
+          LP.links.me = 'https://launchpad.dev/api/~someone';
+          return original_lp;
+    }
+
+    function LPClient(){
+        if (!(this instanceof arguments.callee))
+            throw new Error("Constructor called as a function");
+        this.received = []
+        // We create new functions every time because we allow them to be
+        // configured.
+        this.named_post = function(url, func, config) {
+            this._call('named_post', config, arguments);
+        };
+        this.patch = function(bug_filter, data, config) {
+            this._call('patch', config, arguments);
+        }
+    };
+    LPClient.prototype._call = function(name, config, args) {
+        this.received.push(
+            [name, Array.prototype.slice.call(args)]);
+        if (!Y.Lang.isValue(args.callee.args))
+            throw new Error("Set call_args on "+name);
+        if (Y.Lang.isValue(args.callee.fail) && args.callee.fail) {
+            config.on.failure.apply(undefined, args.callee.args);
+        } else {
+            config.on.success.apply(undefined, args.callee.args);
+        }
+    };
+    // DELETE uses Y.io directly as of this writing, so we cannot stub it
+    // here.
+
+    function make_lp_client_stub() {
+        return new LPClient();
+    }
+
     test_case = new Y.Test.Case({
         name: 'structural_subscription_overlay',
 
@@ -224,6 +286,7 @@
             Assert.areEqual(
                 LP.links.me,
                 context.config.parameters.subscriber);
+            module._show_add_overlay(this.configuration);
         },
 
         test_team_recipient: function() {
@@ -481,28 +544,11 @@
         setUp: function() {
           // Monkeypatch LP to avoid network traffic and to allow
           // insertion of test data.
-          window.LP = {
-            links: {},
-            cache: {}
-          };
-
-          LP.cache.context = {
-            title: 'Test Project',
-            self_link: 'https://launchpad.dev/api/test_project'
-          };
-          LP.cache.administratedTeams = [];
-          LP.cache.importances = ['Unknown', 'Critical', 'High', 'Medium',
-                                  'Low', 'Wishlist', 'Undecided'];
-          LP.cache.statuses = ['New', 'Incomplete', 'Opinion',
-                               'Invalid', 'Won\'t Fix', 'Expired',
-                               'Confirmed', 'Triaged', 'In Progress',
-                               'Fix Committed', 'Fix Released', 'Unknown'];
-          LP.links.me = 'https://launchpad.dev/api/~someone';
-
-          var lp_client = function() {};
+          this.original_lp = monkeypatch_LP();
+
           this.configuration = {
               content_box: content_box_id,
-              lp_client: lp_client
+              lp_client: make_lp_client_stub()
           };
 
           this.content_node = create_test_node();
@@ -510,19 +556,19 @@
         },
 
         tearDown: function() {
-          remove_test_node();
-          delete this.content_node;
+            window.LP = this.original_lp;
+            remove_test_node();
+            delete this.content_node;
         },
 
         test_overlay_error_handling_adding: function() {
             // Verify that errors generated during adding of a filter are
             // displayed to the user.
-            this.configuration.lp_client.named_post =
-                function(url, func, config) {
-                config.on.failure(true, true);
-                };
+            this.configuration.lp_client.named_post.fail = true;
+            this.configuration.lp_client.named_post.args = [true, true];
             module.setup(this.configuration);
             module._show_add_overlay(this.configuration);
+            module._show_add_overlay(this.configuration);
             // After the setup the overlay should be in the DOM.
             overlay = Y.one('#accordion-overlay');
             Assert.isNotNull(overlay);
@@ -540,19 +586,13 @@
             // displayed to the user.
             var original_delete_filter = module._delete_filter;
             module._delete_filter = function() {};
-            this.configuration.lp_client.patch =
-                function(bug_filter, data, config) {
-                    config.on.failure(true, true);
-                };
-            var bug_filter = {
-                'getAttrs': function() { return {}; }
-            };
-            this.configuration.lp_client.named_post =
-                function(url, func, config) {
-                    config.on.success(bug_filter);
-                };
+            this.configuration.lp_client.patch.fail = true;
+            this.configuration.lp_client.patch.args = [true, true];
+            this.configuration.lp_client.named_post.args = [
+                {'getAttrs': function() { return {}; }}];
             module.setup(this.configuration);
             module._show_add_overlay(this.configuration);
+            module._show_add_overlay(this.configuration);
             // After the setup the overlay should be in the DOM.
             overlay = Y.one('#accordion-overlay');
             Assert.isNotNull(overlay);