~bac/juju-gui/1103207

« back to all changes in this revision

Viewing changes to test/test_notifier_widget.js

  • Committer: Matthew Scott
  • Date: 2013-01-09 17:23:33 UTC
  • mfrom: (307 juju-gui)
  • mto: This revision was merged to the branch mainline in revision 312.
  • Revision ID: matthew.scott@canonical.com-20130109172333-ad6ndevmn5p44dz0
Merging with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
'use strict';
2
2
 
3
 
YUI(GlobalConfig).use(['notifier', 'node-event-simulate'], function(Y) {
4
 
  describe('notifier widget', function() {
5
 
    var Notifier, notifierBox;
6
 
 
7
 
    before(function() {
8
 
      Notifier = Y.namespace('juju.widgets').Notifier;
9
 
    });
10
 
 
11
 
    // Create the notifier box and attach it as first element of the body.
12
 
    beforeEach(function() {
13
 
      notifierBox = Y.Node.create('<div id="notifier-box"></div>');
14
 
      notifierBox.setStyle('display', 'none');
15
 
      Y.one('body').prepend(notifierBox);
16
 
    });
17
 
 
18
 
    // Destroy the notifier box created in beforeEach.
19
 
    afterEach(function() {
20
 
      notifierBox.remove();
21
 
      notifierBox.destroy(true);
22
 
    });
23
 
 
24
 
    // Factory rendering and returning a notifier instance.
25
 
    var makeNotifier = function(title, message, timeout) {
26
 
      var notifier = new Notifier({
27
 
        title: title || 'mytitle',
28
 
        message: message || 'mymessage',
29
 
        timeout: timeout || 10000
30
 
      });
31
 
      notifier.render(notifierBox);
32
 
      return notifier;
33
 
    };
34
 
 
35
 
    // Assert the notifier box contains the expectedNumber of notifiers.
36
 
    var assertNumNotifiers = function(expectedNumber) {
37
 
      assert.equal(expectedNumber, notifierBox.get('children').size());
38
 
    };
39
 
 
40
 
    it('should be able to display a notification', function() {
 
3
 
 
4
describe('notifier widget', function() {
 
5
  var Notifier, notifierBox, Y;
 
6
 
 
7
  before(function(done) {
 
8
    Y = YUI(GlobalConfig).use(['notifier', 'node-event-simulate'], function(Y) {
 
9
          Notifier = Y.namespace('juju.widgets').Notifier;
 
10
          done();
 
11
    });
 
12
  });
 
13
 
 
14
  // Create the notifier box and attach it as first element of the body.
 
15
  beforeEach(function() {
 
16
    notifierBox = Y.Node.create('<div id="notifier-box"></div>');
 
17
    notifierBox.setStyle('display', 'none');
 
18
    Y.one('body').prepend(notifierBox);
 
19
  });
 
20
 
 
21
  // Destroy the notifier box created in beforeEach.
 
22
  afterEach(function() {
 
23
    notifierBox.remove();
 
24
    notifierBox.destroy(true);
 
25
  });
 
26
 
 
27
  // Factory rendering and returning a notifier instance.
 
28
  var makeNotifier = function(title, message, timeout) {
 
29
    var notifier = new Notifier({
 
30
      title: title || 'mytitle',
 
31
      message: message || 'mymessage',
 
32
      timeout: timeout || 10000
 
33
    });
 
34
    notifier.render(notifierBox);
 
35
    return notifier;
 
36
  };
 
37
 
 
38
  // Assert the notifier box contains the expectedNumber of notifiers.
 
39
  var assertNumNotifiers = function(expectedNumber) {
 
40
    assert.equal(expectedNumber, notifierBox.get('children').size());
 
41
  };
 
42
 
 
43
  it('should be able to display a notification', function() {
 
44
    makeNotifier();
 
45
    assertNumNotifiers(1);
 
46
  });
 
47
 
 
48
  it('should display the given title and message', function() {
 
49
    makeNotifier('mytitle', 'mymessage');
 
50
    var notifierNode = notifierBox.one('*');
 
51
    assert.equal('mytitle', notifierNode.one('h3').getContent());
 
52
    assert.equal('mymessage', notifierNode.one('div').getContent());
 
53
  });
 
54
 
 
55
  it('should be able to display multiple notifications', function() {
 
56
    var number = 10;
 
57
    for (var i = 0; i < number; i += 1) {
41
58
      makeNotifier();
 
59
    }
 
60
    assertNumNotifiers(number);
 
61
  });
 
62
 
 
63
  it('should display new notifications on top', function() {
 
64
    makeNotifier('mytitle1', 'mymessage1');
 
65
    makeNotifier('mytitle2', 'mymessage2');
 
66
    var notifierNode = notifierBox.one('*');
 
67
    assert.equal('mytitle2', notifierNode.one('h3').getContent());
 
68
    assert.equal('mymessage2', notifierNode.one('div').getContent());
 
69
  });
 
70
 
 
71
  it('should destroy notifications after N milliseconds', function(done) {
 
72
    makeNotifier('mytitle', 'mymessage', 1);
 
73
    // A timeout of 250 milliseconds is used so that we ensure the destroying
 
74
    // animation can be completed.
 
75
    setTimeout(function() {
 
76
      assertNumNotifiers(0);
 
77
      done();
 
78
    }, 250);
 
79
  });
 
80
 
 
81
  it('should destroy notifications on click', function(done) {
 
82
    makeNotifier();
 
83
    notifierBox.one('*').simulate('click');
 
84
    // A timeout of 250 milliseconds is used so that we ensure the destroying
 
85
    // animation can be completed.
 
86
    setTimeout(function() {
 
87
      assertNumNotifiers(0);
 
88
      done();
 
89
    }, 250);
 
90
  });
 
91
 
 
92
  it('should prevent notification removal on mouse enter', function(done) {
 
93
    makeNotifier('mytitle', 'mymessage', 1);
 
94
    notifierBox.one('*').simulate('mouseover');
 
95
    // A timeout of 250 milliseconds is used so that we ensure the node is not
 
96
    // preserved by the destroying animation.
 
97
    setTimeout(function() {
42
98
      assertNumNotifiers(1);
43
 
    });
44
 
 
45
 
    it('should display the given title and message', function() {
46
 
      makeNotifier('mytitle', 'mymessage');
47
 
      var notifierNode = notifierBox.one('*');
48
 
      assert.equal('mytitle', notifierNode.one('h3').getContent());
49
 
      assert.equal('mymessage', notifierNode.one('div').getContent());
50
 
    });
51
 
 
52
 
    it('should be able to display multiple notifications', function() {
53
 
      var number = 10;
54
 
      for (var i = 0; i < number; i += 1) {
55
 
        makeNotifier();
56
 
      }
57
 
      assertNumNotifiers(number);
58
 
    });
59
 
 
60
 
    it('should display new notifications on top', function() {
61
 
      makeNotifier('mytitle1', 'mymessage1');
62
 
      makeNotifier('mytitle2', 'mymessage2');
63
 
      var notifierNode = notifierBox.one('*');
64
 
      assert.equal('mytitle2', notifierNode.one('h3').getContent());
65
 
      assert.equal('mymessage2', notifierNode.one('div').getContent());
66
 
    });
67
 
 
68
 
    it('should destroy notifications after N milliseconds', function(done) {
69
 
      makeNotifier('mytitle', 'mymessage', 1);
70
 
      // A timeout of 250 milliseconds is used so that we ensure the destroying
71
 
      // animation can be completed.
72
 
      setTimeout(function() {
73
 
        assertNumNotifiers(0);
74
 
        done();
75
 
      }, 250);
76
 
    });
77
 
 
78
 
    it('should destroy notifications on click', function(done) {
79
 
      makeNotifier();
80
 
      notifierBox.one('*').simulate('click');
81
 
      // A timeout of 250 milliseconds is used so that we ensure the destroying
82
 
      // animation can be completed.
83
 
      setTimeout(function() {
84
 
        assertNumNotifiers(0);
85
 
        done();
86
 
      }, 250);
87
 
    });
88
 
 
89
 
    it('should prevent notification removal on mouse enter', function(done) {
90
 
      makeNotifier('mytitle', 'mymessage', 1);
91
 
      notifierBox.one('*').simulate('mouseover');
92
 
      // A timeout of 250 milliseconds is used so that we ensure the node is not
93
 
      // preserved by the destroying animation.
94
 
      setTimeout(function() {
95
 
        assertNumNotifiers(1);
96
 
        done();
97
 
      }, 250);
98
 
    });
99
 
 
 
99
      done();
 
100
    }, 250);
100
101
  });
 
102
 
101
103
});
 
104