13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
1 |
/* Copyright 2011 Canonical Ltd. This software is licensed under the
|
2 |
* GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
*
|
|
4 |
* Tests for lp.code.branchmergeproposal.updater.
|
|
5 |
*
|
|
6 |
*/
|
|
7 |
||
8 |
YUI().use('lp.testing.runner', 'test', 'dump', 'console', 'node', |
|
9 |
'lp.testing.mockio', 'event', |
|
10 |
'lp.code.branchmergeproposal.updater', function(Y) { |
|
11 |
||
12 |
var suite = new Y.Test.Suite("BranchMergeProposal Updater Tests"); |
|
13 |
||
14 |
var module = Y.lp.code.branchmergeproposal.updater; |
|
15 |
var UpdaterWidget = module.UpdaterWidget; |
|
16 |
||
17 |
/*
|
|
18 |
* Tests for when the updater is built on top of a pending diff.
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
||
22 |
var pending_mp = Y.one('#pending-mp').getContent(); |
|
23 |
||
24 |
suite.add(new Y.Test.Case({ |
|
25 |
||
26 |
name: 'branchmergeproposal-updater-pending-tests', |
|
27 |
||
28 |
setUp: function() { |
|
29 |
Y.one("#placeholder") |
|
30 |
.empty() |
|
31 |
.append(Y.Node.create(pending_mp)); |
|
32 |
var diff_area = Y.one('#diff-area'); |
|
33 |
this.updater = new UpdaterWidget({srcNode: diff_area}); |
|
34 |
||
35 |
LP.cache.context = { |
|
13958.7.8
by Raphael Badin
Fix style; Add a lp_client on the object itself. |
36 |
web_link: "https://code.launchpad.dev/~foo/bar/foobr/+merge/123"}; |
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
37 |
|
38 |
},
|
|
39 |
||
40 |
tearDown: function() { |
|
41 |
this.updater.destroy(); |
|
42 |
},
|
|
43 |
||
44 |
test_default_values: function() { |
|
45 |
Y.Assert.isTrue(this.updater.get('pending')); |
|
46 |
Y.Assert.areEqual( |
|
47 |
'', |
|
48 |
this.updater.get('diff')); |
|
49 |
},
|
|
50 |
||
51 |
test__setup_diff_container: function() { |
|
52 |
this.updater._setup_diff_container(); |
|
53 |
Y.Assert.isFalse(this.updater.get('pending')); |
|
54 |
Y.Assert.areEqual( |
|
14060.2.4
by Raphael Badin
Add tests. |
55 |
"Preview Diff ", |
13958.7.8
by Raphael Badin
Fix style; Add a lp_client on the object itself. |
56 |
this.updater.get( |
57 |
'srcNode').one('#review-diff h2').get('text')); |
|
58 |
Y.Assert.areEqual( |
|
59 |
"", |
|
60 |
this.updater.get( |
|
61 |
'srcNode').one('.diff-content').get('text')); |
|
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
62 |
},
|
63 |
||
14060.2.4
by Raphael Badin
Add tests. |
64 |
test_set_status_updating: function() { |
65 |
this.updater.set_status_updating(); |
|
66 |
Y.Assert.areEqual( |
|
67 |
'/@@/spinner', |
|
68 |
Y.one('h2').one('img').getAttribute('src')); |
|
69 |
},
|
|
70 |
||
71 |
test_set_status_longpolling: function() { |
|
72 |
this.updater.set_status_longpolling(); |
|
73 |
Y.Assert.areEqual( |
|
74 |
'/@@/longpoll_loading', |
|
75 |
Y.one('h2').one('img').getAttribute('src')); |
|
76 |
},
|
|
77 |
||
78 |
test_set_status_longpollerror: function() { |
|
79 |
this.updater.set_status_longpollerror(); |
|
80 |
Y.Assert.areEqual( |
|
81 |
'/@@/longpoll_error', |
|
82 |
Y.one('h2').one('img').getAttribute('src')); |
|
83 |
},
|
|
84 |
||
85 |
test_cleanup_status: function() { |
|
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
86 |
this.updater._setup_diff_container(); |
14060.2.4
by Raphael Badin
Add tests. |
87 |
this.updater.set_status_updating(); |
88 |
this.updater.cleanup_status(); |
|
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
89 |
Y.Assert.areEqual( |
14060.2.4
by Raphael Badin
Add tests. |
90 |
'Preview Diff ', |
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
91 |
Y.one('h2').get('innerHTML')); |
92 |
},
|
|
93 |
||
94 |
test_get_diff: function() { |
|
95 |
this.updater._setup_diff_container(); |
|
96 |
Y.one('.diff-content').set( |
|
97 |
'innerHTML', 'this is a <span>diff</span>'); |
|
98 |
Y.Assert.areEqual( |
|
99 |
'this is a <span>diff</span>', |
|
100 |
this.updater.get('diff')); |
|
101 |
},
|
|
102 |
||
103 |
test_set_diff: function() { |
|
104 |
this.updater.set('diff', 'this is a <span>diff</span>'); |
|
105 |
Y.Assert.areEqual( |
|
106 |
'this is a <span>diff</span>', |
|
107 |
Y.one('.diff-content').get('innerHTML')); |
|
108 |
},
|
|
109 |
||
110 |
test_update_success: function() { |
|
111 |
var mockio = new Y.lp.testing.mockio.MockIo(); |
|
13958.7.8
by Raphael Badin
Fix style; Add a lp_client on the object itself. |
112 |
this.updater.get('lp_client').io_provider = mockio; |
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
113 |
Y.Assert.areEqual( |
114 |
'', |
|
115 |
this.updater.get('diff')); |
|
116 |
this.updater.update(); |
|
117 |
mockio.success({ |
|
118 |
responseText: 'New <span>diff</span>', |
|
119 |
responseHeaders: {'Content-Type': 'text/html'}}); |
|
120 |
||
121 |
Y.Assert.areEqual( |
|
122 |
'New <span>diff</span>', |
|
123 |
this.updater.get('diff')); |
|
124 |
},
|
|
125 |
||
126 |
test_update_fires_event: function() { |
|
127 |
var fired = false; |
|
128 |
var mockio = new Y.lp.testing.mockio.MockIo(); |
|
13958.7.8
by Raphael Badin
Fix style; Add a lp_client on the object itself. |
129 |
this.updater.get('lp_client').io_provider = mockio; |
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
130 |
this.updater.on(this.updater.NAME + '.updated', function() { |
131 |
fired = true; |
|
132 |
});
|
|
133 |
this.updater.update(); |
|
134 |
mockio.success({ |
|
135 |
responseText: 'New <span>diff</span>', |
|
136 |
responseHeaders: {'Content-Type': 'text/html'}}); |
|
137 |
||
138 |
Y.Assert.isTrue(fired); |
|
139 |
}
|
|
140 |
||
141 |
}));
|
|
142 |
||
143 |
/*
|
|
144 |
* Tests for when the updater is built on top of an existing diff.
|
|
145 |
*
|
|
146 |
*/
|
|
147 |
var current_mp = Y.one('#current-mp').getContent(); |
|
148 |
||
149 |
suite.add(new Y.Test.Case({ |
|
150 |
||
151 |
name: 'branchmergeproposal-updater-refresh-tests', |
|
152 |
||
153 |
setUp: function() { |
|
154 |
Y.one("#placeholder") |
|
155 |
.empty() |
|
156 |
.append(Y.Node.create(current_mp)); |
|
157 |
var diff_area = Y.one('#diff-area'); |
|
158 |
this.updater = new UpdaterWidget({srcNode: diff_area}); |
|
159 |
},
|
|
160 |
||
161 |
tearDown: function() { |
|
162 |
this.updater.destroy(); |
|
163 |
},
|
|
164 |
||
165 |
test_default_values: function() { |
|
166 |
Y.Assert.isFalse(this.updater.get('pending')); |
|
167 |
Y.Assert.areEqual( |
|
168 |
'Example diff', |
|
169 |
this.updater.get('diff')); |
|
170 |
},
|
|
171 |
||
172 |
test_get_diff: function() { |
|
173 |
Y.one('.diff-content').set( |
|
174 |
'innerHTML', 'this is a <span>diff</span>'); |
|
175 |
Y.Assert.areEqual( |
|
176 |
'this is a <span>diff</span>', |
|
177 |
this.updater.get('diff')); |
|
178 |
}
|
|
179 |
||
180 |
}));
|
|
181 |
||
13958.7.10
by Raphael Badin
Only update the diff when the event means that the diff has been updated. |
182 |
suite.add(new Y.Test.Case({ |
183 |
||
184 |
name: 'branchmergeproposal-updater-utilities', |
|
185 |
||
186 |
test_is_mp_diff_updated_modified: function() { |
|
187 |
var data = {what: 'modified', edited_fields: ['preview_diff']}; |
|
188 |
Y.Assert.isTrue(module.is_mp_diff_updated(data)); |
|
189 |
},
|
|
190 |
||
191 |
test_is_mp_diff_updater_deleted: function() { |
|
192 |
var data = {what: 'deleted'}; |
|
193 |
Y.Assert.isFalse(module.is_mp_diff_updated(data)); |
|
194 |
},
|
|
195 |
||
196 |
test_is_mp_diff_updated_title_changed: function() { |
|
197 |
var data = {what: 'modified', edited_fields: ['title']}; |
|
198 |
Y.Assert.isFalse(module.is_mp_diff_updated(data)); |
|
199 |
}
|
|
200 |
||
201 |
}));
|
|
202 |
||
13958.7.1
by Raphael Badin
Create UpdaterWidget to update the MP in place. |
203 |
Y.lp.testing.Runner.run(suite); |
204 |
||
205 |
});
|