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
1=== modified file 'lib/lp/registry/javascript/tests/test_structural_subscription.js'
2--- lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-07 14:14:03 +0000
3+++ lib/lp/registry/javascript/tests/test_structural_subscription.js 2011-04-07 19:07:27 +0000
4@@ -22,6 +22,10 @@
5 var content_box_name = 'ss-content-box';
6 var content_box_id = '#' + content_box_name;
7
8+ // Listing node.
9+ var subscription_listing_name = 'subscription-listing';
10+ var subscription_listing_id = '#' + subscription_listing_name;
11+
12 var target_link_class = '.menu-link-subscribe_to_bug_mail';
13
14 function array_compare(a,b) {
15@@ -36,10 +40,13 @@
16 return true;
17 }
18
19- function create_test_node() {
20+ function create_test_node(include_listing) {
21 return Y.Node.create(
22 '<div id="test-content">' +
23 ' <div id="' + content_box_name + '"></div>' +
24+ (include_listing
25+ ? (' <div id="' + subscription_listing_name + '"></div>')
26+ : '') +
27 '</div>');
28 }
29
30@@ -58,6 +65,61 @@
31 return true;
32 }
33
34+ function monkeypatch_LP() {
35+ // Monkeypatch LP to avoid network traffic and to allow
36+ // insertion of test data.
37+ var original_lp = window.LP
38+ window.LP = {
39+ links: {},
40+ cache: {}
41+ };
42+
43+ LP.cache.context = {
44+ title: 'Test Project',
45+ self_link: 'https://launchpad.dev/api/test_project'
46+ };
47+ LP.cache.administratedTeams = [];
48+ LP.cache.importances = ['Unknown', 'Critical', 'High', 'Medium',
49+ 'Low', 'Wishlist', 'Undecided'];
50+ LP.cache.statuses = ['New', 'Incomplete', 'Opinion',
51+ 'Invalid', 'Won\'t Fix', 'Expired',
52+ 'Confirmed', 'Triaged', 'In Progress',
53+ 'Fix Committed', 'Fix Released', 'Unknown'];
54+ LP.links.me = 'https://launchpad.dev/api/~someone';
55+ return original_lp;
56+ }
57+
58+ function LPClient(){
59+ if (!(this instanceof arguments.callee))
60+ throw new Error("Constructor called as a function");
61+ this.received = []
62+ // We create new functions every time because we allow them to be
63+ // configured.
64+ this.named_post = function(url, func, config) {
65+ this._call('named_post', config, arguments);
66+ };
67+ this.patch = function(bug_filter, data, config) {
68+ this._call('patch', config, arguments);
69+ }
70+ };
71+ LPClient.prototype._call = function(name, config, args) {
72+ this.received.push(
73+ [name, Array.prototype.slice.call(args)]);
74+ if (!Y.Lang.isValue(args.callee.args))
75+ throw new Error("Set call_args on "+name);
76+ if (Y.Lang.isValue(args.callee.fail) && args.callee.fail) {
77+ config.on.failure.apply(undefined, args.callee.args);
78+ } else {
79+ config.on.success.apply(undefined, args.callee.args);
80+ }
81+ };
82+ // DELETE uses Y.io directly as of this writing, so we cannot stub it
83+ // here.
84+
85+ function make_lp_client_stub() {
86+ return new LPClient();
87+ }
88+
89 test_case = new Y.Test.Case({
90 name: 'structural_subscription_overlay',
91
92@@ -481,28 +543,11 @@
93 setUp: function() {
94 // Monkeypatch LP to avoid network traffic and to allow
95 // insertion of test data.
96- window.LP = {
97- links: {},
98- cache: {}
99- };
100-
101- LP.cache.context = {
102- title: 'Test Project',
103- self_link: 'https://launchpad.dev/api/test_project'
104- };
105- LP.cache.administratedTeams = [];
106- LP.cache.importances = ['Unknown', 'Critical', 'High', 'Medium',
107- 'Low', 'Wishlist', 'Undecided'];
108- LP.cache.statuses = ['New', 'Incomplete', 'Opinion',
109- 'Invalid', 'Won\'t Fix', 'Expired',
110- 'Confirmed', 'Triaged', 'In Progress',
111- 'Fix Committed', 'Fix Released', 'Unknown'];
112- LP.links.me = 'https://launchpad.dev/api/~someone';
113-
114- var lp_client = function() {};
115+ this.original_lp = monkeypatch_LP();
116+
117 this.configuration = {
118 content_box: content_box_id,
119- lp_client: lp_client
120+ lp_client: make_lp_client_stub()
121 };
122
123 this.content_node = create_test_node();
124@@ -510,17 +555,16 @@
125 },
126
127 tearDown: function() {
128- remove_test_node();
129- delete this.content_node;
130+ window.LP = this.original_lp;
131+ remove_test_node();
132+ delete this.content_node;
133 },
134
135 test_overlay_error_handling_adding: function() {
136 // Verify that errors generated during adding of a filter are
137 // displayed to the user.
138- this.configuration.lp_client.named_post =
139- function(url, func, config) {
140- config.on.failure(true, true);
141- };
142+ this.configuration.lp_client.named_post.fail = true;
143+ this.configuration.lp_client.named_post.args = [true, true];
144 module.setup(this.configuration);
145 module._show_add_overlay(this.configuration);
146 // After the setup the overlay should be in the DOM.
147@@ -540,17 +584,10 @@
148 // displayed to the user.
149 var original_delete_filter = module._delete_filter;
150 module._delete_filter = function() {};
151- this.configuration.lp_client.patch =
152- function(bug_filter, data, config) {
153- config.on.failure(true, true);
154- };
155- var bug_filter = {
156- 'getAttrs': function() { return {}; }
157- };
158- this.configuration.lp_client.named_post =
159- function(url, func, config) {
160- config.on.success(bug_filter);
161- };
162+ this.configuration.lp_client.patch.fail = true;
163+ this.configuration.lp_client.patch.args = [true, true];
164+ this.configuration.lp_client.named_post.args = [
165+ {'getAttrs': function() { return {}; }}];
166 module.setup(this.configuration);
167 module._show_add_overlay(this.configuration);
168 // After the setup the overlay should be in the DOM.