Skip to content

Commit f257d41

Browse files
committed
Add notify unit tests.
1 parent 17c0952 commit f257d41

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

specs/chrome/notify-spec.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,96 @@
22
/* global describe, it, expect */
33

44
'use strict';
5+
6+
describe('notify', function() {
7+
afterAll(function() {
8+
GLOBAL.base = GLOBAL.box = GLOBAL.content = GLOBAL.notifier = null;
9+
});
10+
11+
beforeAll(function(done) {
12+
var jsdom = require('jsdom');
13+
jsdom.env('<html><body><div class="base"></div></body></html>',
14+
[__dirname + '/../../jquery-2.1.4.js'], function (err, win) {
15+
GLOBAL.window = win
16+
GLOBAL.document = win.document
17+
GLOBAL.jQuery = GLOBAL.$ = require('jquery');
18+
require(__dirname + '/../../src/chrome/assets/js/notify.js');
19+
GLOBAL.base = $('div.base');
20+
GLOBAL.notifier = base.notify({ hide: { speed: 0 }, show: { speed: 0 }, timeout: 100 });
21+
GLOBAL.box = base.next('div.notify');
22+
GLOBAL.arrow = box.children('div.arrow');
23+
GLOBAL.content = box.children('div.content');
24+
done();
25+
});
26+
});
27+
28+
beforeEach(function() {
29+
box.show();
30+
});
31+
32+
it('should render error message', function() {
33+
notifier.error('message');
34+
expect(box.css('display')).not.toEqual('none');
35+
expect(box.hasClass('error')).toBeTruthy();
36+
expect(box.hasClass('notify')).toBeTruthy();
37+
expect(arrow.css('right')).not.toEqual('{{arrow.right}}px');
38+
expect(content.text()).toEqual('message');
39+
content.trigger('click');
40+
expect(box.css('display')).toEqual('none');
41+
});
42+
43+
it('should render info message', function() {
44+
notifier.info('message');
45+
expect(box.css('display')).not.toEqual('none');
46+
expect(box.hasClass('info')).toBeTruthy();
47+
expect(box.hasClass('notify')).toBeTruthy();
48+
expect(arrow.css('right')).not.toEqual('{{arrow.right}}px');
49+
expect(content.text()).toEqual('message');
50+
content.trigger('click');
51+
expect(box.css('display')).toEqual('none');
52+
});
53+
54+
it('should render log message', function() {
55+
notifier.log('message');
56+
expect(box.css('display')).not.toEqual('none');
57+
expect(box.hasClass('notify')).toBeTruthy();
58+
expect(arrow.css('right')).not.toEqual('{{arrow.right}}px');
59+
expect(content.text()).toEqual('message');
60+
content.trigger('click');
61+
expect(box.css('display')).toEqual('none');
62+
});
63+
64+
it('should render success message', function() {
65+
notifier.success('message');
66+
expect(box.css('display')).not.toEqual('none');
67+
expect(box.hasClass('success')).toBeTruthy();
68+
expect(box.hasClass('notify')).toBeTruthy();
69+
expect(arrow.css('right')).not.toEqual('{{arrow.right}}px');
70+
expect(content.text()).toEqual('message');
71+
content.trigger('click');
72+
expect(box.css('display')).toEqual('none');
73+
});
74+
75+
it('should render warn message', function() {
76+
notifier.warn('message');
77+
expect(box.css('display')).not.toEqual('none');
78+
expect(box.hasClass('warn')).toBeTruthy();
79+
expect(box.hasClass('notify')).toBeTruthy();
80+
expect(arrow.css('right')).not.toEqual('{{arrow.right}}px');
81+
expect(content.text()).toEqual('message');
82+
content.trigger('click');
83+
expect(box.css('display')).toEqual('none');
84+
});
85+
86+
it('should hide the box in requested timeout', function(done) {
87+
notifier.log('message');
88+
expect(box.css('display')).not.toEqual('none');
89+
expect(box.hasClass('notify')).toBeTruthy();
90+
expect(arrow.css('right')).not.toEqual('{{arrow.right}}px');
91+
expect(content.text()).toEqual('message');
92+
setTimeout(function() {
93+
expect(box.css('display')).toEqual('none');
94+
done();
95+
}, 750);
96+
});
97+
});

0 commit comments

Comments
 (0)