Merge lp:~frankban/juju-gui/fix-notification-tests into lp:juju-gui/experimental

Proposed by Francesco Banconi
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
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+139677@code.launchpad.net

Description of the change

Restored notifications tests.

This branch restores the tests previously skipped
(as a consequence of the topology refactor) in
``test_application_notifications``.

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://codereview.appspot.com/6942045/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :

Reviewers: mp+139677_code.launchpad.net,

Message:
Please take a look.

Description:
Restored notifications tests.

This branch restores the tests previously skipped
(as a consequence of the topology refactor) in
``test_application_notifications``.

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-notification-tests/+merge/139677

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6942045/

Affected files:
   A [revision details]
   M test/test_application_notifications.js

Revision history for this message
Gary Poster (gary) wrote :

Land as is.

Really nice, Francesco. Thank you.

Gary

https://codereview.appspot.com/6942045/

Revision history for this message
Benjamin Saller (bcsaller) wrote :

As a fly by review, this branch made me happier than it should have,
Thanks.

https://codereview.appspot.com/6942045/

Revision history for this message
Francesco Banconi (frankban) wrote :

Hi Gary and Ben,

thanks for the reviews.

https://codereview.appspot.com/6942045/

Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Restored notifications tests.

This branch restores the tests previously skipped
(as a consequence of the topology refactor) in
``test_application_notifications``.

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://codereview.appspot.com/6942045

https://codereview.appspot.com/6942045/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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 'use strict';
6
7 describe('juju application notifications', function() {
8- var Y, juju, models, views, applicationContainer, notificationsContainer,
9- viewContainer, db, _setTimeout, _viewsHighlightRow, ERR_EV, NO_OP;
10-
11- function assertNotificationNumber(value) {
12- assert.equal(
13- applicationContainer.one('#notify-indicator').getHTML().trim(),
14- value, 'The system didn\'t show the alert');
15- }
16+ var _setTimeout, _viewsHighlightRow, db, ERR_EV, juju, models, NO_OP,
17+ viewContainer, views, Y;
18
19 before(function() {
20 Y = YUI(GlobalConfig).use(['node',
21@@ -39,34 +33,12 @@
22 'juju-tests-utils',
23 'node-event-simulate'],
24 function(Y) {
25- applicationContainer = Y.Node.create('<div id="test-container" />');
26- applicationContainer.appendTo(Y.one('body'));
27-
28- notificationsContainer = Y.Node.create('<div id="notifications" />');
29- notificationsContainer.appendTo(applicationContainer);
30-
31 viewContainer = Y.Node.create('<div />');
32- viewContainer.appendTo(applicationContainer);
33+ viewContainer.appendTo(Y.one('body'));
34+ viewContainer.hide();
35
36 db = new models.Database();
37
38- var notificationsView = new views.NotificationsView(
39- { container: notificationsContainer,
40- db: db,
41- env: {
42- on: NO_OP,
43- get: function(key) {
44- if (key === 'connected') {
45- return true;
46- }
47- return null;
48- }
49- },
50- notifications: db.notifications
51- });
52-
53- notificationsView.render();
54-
55 // The notifications.js delays the notification update.
56 // We are going to avoid this timeout to make it possible to test
57 // the notification callback synchronously.
58@@ -83,11 +55,32 @@
59 });
60
61 afterEach(function() {
62- applicationContainer.remove(true);
63+ viewContainer.remove(true);
64 window.setTimeout = _setTimeout;
65 views.highlightRow = _viewsHighlightRow;
66 });
67
68+ it('should notify errors in the notifications view', function() {
69+ viewContainer.set('id', 'notifications');
70+ var notificationsView = new views.NotificationsView({
71+ container: viewContainer,
72+ env: {
73+ on: NO_OP,
74+ get: function(key) {
75+ if (key === 'connected') {
76+ return true;
77+ }
78+ return null;
79+ }
80+ },
81+ notifications: db.notifications
82+ });
83+ notificationsView.render();
84+ var notification = new models.Notification({level: 'error'});
85+ db.notifications.add(notification);
86+ assert.equal('1', viewContainer.one('#notify-indicator').getHTML().trim());
87+ });
88+
89 it('should show notification for "add_unit" and "remove_units" exceptions' +
90 ' (service view)', function() {
91 var view = new views.service(
92@@ -124,11 +117,11 @@
93
94 // It triggers the "add unit" logic
95 view._modifyUnits(3);
96- assertNotificationNumber('1');
97+ assert.equal(1, db.notifications.size());
98
99 // It triggers the "remove unit" logic
100 view._modifyUnits(1);
101- assertNotificationNumber('2');
102+ assert.equal(2, db.notifications.size());
103 });
104
105 it('should show notification for "remove_units" and "resolved" exceptions' +
106@@ -173,7 +166,7 @@
107 view.remove_panel.footerNode.one('.btn-danger').simulate('click');
108 view.remove_panel.destroy();
109
110- assertNotificationNumber('1');
111+ assert.equal(1, db.notifications.size());
112
113 // Fake relation
114 db.relations.getById = function() {
115@@ -192,128 +185,50 @@
116 }
117 });
118
119- assertNotificationNumber('2');
120+ assert.equal(2, db.notifications.size());
121 });
122
123- it.skip('should show notification for "add_relation" and "remove_relation"' +
124- ' exceptions (environment view)', function() {
125- var view = new views.environment({
126- db: db,
127- container: viewContainer});
128+ it('should add a notification for "addRelation" exceptions (env view)',
129+ function() {
130+ var view = new views.environment({db: db, container: viewContainer});
131 view.render();
132+ var module = view.topo.modules.MegaModule;
133+ // The callback wants to remove the pending relation from the db.
134 db.relations.remove = NO_OP;
135-
136- view.service_click_actions._addRelationCallback.apply(view,
137- [view, 'relation_id', ERR_EV]);
138-
139- assertNotificationNumber('1');
140-
141- //view, relationElement, relationId, confirmButton, ev
142- view._removeRelationCallback.apply(view, [{
143- get: function() {return {hide: NO_OP, destroy: NO_OP};},
144- removeSVGClass: NO_OP
145- }, {}, '', {
146- set: NO_OP
147- }, ERR_EV]);
148-
149- assertNotificationNumber('2');
150- });
151-
152- it.skip('should show notification for "add_relation" and "destroy_service"' +
153- ' exceptions (environment view)', function() {
154- var fakeLink = (function() {
155- var link = [{}, {}];
156- link.enter = function() {
157- return {
158- insert: function() {
159- return {
160- attr: NO_OP
161- };
162- }
163- };
164- };
165- return link;
166- })(),
167- env = {
168- destroy_service: function(service, callback) {
169- callback(ERR_EV);
170- },
171- add_relation: function(endpoint_a, endpoint_b, callback) {
172- callback(ERR_EV);
173- }
174- },
175- view = {
176- set: NO_OP,
177- drawRelation: NO_OP,
178- cancelRelationBuild: NO_OP,
179-
180- vis: {
181- selectAll: function() {
182- return {
183- data: function() {return fakeLink;}
184- };
185- }
186- },
187- removeSVGClass: NO_OP,
188- db: db,
189- destroy_service: {
190- get: NO_OP
191- },
192- env: env,
193- get: function(key) {
194- if ('getModelURL' === key) {
195- return NO_OP;
196- }
197- if ('updateEndpoints' === key) {
198- return NO_OP;
199- }
200- if ('env' === key) {
201- return env;
202- }
203- if ('addRelationStart_service' === key) {
204- return {};
205- }
206- if ('db' === key) {
207- return db;
208- }
209- if ('destroy_service' === key) {
210- return {
211- get: NO_OP
212- };
213- }
214- return null;
215- },
216- container: viewContainer,
217- _addRelationCallback: function() {
218- // Executing the "views.environment.prototype
219- // .service_click_actions._addRelationCallback" function
220- //instead.
221- views.environment.prototype.service_click_actions
222- ._addRelationCallback.apply(this, arguments);
223- },
224- _destroyCallback: function() {
225- // Executing the "views.environment.prototype
226- // .service_click_actions._destroyCallback" function
227- //instead.
228- views.environment.prototype.service_click_actions
229- ._destroyCallback.apply(this, arguments);
230- }
231- };
232-
233- views.environment.prototype.service_click_actions.addRelationEnd
234- .apply(view, [
235- [
236- ['s1', {name: 'n', role: 'client'}],
237- ['s2', {name: 'n', role: 'server'}]],
238- view]);
239-
240- assertNotificationNumber('1');
241-
242- views.environment.prototype.service_click_actions.destroyService.apply(
243- //destroyService function signature > (m, view, btn)
244- view, [{}, view, {set: NO_OP}]);
245-
246- assertNotificationNumber('2');
247+ // The _addRelationCallback args are: view, relation id, event.
248+ var args = [module, 'relation_id', ERR_EV];
249+ module.service_click_actions._addRelationCallback.apply(module, args);
250+ assert.equal(1, db.notifications.size());
251+ });
252+
253+ it('should add a notification for "removeRelation" exceptions (env view)',
254+ function() {
255+ var view = new views.environment({db: db, container: viewContainer});
256+ view.render();
257+ var module = view.topo.modules.MegaModule;
258+ // The _removeRelationCallback args are: view, relation element,
259+ // relation id, confirm button, event.
260+ var args = [
261+ {get: function() {return {hide: NO_OP, destroy: NO_OP};},
262+ removeSVGClass: NO_OP
263+ }, {}, 'relation_id', {set: NO_OP}, ERR_EV
264+ ];
265+ module._removeRelationCallback.apply(module, args);
266+ assert.equal(1, db.notifications.size());
267+ });
268+
269+ it('should add a notification for "destroyService" exceptions (env view)',
270+ function() {
271+ var view = new views.environment({db: db, container: viewContainer});
272+ view.render();
273+ var module = view.topo.modules.MegaModule;
274+ // The callback uses the 'getModelURL' attribute to retrieve the
275+ // service URL.
276+ module.set('getModelURL', NO_OP);
277+ // The _destroyCallback args are: service, view, confirm button, event.
278+ var args = [{}, module, {set: NO_OP}, ERR_EV];
279+ module.service_click_actions._destroyCallback.apply(module, args);
280+ assert.equal(1, db.notifications.size());
281 });
282
283 it('should show notification for "get_service" exceptions' +
284@@ -338,7 +253,7 @@
285
286 view.updateConstraints();
287
288- assertNotificationNumber('1');
289+ assert.equal(1, db.notifications.size());
290 });
291
292 it('should show notification for "get_service", "expose" and "unexpose"' +
293@@ -388,13 +303,13 @@
294 view.render();
295
296 view.saveConfig();
297- assertNotificationNumber('1');
298+ assert.equal(1, db.notifications.size());
299
300 view.exposeService();
301- assertNotificationNumber('2');
302+ assert.equal(2, db.notifications.size());
303
304 view.unexposeService();
305- assertNotificationNumber('3');
306+ assert.equal(3, db.notifications.size());
307 });
308
309 it('should show notification for "remove_relation"' +
310@@ -437,7 +352,7 @@
311 view.remove_panel.footerNode.one('.btn-danger').simulate('click');
312 view.remove_panel.destroy();
313
314- assertNotificationNumber('1');
315+ assert.equal(1, db.notifications.size());
316 });
317
318 it('should show notification for "deploy" exceptions (charm view)',

Subscribers

People subscribed via source and target branches