Merge lp:~frankban/juju-gui/fix-notification-tests into lp:juju-gui/experimental
- fix-notification-tests
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 279 | ||||
Proposed branch: | lp:~frankban/juju-gui/fix-notification-tests | ||||
Merge into: | lp:juju-gui/experimental | ||||
Diff against target: |
318 lines (+74/-159) 1 file modified
test/test_application_notifications.js (+74/-159) |
||||
To merge this branch: | bzr merge lp:~frankban/juju-gui/fix-notification-tests | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju GUI Hackers | Pending | ||
Review via email: mp+139677@code.launchpad.net |
Commit message
Description of the change
Restored notifications tests.
This branch restores the tests previously skipped
(as a consequence of the topology refactor) in
``test_
Simplified the way the number of notifications is
tested: now, rather than checking a value in the DOM,
we check how many model instances are present in
the notifications model list.
Also added a test for the notifications view, that was
no longer exercised due to the change described above.
Francesco Banconi (frankban) wrote : | # |
Gary Poster (gary) wrote : | # |
Benjamin Saller (bcsaller) wrote : | # |
As a fly by review, this branch made me happier than it should have,
Thanks.
Francesco Banconi (frankban) wrote : | # |
Francesco Banconi (frankban) wrote : | # |
*** Submitted:
Restored notifications tests.
This branch restores the tests previously skipped
(as a consequence of the topology refactor) in
``test_
Simplified the way the number of notifications is
tested: now, rather than checking a value in the DOM,
we check how many model instances are present in
the notifications model list.
Also added a test for the notifications view, that was
no longer exercised due to the change described above.
R=gary.poster, benjamin.saller
CC=
https:/
Preview Diff
1 | === modified file 'test/test_application_notifications.js' | |||
2 | --- test/test_application_notifications.js 2012-12-06 17:46:42 +0000 | |||
3 | +++ test/test_application_notifications.js 2012-12-13 11:59:44 +0000 | |||
4 | @@ -1,14 +1,8 @@ | |||
5 | 1 | 'use strict'; | 1 | 'use strict'; |
6 | 2 | 2 | ||
7 | 3 | describe('juju application notifications', function() { | 3 | describe('juju application notifications', function() { |
16 | 4 | var Y, juju, models, views, applicationContainer, notificationsContainer, | 4 | var _setTimeout, _viewsHighlightRow, db, ERR_EV, juju, models, NO_OP, |
17 | 5 | viewContainer, db, _setTimeout, _viewsHighlightRow, ERR_EV, NO_OP; | 5 | viewContainer, views, Y; |
10 | 6 | |||
11 | 7 | function assertNotificationNumber(value) { | ||
12 | 8 | assert.equal( | ||
13 | 9 | applicationContainer.one('#notify-indicator').getHTML().trim(), | ||
14 | 10 | value, 'The system didn\'t show the alert'); | ||
15 | 11 | } | ||
18 | 12 | 6 | ||
19 | 13 | before(function() { | 7 | before(function() { |
20 | 14 | Y = YUI(GlobalConfig).use(['node', | 8 | Y = YUI(GlobalConfig).use(['node', |
21 | @@ -39,34 +33,12 @@ | |||
22 | 39 | 'juju-tests-utils', | 33 | 'juju-tests-utils', |
23 | 40 | 'node-event-simulate'], | 34 | 'node-event-simulate'], |
24 | 41 | function(Y) { | 35 | function(Y) { |
25 | 42 | applicationContainer = Y.Node.create('<div id="test-container" />'); | ||
26 | 43 | applicationContainer.appendTo(Y.one('body')); | ||
27 | 44 | |||
28 | 45 | notificationsContainer = Y.Node.create('<div id="notifications" />'); | ||
29 | 46 | notificationsContainer.appendTo(applicationContainer); | ||
30 | 47 | |||
31 | 48 | viewContainer = Y.Node.create('<div />'); | 36 | viewContainer = Y.Node.create('<div />'); |
33 | 49 | viewContainer.appendTo(applicationContainer); | 37 | viewContainer.appendTo(Y.one('body')); |
34 | 38 | viewContainer.hide(); | ||
35 | 50 | 39 | ||
36 | 51 | db = new models.Database(); | 40 | db = new models.Database(); |
37 | 52 | 41 | ||
38 | 53 | var notificationsView = new views.NotificationsView( | ||
39 | 54 | { container: notificationsContainer, | ||
40 | 55 | db: db, | ||
41 | 56 | env: { | ||
42 | 57 | on: NO_OP, | ||
43 | 58 | get: function(key) { | ||
44 | 59 | if (key === 'connected') { | ||
45 | 60 | return true; | ||
46 | 61 | } | ||
47 | 62 | return null; | ||
48 | 63 | } | ||
49 | 64 | }, | ||
50 | 65 | notifications: db.notifications | ||
51 | 66 | }); | ||
52 | 67 | |||
53 | 68 | notificationsView.render(); | ||
54 | 69 | |||
55 | 70 | // The notifications.js delays the notification update. | 42 | // The notifications.js delays the notification update. |
56 | 71 | // We are going to avoid this timeout to make it possible to test | 43 | // We are going to avoid this timeout to make it possible to test |
57 | 72 | // the notification callback synchronously. | 44 | // the notification callback synchronously. |
58 | @@ -83,11 +55,32 @@ | |||
59 | 83 | }); | 55 | }); |
60 | 84 | 56 | ||
61 | 85 | afterEach(function() { | 57 | afterEach(function() { |
63 | 86 | applicationContainer.remove(true); | 58 | viewContainer.remove(true); |
64 | 87 | window.setTimeout = _setTimeout; | 59 | window.setTimeout = _setTimeout; |
65 | 88 | views.highlightRow = _viewsHighlightRow; | 60 | views.highlightRow = _viewsHighlightRow; |
66 | 89 | }); | 61 | }); |
67 | 90 | 62 | ||
68 | 63 | it('should notify errors in the notifications view', function() { | ||
69 | 64 | viewContainer.set('id', 'notifications'); | ||
70 | 65 | var notificationsView = new views.NotificationsView({ | ||
71 | 66 | container: viewContainer, | ||
72 | 67 | env: { | ||
73 | 68 | on: NO_OP, | ||
74 | 69 | get: function(key) { | ||
75 | 70 | if (key === 'connected') { | ||
76 | 71 | return true; | ||
77 | 72 | } | ||
78 | 73 | return null; | ||
79 | 74 | } | ||
80 | 75 | }, | ||
81 | 76 | notifications: db.notifications | ||
82 | 77 | }); | ||
83 | 78 | notificationsView.render(); | ||
84 | 79 | var notification = new models.Notification({level: 'error'}); | ||
85 | 80 | db.notifications.add(notification); | ||
86 | 81 | assert.equal('1', viewContainer.one('#notify-indicator').getHTML().trim()); | ||
87 | 82 | }); | ||
88 | 83 | |||
89 | 91 | it('should show notification for "add_unit" and "remove_units" exceptions' + | 84 | it('should show notification for "add_unit" and "remove_units" exceptions' + |
90 | 92 | ' (service view)', function() { | 85 | ' (service view)', function() { |
91 | 93 | var view = new views.service( | 86 | var view = new views.service( |
92 | @@ -124,11 +117,11 @@ | |||
93 | 124 | 117 | ||
94 | 125 | // It triggers the "add unit" logic | 118 | // It triggers the "add unit" logic |
95 | 126 | view._modifyUnits(3); | 119 | view._modifyUnits(3); |
97 | 127 | assertNotificationNumber('1'); | 120 | assert.equal(1, db.notifications.size()); |
98 | 128 | 121 | ||
99 | 129 | // It triggers the "remove unit" logic | 122 | // It triggers the "remove unit" logic |
100 | 130 | view._modifyUnits(1); | 123 | view._modifyUnits(1); |
102 | 131 | assertNotificationNumber('2'); | 124 | assert.equal(2, db.notifications.size()); |
103 | 132 | }); | 125 | }); |
104 | 133 | 126 | ||
105 | 134 | it('should show notification for "remove_units" and "resolved" exceptions' + | 127 | it('should show notification for "remove_units" and "resolved" exceptions' + |
106 | @@ -173,7 +166,7 @@ | |||
107 | 173 | view.remove_panel.footerNode.one('.btn-danger').simulate('click'); | 166 | view.remove_panel.footerNode.one('.btn-danger').simulate('click'); |
108 | 174 | view.remove_panel.destroy(); | 167 | view.remove_panel.destroy(); |
109 | 175 | 168 | ||
111 | 176 | assertNotificationNumber('1'); | 169 | assert.equal(1, db.notifications.size()); |
112 | 177 | 170 | ||
113 | 178 | // Fake relation | 171 | // Fake relation |
114 | 179 | db.relations.getById = function() { | 172 | db.relations.getById = function() { |
115 | @@ -192,128 +185,50 @@ | |||
116 | 192 | } | 185 | } |
117 | 193 | }); | 186 | }); |
118 | 194 | 187 | ||
120 | 195 | assertNotificationNumber('2'); | 188 | assert.equal(2, db.notifications.size()); |
121 | 196 | }); | 189 | }); |
122 | 197 | 190 | ||
128 | 198 | it.skip('should show notification for "add_relation" and "remove_relation"' + | 191 | it('should add a notification for "addRelation" exceptions (env view)', |
129 | 199 | ' exceptions (environment view)', function() { | 192 | function() { |
130 | 200 | var view = new views.environment({ | 193 | var view = new views.environment({db: db, container: viewContainer}); |
126 | 201 | db: db, | ||
127 | 202 | container: viewContainer}); | ||
131 | 203 | view.render(); | 194 | view.render(); |
132 | 195 | var module = view.topo.modules.MegaModule; | ||
133 | 196 | // The callback wants to remove the pending relation from the db. | ||
134 | 204 | db.relations.remove = NO_OP; | 197 | db.relations.remove = NO_OP; |
247 | 205 | 198 | // The _addRelationCallback args are: view, relation id, event. | |
248 | 206 | view.service_click_actions._addRelationCallback.apply(view, | 199 | var args = [module, 'relation_id', ERR_EV]; |
249 | 207 | [view, 'relation_id', ERR_EV]); | 200 | module.service_click_actions._addRelationCallback.apply(module, args); |
250 | 208 | 201 | assert.equal(1, db.notifications.size()); | |
251 | 209 | assertNotificationNumber('1'); | 202 | }); |
252 | 210 | 203 | ||
253 | 211 | //view, relationElement, relationId, confirmButton, ev | 204 | it('should add a notification for "removeRelation" exceptions (env view)', |
254 | 212 | view._removeRelationCallback.apply(view, [{ | 205 | function() { |
255 | 213 | get: function() {return {hide: NO_OP, destroy: NO_OP};}, | 206 | var view = new views.environment({db: db, container: viewContainer}); |
256 | 214 | removeSVGClass: NO_OP | 207 | view.render(); |
257 | 215 | }, {}, '', { | 208 | var module = view.topo.modules.MegaModule; |
258 | 216 | set: NO_OP | 209 | // The _removeRelationCallback args are: view, relation element, |
259 | 217 | }, ERR_EV]); | 210 | // relation id, confirm button, event. |
260 | 218 | 211 | var args = [ | |
261 | 219 | assertNotificationNumber('2'); | 212 | {get: function() {return {hide: NO_OP, destroy: NO_OP};}, |
262 | 220 | }); | 213 | removeSVGClass: NO_OP |
263 | 221 | 214 | }, {}, 'relation_id', {set: NO_OP}, ERR_EV | |
264 | 222 | it.skip('should show notification for "add_relation" and "destroy_service"' + | 215 | ]; |
265 | 223 | ' exceptions (environment view)', function() { | 216 | module._removeRelationCallback.apply(module, args); |
266 | 224 | var fakeLink = (function() { | 217 | assert.equal(1, db.notifications.size()); |
267 | 225 | var link = [{}, {}]; | 218 | }); |
268 | 226 | link.enter = function() { | 219 | |
269 | 227 | return { | 220 | it('should add a notification for "destroyService" exceptions (env view)', |
270 | 228 | insert: function() { | 221 | function() { |
271 | 229 | return { | 222 | var view = new views.environment({db: db, container: viewContainer}); |
272 | 230 | attr: NO_OP | 223 | view.render(); |
273 | 231 | }; | 224 | var module = view.topo.modules.MegaModule; |
274 | 232 | } | 225 | // The callback uses the 'getModelURL' attribute to retrieve the |
275 | 233 | }; | 226 | // service URL. |
276 | 234 | }; | 227 | module.set('getModelURL', NO_OP); |
277 | 235 | return link; | 228 | // The _destroyCallback args are: service, view, confirm button, event. |
278 | 236 | })(), | 229 | var args = [{}, module, {set: NO_OP}, ERR_EV]; |
279 | 237 | env = { | 230 | module.service_click_actions._destroyCallback.apply(module, args); |
280 | 238 | destroy_service: function(service, callback) { | 231 | assert.equal(1, db.notifications.size()); |
169 | 239 | callback(ERR_EV); | ||
170 | 240 | }, | ||
171 | 241 | add_relation: function(endpoint_a, endpoint_b, callback) { | ||
172 | 242 | callback(ERR_EV); | ||
173 | 243 | } | ||
174 | 244 | }, | ||
175 | 245 | view = { | ||
176 | 246 | set: NO_OP, | ||
177 | 247 | drawRelation: NO_OP, | ||
178 | 248 | cancelRelationBuild: NO_OP, | ||
179 | 249 | |||
180 | 250 | vis: { | ||
181 | 251 | selectAll: function() { | ||
182 | 252 | return { | ||
183 | 253 | data: function() {return fakeLink;} | ||
184 | 254 | }; | ||
185 | 255 | } | ||
186 | 256 | }, | ||
187 | 257 | removeSVGClass: NO_OP, | ||
188 | 258 | db: db, | ||
189 | 259 | destroy_service: { | ||
190 | 260 | get: NO_OP | ||
191 | 261 | }, | ||
192 | 262 | env: env, | ||
193 | 263 | get: function(key) { | ||
194 | 264 | if ('getModelURL' === key) { | ||
195 | 265 | return NO_OP; | ||
196 | 266 | } | ||
197 | 267 | if ('updateEndpoints' === key) { | ||
198 | 268 | return NO_OP; | ||
199 | 269 | } | ||
200 | 270 | if ('env' === key) { | ||
201 | 271 | return env; | ||
202 | 272 | } | ||
203 | 273 | if ('addRelationStart_service' === key) { | ||
204 | 274 | return {}; | ||
205 | 275 | } | ||
206 | 276 | if ('db' === key) { | ||
207 | 277 | return db; | ||
208 | 278 | } | ||
209 | 279 | if ('destroy_service' === key) { | ||
210 | 280 | return { | ||
211 | 281 | get: NO_OP | ||
212 | 282 | }; | ||
213 | 283 | } | ||
214 | 284 | return null; | ||
215 | 285 | }, | ||
216 | 286 | container: viewContainer, | ||
217 | 287 | _addRelationCallback: function() { | ||
218 | 288 | // Executing the "views.environment.prototype | ||
219 | 289 | // .service_click_actions._addRelationCallback" function | ||
220 | 290 | //instead. | ||
221 | 291 | views.environment.prototype.service_click_actions | ||
222 | 292 | ._addRelationCallback.apply(this, arguments); | ||
223 | 293 | }, | ||
224 | 294 | _destroyCallback: function() { | ||
225 | 295 | // Executing the "views.environment.prototype | ||
226 | 296 | // .service_click_actions._destroyCallback" function | ||
227 | 297 | //instead. | ||
228 | 298 | views.environment.prototype.service_click_actions | ||
229 | 299 | ._destroyCallback.apply(this, arguments); | ||
230 | 300 | } | ||
231 | 301 | }; | ||
232 | 302 | |||
233 | 303 | views.environment.prototype.service_click_actions.addRelationEnd | ||
234 | 304 | .apply(view, [ | ||
235 | 305 | [ | ||
236 | 306 | ['s1', {name: 'n', role: 'client'}], | ||
237 | 307 | ['s2', {name: 'n', role: 'server'}]], | ||
238 | 308 | view]); | ||
239 | 309 | |||
240 | 310 | assertNotificationNumber('1'); | ||
241 | 311 | |||
242 | 312 | views.environment.prototype.service_click_actions.destroyService.apply( | ||
243 | 313 | //destroyService function signature > (m, view, btn) | ||
244 | 314 | view, [{}, view, {set: NO_OP}]); | ||
245 | 315 | |||
246 | 316 | assertNotificationNumber('2'); | ||
281 | 317 | }); | 232 | }); |
282 | 318 | 233 | ||
283 | 319 | it('should show notification for "get_service" exceptions' + | 234 | it('should show notification for "get_service" exceptions' + |
284 | @@ -338,7 +253,7 @@ | |||
285 | 338 | 253 | ||
286 | 339 | view.updateConstraints(); | 254 | view.updateConstraints(); |
287 | 340 | 255 | ||
289 | 341 | assertNotificationNumber('1'); | 256 | assert.equal(1, db.notifications.size()); |
290 | 342 | }); | 257 | }); |
291 | 343 | 258 | ||
292 | 344 | it('should show notification for "get_service", "expose" and "unexpose"' + | 259 | it('should show notification for "get_service", "expose" and "unexpose"' + |
293 | @@ -388,13 +303,13 @@ | |||
294 | 388 | view.render(); | 303 | view.render(); |
295 | 389 | 304 | ||
296 | 390 | view.saveConfig(); | 305 | view.saveConfig(); |
298 | 391 | assertNotificationNumber('1'); | 306 | assert.equal(1, db.notifications.size()); |
299 | 392 | 307 | ||
300 | 393 | view.exposeService(); | 308 | view.exposeService(); |
302 | 394 | assertNotificationNumber('2'); | 309 | assert.equal(2, db.notifications.size()); |
303 | 395 | 310 | ||
304 | 396 | view.unexposeService(); | 311 | view.unexposeService(); |
306 | 397 | assertNotificationNumber('3'); | 312 | assert.equal(3, db.notifications.size()); |
307 | 398 | }); | 313 | }); |
308 | 399 | 314 | ||
309 | 400 | it('should show notification for "remove_relation"' + | 315 | it('should show notification for "remove_relation"' + |
310 | @@ -437,7 +352,7 @@ | |||
311 | 437 | view.remove_panel.footerNode.one('.btn-danger').simulate('click'); | 352 | view.remove_panel.footerNode.one('.btn-danger').simulate('click'); |
312 | 438 | view.remove_panel.destroy(); | 353 | view.remove_panel.destroy(); |
313 | 439 | 354 | ||
315 | 440 | assertNotificationNumber('1'); | 355 | assert.equal(1, db.notifications.size()); |
316 | 441 | }); | 356 | }); |
317 | 442 | 357 | ||
318 | 443 | it('should show notification for "deploy" exceptions (charm view)', | 358 | it('should show notification for "deploy" exceptions (charm view)', |
Reviewers: mp+139677_ code.launchpad. net,
Message:
Please take a look.
Description:
Restored notifications tests.
This branch restores the tests previously skipped application_ notifications` `.
(as a consequence of the topology refactor) in
``test_
Simplified the way the number of notifications is
tested: now, rather than checking a value in the DOM,
we check how many model instances are present in
the notifications model list.
Also added a test for the notifications view, that was
no longer exercised due to the change described above.
https:/ /code.launchpad .net/~frankban/ juju-gui/ fix-notificatio n-tests/ +merge/ 139677
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6942045/
Affected files: application_ notifications. js
A [revision details]
M test/test_