Merge lp:~benji/launchpad/add-edit-tests-2 into lp:launchpad

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: no longer in the source branch.
Merged at revision: 12781
Proposed branch: lp:~benji/launchpad/add-edit-tests-2
Merge into: lp:launchpad
Prerequisite: lp:~benji/launchpad/ss-test-refactorings
Diff against target: 320 lines (+269/-9)
2 files modified
lib/lp/registry/javascript/structural-subscription.js (+12/-1)
lib/lp/registry/javascript/tests/test_structural_subscription.js (+257/-8)
To merge this branch: bzr merge lp:~benji/launchpad/add-edit-tests-2
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+56832@code.launchpad.net

Commit message

[r=jcsackett][no-qa] add tests for structural subscriptions subscribe/edit/unsubscribe workflow

Description of the change

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.

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

Looks good to me.

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/structural-subscription.js'
2--- lib/lp/registry/javascript/structural-subscription.js 2011-04-07 14:16:39 +0000
3+++ lib/lp/registry/javascript/structural-subscription.js 2011-04-08 13:43:45 +0000
4@@ -1050,6 +1050,17 @@
5 };
6 }
7
8+// If set, this will be used instead of Y.io. This is for testing.
9+namespace._Y_io_hook = null;
10+
11+function do_io(link, config) {
12+ var yio = Y.io;
13+ if (namespace._Y_io_hook) {
14+ yio = namespace._Y_io_hook;
15+ }
16+ yio(link, config);
17+}
18+
19 /**
20 * Construct a handler for an unsubscribe link.
21 */
22@@ -1082,7 +1093,7 @@
23 failure: error_handler.getFailureHandler()
24 }
25 };
26- Y.io(filter.self_link, y_config);
27+ do_io(filter.self_link, y_config);
28 };
29 }
30
31
32=== modified file 'lib/lp/registry/javascript/tests/test_structural_subscription.js'
33--- lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-07 23:44:25 +0000
34+++ lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-08 13:43:45 +0000
35@@ -5,7 +5,7 @@
36 filter: 'raw',
37 combine: false,
38 fetchCSS: false
39- }).use('test', 'console', 'node', 'lp.client',
40+ }).use('test', 'console', 'node', 'node-event-simulate', 'lp.client',
41 'lp.registry.structural_subscription', function(Y) {
42
43 var suite = new Y.Test.Suite("Structural subscription overlay tests");
44@@ -41,13 +41,16 @@
45 }
46
47 function create_test_node(include_listing) {
48- return Y.Node.create(
49- '<div id="test-content">' +
50- ' <div id="' + content_box_name + '"></div>' +
51- (include_listing
52- ? (' <div id="' + subscription_listing_name + '"></div>')
53- : '') +
54- '</div>');
55+ var test_node = Y.Node.create('<div id="test-content">')
56+ .append(Y.Node.create('<div></div>')
57+ .set('id', content_box_name))
58+
59+ if (include_listing) {
60+ test_node.append(Y.Node.create('<div style="width: 50%"></div>')
61+ .set('id', subscription_listing_name));
62+ }
63+
64+ return test_node;
65 }
66
67 function remove_test_node() {
68@@ -846,6 +849,252 @@
69 }));
70
71 suite.add(new Y.Test.Case({
72+<<<<<<< TREE
73+ name: 'Structural Subscription: add subcription workflow',
74+
75+ _should: {error: {}},
76+
77+ setUp: function() {
78+ var TestBugFilter = function() {};
79+ TestBugFilter.prototype = {
80+ 'getAttrs': function () {
81+ return {};
82+ }
83+ };
84+ // We need an lp_client that will appear to succesfully create the
85+ // bug filter.
86+ var TestClient = function() {};
87+ TestClient.prototype = {
88+ named_post: function (uri, operation_name, config) {
89+ config.on.success(new TestBugFilter());
90+ this.post_called = true;
91+ },
92+ patch: function(uri, representation, config, headers) {
93+ config.on.success();
94+ this.patch_called = true;
95+ },
96+ post_called: false,
97+ patch_called: false
98+ };
99+
100+ this.original_lp = monkeypatch_LP();
101+
102+ this.configuration = {
103+ content_box: content_box_id,
104+ lp_client: new TestClient()
105+ };
106+ this.content_node = create_test_node();
107+ Y.one('body').appendChild(this.content_node);
108+ },
109+
110+ tearDown: function() {
111+ window.LP = this.original_lp;
112+ remove_test_node();
113+ delete this.content_node;
114+ },
115+
116+ test_simple_add_workflow: function() {
117+ // Clicking on the "Subscribe to bug mail" link and then clicking
118+ // on the overlay form's "OK" button results in a filter being
119+ // created and PATCHed.
120+ module.setup(this.configuration);
121+ Y.one('a.menu-link-subscribe_to_bug_mail').simulate('click');
122+ Assert.isFalse(module.lp_client.post_called);
123+ Assert.isFalse(module.lp_client.patch_called);
124+ var button = Y.one('.yui3-lazr-formoverlay-actions button');
125+ Assert.areEqual(button.get('text'), 'OK');
126+ button.simulate('click');
127+ Assert.isTrue(module.lp_client.post_called);
128+ Assert.isTrue(module.lp_client.patch_called);
129+ },
130+
131+ test_simple_add_workflow_cancled: function() {
132+ // Clicking on the "Subscribe to bug mail" link and then clicking
133+ // on the overlay form's cancel button results in no filter being
134+ // created or PATCHed.
135+ module.setup(this.configuration);
136+ Y.one('a.menu-link-subscribe_to_bug_mail').simulate('click');
137+ Assert.isFalse(module.lp_client.post_called);
138+ Assert.isFalse(module.lp_client.patch_called);
139+ var button = Y.one(
140+ '.yui3-lazr-formoverlay-actions button+button');
141+ Assert.areEqual(button.get('text'), 'Cancel');
142+ button.simulate('click');
143+ Assert.isFalse(module.lp_client.post_called);
144+ Assert.isFalse(module.lp_client.patch_called);
145+ }
146+
147+ }));
148+
149+ suite.add(new Y.Test.Case({
150+ name: 'Structural Subscription: edit subcription workflow',
151+
152+ _should: {error: {}},
153+
154+ setUp: function() {
155+ var TestBugFilter = function(data) {
156+ if (data !== undefined) {
157+ this._data = data;
158+ } else {
159+ this._data = {};
160+ }
161+ };
162+ TestBugFilter.prototype = {
163+ 'getAttrs': function () {
164+ return this._data;
165+ }
166+ };
167+ // We need an lp_client that will appear to succesfully create the
168+ // bug filter.
169+ var TestClient = function() {
170+ this.post_called = false;
171+ this.patch_called = false;
172+ };
173+ TestClient.prototype = {
174+ named_post: function (uri, operation_name, config) {
175+ config.on.success(new TestBugFilter());
176+ this.post_called = true;
177+ },
178+ patch: function(uri, representation, config, headers) {
179+ config.on.success(new TestBugFilter(representation));
180+ this.patch_called = true;
181+ }
182+ };
183+
184+ this.original_lp = monkeypatch_LP();
185+
186+ LP.cache.subscription_info = [{
187+ target_url: 'http://example.com',
188+ target_title:'Example project',
189+ filters: [{
190+ filter: {
191+ description: 'DESCRIPTION',
192+ statuses: [],
193+ importances: [],
194+ tags: [],
195+ find_all_tags: true,
196+ bug_notification_level: 'Discussion',
197+ self_link: 'http://example.com/a_filter'
198+ },
199+ can_mute: true,
200+ is_muted: false,
201+ subscriber_is_team: false,
202+ subscriber_url: 'http://example.com/subscriber',
203+ subscriber_title: 'Thidwick',
204+ user_is_team_admin: false
205+ }]
206+ }];
207+
208+
209+ this.configuration = {
210+ content_box: content_box_id,
211+ lp_client: new TestClient()
212+ };
213+ this.content_node = create_test_node(true);
214+ Y.one('body').appendChild(this.content_node);
215+ },
216+
217+ tearDown: function() {
218+ window.LP = this.original_lp;
219+ remove_test_node();
220+ delete this.content_node;
221+ },
222+
223+ test_simple_edit_workflow: function() {
224+ module.setup_bug_subscriptions(this.configuration);
225+
226+ // Editing a value via the edit link and dialog causes the
227+ // subscription list to reflect the new value.
228+ var label = Y.one('.filter-name span').get('text');
229+ Assert.isTrue(label.indexOf('DESCRIPTION') !== -1);
230+
231+ // No PATCHing has happened yet.
232+ Assert.isFalse(module.lp_client.patch_called);
233+
234+ // Click the edit link.
235+ Y.one('a.edit-subscription').simulate('click');
236+
237+ // Set a new name (description) and click OK.
238+ Y.one('input[name="name"]').set('value', 'NEW VALUE');
239+ var button = Y.one('.yui3-lazr-formoverlay-actions button');
240+ Assert.areEqual(button.get('text'), 'OK');
241+ button.simulate('click');
242+
243+ // Clicking OK resulted in the bug filter being PATCHed.
244+ Assert.isTrue(module.lp_client.patch_called);
245+ // And the new value is reflected in the subscription listing.
246+ label = Y.one('.filter-name span').get('text');
247+ Assert.isTrue(label.indexOf('NEW VALUE') !== -1);
248+ }
249+
250+ }));
251+
252+ suite.add(new Y.Test.Case({
253+ name: 'Structural Subscription: unsubscribing',
254+
255+ _should: {error: {}},
256+
257+ setUp: function() {
258+ var TestClient = function() {};
259+ this.original_lp = monkeypatch_LP();
260+
261+ LP.cache.subscription_info = [{
262+ target_url: 'http://example.com',
263+ target_title:'Example project',
264+ filters: [{
265+ filter: {
266+ description: 'DESCRIPTION',
267+ statuses: [],
268+ importances: [],
269+ tags: [],
270+ find_all_tags: true,
271+ bug_notification_level: 'Discussion',
272+ self_link: 'http://example.com/a_filter'
273+ },
274+ can_mute: true,
275+ is_muted: false,
276+ subscriber_is_team: false,
277+ subscriber_url: 'http://example.com/subscriber',
278+ subscriber_title: 'Thidwick',
279+ user_is_team_admin: false
280+ }]
281+ }];
282+
283+ this.configuration = {
284+ content_box: content_box_id,
285+ lp_client: new TestClient()
286+ };
287+ this.content_node = create_test_node(true);
288+ Y.one('body').appendChild(this.content_node);
289+ },
290+
291+ tearDown: function() {
292+ window.LP = this.original_lp;
293+ remove_test_node();
294+ delete this.content_node;
295+ },
296+
297+ test_simple_unsubscribe: function() {
298+ // Clicking on the unsubscribe link will result in a DELETE being
299+ // sent and the filter description being removed.
300+
301+ var DELETE_performed = false;
302+ // Fake a DELETE that succeeds.
303+ module._Y_io_hook = function (link, config) {
304+ DELETE_performed = true;
305+ config.on.success();
306+ };
307+
308+ module.setup_bug_subscriptions(this.configuration);
309+ Y.one('a.delete-subscription').simulate('click');
310+ Assert.isTrue(DELETE_performed);
311+ }
312+
313+ }));
314+
315+ suite.add(new Y.Test.Case({
316+=======
317+>>>>>>> MERGE-SOURCE
318 name: 'Add a subscription from +subscriptions page',
319
320 setUp: function() {