~juju-gui/juju-gui/trunk

« back to all changes in this revision

Viewing changes to test/test_notifications.js

  • Committer: Francesco Banconi
  • Date: 2012-11-16 15:28:01 UTC
  • mfrom: (243.2.16 bug-1076404-growl)
  • Revision ID: francesco.banconi@canonical.com-20121116152801-a3zaldhw4fatgboy
Growl-style notifications.

This branch introduces growl-style notifications
in the top-right corner of the window.
Implemented a notifier widget: it is a reusable
piece of code that just need a title, a message
and a timeout to display a notification. It is used
to render notification outside view containers, so
that notifications are preserved when the user changes
the current view.

A notifier is created when a notification is added,
following these rules:
- the notification is an error;
- the notification is local (it's not related to the
  delta stream).

The last point involves adding a new field "isDelta"
to the notification model, defaulting to false.
Notifications created when the delta stream arrives are
marked as "isDelta: true".

UI: new notifications appear on top, and disappear after
8 seconds. Mouse over prevents a notification to hide, 
mouse click destroys a notification.

Also fixed a bug in the unit view: a callable was undefined
when trying to "retry" or "resolve" a unit.

R=thiago, matthew.scott
CC=
https://codereview.appspot.com/6851058

Show diffs side-by-side

added added

removed removed

Lines of Context:
414
414
        'Relation with endpoint1 (relation type "relation1") was created');
415
415
  });
416
416
});
 
417
 
 
418
describe('notification visual feedback', function() {
 
419
  var env, models, notifications, notificationsView, notifierBox, views, Y;
 
420
 
 
421
  before(function(done) {
 
422
    Y = YUI(GlobalConfig).use('juju-env', 'juju-models', 'juju-views',
 
423
        function(Y) {
 
424
          var juju = Y.namespace('juju');
 
425
          env = new juju.Environment();
 
426
          models = Y.namespace('juju.models');
 
427
          views = Y.namespace('juju.views');
 
428
          done();
 
429
        });
 
430
  });
 
431
 
 
432
  // Instantiate the notifications model list and view.
 
433
  // Also create the notifier box and attach it as first element of the body.
 
434
  beforeEach(function() {
 
435
    notifications = new models.NotificationList();
 
436
    notificationsView = new views.NotificationsView({
 
437
      env: env,
 
438
      notifications: notifications
 
439
    });
 
440
    notifierBox = Y.Node.create('<div id="notifier-box"></div>');
 
441
    notifierBox.setStyle('display', 'none');
 
442
    Y.one('body').prepend(notifierBox);
 
443
  });
 
444
 
 
445
  // Destroy the notifier box created in beforeEach.
 
446
  afterEach(function() {
 
447
    notifierBox.remove();
 
448
    notifierBox.destroy(true);
 
449
  });
 
450
 
 
451
  // Assert the notifier box contains the expectedNumber of notifiers.
 
452
  var assertNumNotifiers = function(expectedNumber) {
 
453
    assert.equal(expectedNumber, notifierBox.get('children').size());
 
454
  };
 
455
 
 
456
  it('should appear when a new error is notified', function() {
 
457
    notifications.add({title: 'mytitle', level: 'error'});
 
458
    assertNumNotifiers(1);
 
459
  });
 
460
 
 
461
  it('should only appear when the DOM contains the notifier box', function() {
 
462
    notifierBox.remove();
 
463
    notifications.add({title: 'mytitle', level: 'error'});
 
464
    assertNumNotifiers(0);
 
465
  });
 
466
 
 
467
  it('should not appear when the notification is not an error', function() {
 
468
    notifications.add({title: 'mytitle', level: 'info'});
 
469
    assertNumNotifiers(0);
 
470
  });
 
471
 
 
472
  it('should not appear when the notification comes form delta', function() {
 
473
    notifications.add({title: 'mytitle', level: 'error', isDelta: true});
 
474
    assertNumNotifiers(0);
 
475
  });
 
476
 
 
477
});