3
YUI(GlobalConfig).use(['notifier', 'node-event-simulate'], function(Y) {
4
describe('notifier widget', function() {
5
var Notifier, notifierBox;
8
Notifier = Y.namespace('juju.widgets').Notifier;
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);
18
// Destroy the notifier box created in beforeEach.
19
afterEach(function() {
21
notifierBox.destroy(true);
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
31
notifier.render(notifierBox);
35
// Assert the notifier box contains the expectedNumber of notifiers.
36
var assertNumNotifiers = function(expectedNumber) {
37
assert.equal(expectedNumber, notifierBox.get('children').size());
40
it('should be able to display a notification', function() {
4
describe('notifier widget', function() {
5
var Notifier, notifierBox, Y;
7
before(function(done) {
8
Y = YUI(GlobalConfig).use(['notifier', 'node-event-simulate'], function(Y) {
9
Notifier = Y.namespace('juju.widgets').Notifier;
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);
21
// Destroy the notifier box created in beforeEach.
22
afterEach(function() {
24
notifierBox.destroy(true);
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
34
notifier.render(notifierBox);
38
// Assert the notifier box contains the expectedNumber of notifiers.
39
var assertNumNotifiers = function(expectedNumber) {
40
assert.equal(expectedNumber, notifierBox.get('children').size());
43
it('should be able to display a notification', function() {
45
assertNumNotifiers(1);
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());
55
it('should be able to display multiple notifications', function() {
57
for (var i = 0; i < number; i += 1) {
60
assertNumNotifiers(number);
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());
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);
81
it('should destroy notifications on click', function(done) {
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);
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);
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());
52
it('should be able to display multiple notifications', function() {
54
for (var i = 0; i < number; i += 1) {
57
assertNumNotifiers(number);
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());
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);
78
it('should destroy notifications on click', function(done) {
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);
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);