← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~benji/launchpad/add-edit-tests into lp:launchpad/db-devel

 

Benji York has proposed merging lp:~benji/launchpad/add-edit-tests into lp:launchpad/db-devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~benji/launchpad/add-edit-tests/+merge/56806

This branch adds workflow tests for adding bug notification
subscriptions, editing them, and unsubscribing from them.  The intent is
to test the basic workflow in each scenario as well as provide a good
framework for more tests in the future.

The tests can be run by loading
lib/lp/registry/javascript/tests/test_structural_subscription.html in a
browser.

There is not lint reported for the added/changed lines but there is
quite a bit for the pre-existing lines.  Fixes for those are in a
forthcoming branch in order to keep this branch sane.
-- 
https://code.launchpad.net/~benji/launchpad/add-edit-tests/+merge/56806
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~benji/launchpad/add-edit-tests into lp:launchpad/db-devel.
=== modified file 'lib/lp/registry/javascript/structural-subscription.js'
--- lib/lp/registry/javascript/structural-subscription.js	2011-04-06 16:59:46 +0000
+++ lib/lp/registry/javascript/structural-subscription.js	2011-04-07 17:06:53 +0000
@@ -1046,6 +1046,17 @@
     };
 }
 
+// If set, this will be used instead of Y.io.  This is for testing.
+namespace._Y_io_hook = null;
+
+function do_io(link, config) {
+    var yio = Y.io;
+    if (namespace._Y_io_hook) {
+        yio = namespace._Y_io_hook;
+    }
+    yio(link, config);
+}
+
 /**
  * Construct a handler for an unsubscribe link.
  */
@@ -1073,11 +1084,20 @@
                         collapse_node(subscriber, { remove_on_end: true });
                         LP.cache.subscription_info[subscriber_id].filters = [];
                     }
+<<<<<<< TREE
                 },
                 failure: error_handler.getFailureHandler()
             }
         };
         Y.io(filter.self_link, y_config);
+=======
+                    collapse_node(to_collapse);
+                    },
+                 failure: error_handler.getFailureHandler()
+                }
+            };
+        do_io(filter.self_link, y_config);
+>>>>>>> MERGE-SOURCE
     };
 }
 
@@ -1172,7 +1192,7 @@
         label.setStyle('display', null);
         description.setStyle('color', '#bbb');
     } else {
-        control.set('text', 'Do not receive emails from this subscription');
+        control.set('text', 'Stop your emails from this subscription');
         control.replaceClass('yes', 'no');
         label.setStyle('display', 'none');
         description.setStyle('color', null);

=== modified file 'lib/lp/registry/javascript/tests/test_structural_subscription.js'
--- lib/lp/registry/javascript/tests/test_structural_subscription.js	2011-04-06 16:48:21 +0000
+++ lib/lp/registry/javascript/tests/test_structural_subscription.js	2011-04-07 17:06:53 +0000
@@ -5,7 +5,7 @@
     filter: 'raw',
     combine: false,
     fetchCSS: false
-    }).use('test', 'console', 'node', 'lp.client',
+    }).use('test', 'console', 'node', 'node-event-simulate', 'lp.client',
         'lp.registry.structural_subscription', function(Y) {
 
     var suite = new Y.Test.Suite("Structural subscription overlay tests");
@@ -45,7 +45,7 @@
                 '<div id="test-content">' +
                 '  <div id="' + content_box_name + '"></div>' +
                 (include_listing
-                 ? ('  <div id="' + subscription_listing_name + '"></div>')
+                 ? ('  <div id="' + subscription_listing_name + '" style="width: 50%"></div>')
                  : '') +
                 '</div>');
     }
@@ -874,7 +874,7 @@
                     }
                     ]
                 }
-                ]
+                ];
         },
 
         tearDown: function() {
@@ -960,6 +960,248 @@
 
     }));
 
+    suite.add(new Y.Test.Case({
+        name: 'Structural Subscription: add subcription workflow',
+
+        _should: {error: {}},
+
+        setUp: function() {
+            var TestBugFilter = function() {};
+            TestBugFilter.prototype = {
+                'getAttrs': function () {
+                    return {};
+                }
+            };
+            // We need an lp_client that will appear to succesfully create the
+            // bug filter.
+            var TestClient = function() {};
+            TestClient.prototype = {
+                named_post: function (uri, operation_name, config) {
+                    config.on.success(new TestBugFilter());
+                    this.post_called = true;
+                },
+                patch: function(uri, representation, config, headers) {
+                    config.on.success();
+                    this.patch_called = true;
+                },
+                post_called: false,
+                patch_called: false
+            };
+
+            this.original_lp = monkeypatch_LP();
+
+            this.configuration = {
+                content_box: content_box_id,
+                lp_client: new TestClient()
+            };
+            this.content_node = create_test_node();
+            Y.one('body').appendChild(this.content_node);
+        },
+
+        tearDown: function() {
+            window.LP = this.original_lp;
+            remove_test_node();
+            delete this.content_node;
+        },
+
+        test_simple_add_workflow: function() {
+            // Clicking on the "Subscribe to bug mail" link and then clicking
+            // on the overlay form's "OK" button results in a filter being
+            // created and PATCHed.
+            module.setup(this.configuration);
+            Y.one('a.menu-link-subscribe_to_bug_mail').simulate('click');
+            Assert.isFalse(module.lp_client.post_called);
+            Assert.isFalse(module.lp_client.patch_called);
+            var button = Y.one('.yui3-lazr-formoverlay-actions button');
+            Assert.areEqual(button.get('text'), 'OK');
+            button.simulate('click');
+            Assert.isTrue(module.lp_client.post_called);
+            Assert.isTrue(module.lp_client.patch_called);
+        },
+
+        test_simple_add_workflow_cancled: function() {
+            // Clicking on the "Subscribe to bug mail" link and then clicking
+            // on the overlay form's cancel button results in no filter being
+            // created or PATCHed.
+            module.setup(this.configuration);
+            Y.one('a.menu-link-subscribe_to_bug_mail').simulate('click');
+            Assert.isFalse(module.lp_client.post_called);
+            Assert.isFalse(module.lp_client.patch_called);
+            var button = Y.one(
+                '.yui3-lazr-formoverlay-actions button+button');
+            Assert.areEqual(button.get('text'), 'Cancel');
+            button.simulate('click');
+            Assert.isFalse(module.lp_client.post_called);
+            Assert.isFalse(module.lp_client.patch_called);
+        }
+
+    }));
+
+    suite.add(new Y.Test.Case({
+        name: 'Structural Subscription: edit subcription workflow',
+
+        _should: {error: {}},
+
+        setUp: function() {
+            var TestBugFilter = function(data) {
+                if (data !== undefined) {
+                    this._data = data;
+                } else {
+                    this._data = {};
+                }
+            };
+            TestBugFilter.prototype = {
+                'getAttrs': function () {
+                    return this._data;
+                }
+            };
+            // We need an lp_client that will appear to succesfully create the
+            // bug filter.
+            var TestClient = function() {
+                this.post_called = false;
+                this.patch_called = false;
+            };
+            TestClient.prototype = {
+                named_post: function (uri, operation_name, config) {
+                    config.on.success(new TestBugFilter());
+                    this.post_called = true;
+                },
+                patch: function(uri, representation, config, headers) {
+                    config.on.success(new TestBugFilter(representation));
+                    this.patch_called = true;
+                }
+            };
+
+            this.original_lp = monkeypatch_LP();
+
+            LP.cache.subscription_info = [{
+                target_url: 'http://example.com',
+                target_title:'Example project',
+                filters: [{
+                    filter: {
+                        description: 'DESCRIPTION',
+                        statuses: [],
+                        importances: [],
+                        tags: [],
+                        find_all_tags: true,
+                        bug_notification_level: 'Discussion',
+                        self_link: 'http://example.com/a_filter'
+                        },
+                    can_mute: true,
+                    is_muted: false,
+                    subscriber_is_team: false,
+                    subscriber_url: 'http://example.com/subscriber',
+                    subscriber_title: 'Thidwick',
+                    user_is_team_admin: false
+                }]
+            }];
+
+
+            this.configuration = {
+                content_box: content_box_id,
+                lp_client: new TestClient()
+            };
+            this.content_node = create_test_node(true);
+            Y.one('body').appendChild(this.content_node);
+        },
+
+        tearDown: function() {
+            window.LP = this.original_lp;
+            remove_test_node();
+            delete this.content_node;
+        },
+
+        test_simple_edit_workflow: function() {
+            module.setup_bug_subscriptions(this.configuration);
+
+            // Editing a value via the edit link and dialog causes the
+            // subscription list to reflect the new value.
+            var label = Y.one('.filter-name span').get('text');
+            Assert.isTrue(label.indexOf('DESCRIPTION') !== -1);
+
+            // No PATCHing has happened yet.
+            Assert.isFalse(module.lp_client.patch_called);
+
+            // Click the edit link.
+            Y.one('a.edit-subscription').simulate('click');
+
+            // Set a new name (description) and click OK.
+            Y.one('input[name="name"]').set('value', 'NEW VALUE');
+            var button = Y.one('.yui3-lazr-formoverlay-actions button');
+            Assert.areEqual(button.get('text'), 'OK');
+            button.simulate('click');
+
+            // Clicking OK resulted in the bug filter being PATCHed.
+            Assert.isTrue(module.lp_client.patch_called);
+            // And the new value is reflected in the subscription listing.
+            label = Y.one('.filter-name span').get('text');
+            Assert.isTrue(label.indexOf('NEW VALUE') !== -1);
+        }
+
+    }));
+
+    suite.add(new Y.Test.Case({
+        name: 'Structural Subscription: unsubscribing',
+
+        _should: {error: {}},
+
+        setUp: function() {
+            var TestClient = function() {};
+            this.original_lp = monkeypatch_LP();
+
+            LP.cache.subscription_info = [{
+                target_url: 'http://example.com',
+                target_title:'Example project',
+                filters: [{
+                    filter: {
+                        description: 'DESCRIPTION',
+                        statuses: [],
+                        importances: [],
+                        tags: [],
+                        find_all_tags: true,
+                        bug_notification_level: 'Discussion',
+                        self_link: 'http://example.com/a_filter'
+                        },
+                    can_mute: true,
+                    is_muted: false,
+                    subscriber_is_team: false,
+                    subscriber_url: 'http://example.com/subscriber',
+                    subscriber_title: 'Thidwick',
+                    user_is_team_admin: false
+                }]
+            }];
+
+            this.configuration = {
+                content_box: content_box_id,
+                lp_client: new TestClient()
+            };
+            this.content_node = create_test_node(true);
+            Y.one('body').appendChild(this.content_node);
+        },
+
+        tearDown: function() {
+            window.LP = this.original_lp;
+            remove_test_node();
+            delete this.content_node;
+        },
+
+        test_simple_unsubscribe: function() {
+            // Clicking on the unsubscribe link will result in a DELETE being
+            // sent and the filter description being removed.
+
+            var DELETE_performed = false;
+            // Fake a DELETE that succeeds.
+            module._Y_io_hook = function (link, config) {
+                DELETE_performed = true;
+                config.on.success();
+            };
+
+            module.setup_bug_subscriptions(this.configuration);
+            Y.one('a.delete-subscription').simulate('click');
+            Assert.isTrue(DELETE_performed);
+        }
+
+    }));
     // Lock, stock, and two smoking barrels.
     var handle_complete = function(data) {
         var status_node = Y.Node.create(