1 | var Notify = require('../notifiers/balloon')
|
2 | , should = require('should')
|
3 | , utils = require('../lib/utils')
|
4 | , os = require('os')
|
5 | , assert = require('assert');
|
6 |
|
7 | describe('WindowsBalloon', function(){
|
8 |
|
9 | before(function () {
|
10 | this.original = utils.immediateFileCommand;
|
11 | this.originalType = os.type;
|
12 | os.type = function () {
|
13 | return "Windows_NT";
|
14 | };
|
15 | });
|
16 |
|
17 | after(function () {
|
18 | utils.immediateFileCommand = this.original;
|
19 | os.type = this.originalType;
|
20 | });
|
21 |
|
22 | it('should pass on title and body', function (done) {
|
23 | var expected = [ '-m', 'body', '-p', 'title', '-q' ];
|
24 |
|
25 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
26 | argsList.should.eql(expected);
|
27 | done();
|
28 | };
|
29 |
|
30 | var notifier = new Notify();
|
31 |
|
32 | notifier.notify({
|
33 | title: "title",
|
34 | message: "body"
|
35 | }, function (err) {
|
36 | should.not.exist(err);
|
37 | })
|
38 | });
|
39 |
|
40 | it('should pass have default title', function (done) {
|
41 | var expected = [ '-m', 'body', '-q', '-p', 'Node Notification:' ];
|
42 |
|
43 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
44 | argsList.should.eql(expected);
|
45 | done();
|
46 | };
|
47 |
|
48 | var notifier = new Notify();
|
49 |
|
50 | notifier.notify({
|
51 | message: "body"
|
52 | }, function (err) {
|
53 | should.not.exist(err);
|
54 | })
|
55 | });
|
56 |
|
57 | it('should throw error if no message is passed', function (done) {
|
58 |
|
59 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
60 | should.not.exist(argsList);
|
61 | };
|
62 |
|
63 | var notifier = new Notify();
|
64 |
|
65 | notifier.notify({
|
66 | }, function (err) {
|
67 | err.message.should.equal("Message is required.");
|
68 | done();
|
69 | });
|
70 | });
|
71 |
|
72 | it('should escape message input', function (done) {
|
73 | var expected = [ '-m', 'some "me\'ss\`age\`\"', '-q', '-p', 'Node Notification:' ];
|
74 |
|
75 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
76 | argsList.should.eql(expected);
|
77 | done();
|
78 | };
|
79 |
|
80 | var notifier = new Notify();
|
81 |
|
82 | notifier.notify({
|
83 | message: 'some "me\'ss`age`"'
|
84 | }, function (err) {
|
85 | should.not.exist(err);
|
86 | })
|
87 | });
|
88 |
|
89 | it('should be able to deactivate silent mode', function (done) {
|
90 | var expected = [ '-m', 'body', '-p', 'Node Notification:' ];
|
91 |
|
92 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
93 | argsList.should.eql(expected);
|
94 | done();
|
95 | };
|
96 |
|
97 | var notifier = new Notify();
|
98 |
|
99 | notifier.notify({
|
100 | message: "body",
|
101 | sound: true
|
102 | }, function (err) {
|
103 | should.not.exist(err);
|
104 | })
|
105 | });
|
106 |
|
107 |
|
108 | it('should be able to deactivate silent mode, by doing quiet false', function (done) {
|
109 | var expected = [ '-m', 'body', '-p', 'Node Notification:' ];
|
110 |
|
111 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
112 | argsList.should.eql(expected);
|
113 | done();
|
114 | };
|
115 |
|
116 | var notifier = new Notify();
|
117 |
|
118 | notifier.notify({
|
119 | message: "body",
|
120 | quiet: false
|
121 | }, function (err) {
|
122 | should.not.exist(err);
|
123 | })
|
124 | });
|
125 |
|
126 | it('should send set time', function (done) {
|
127 | var expected = [ '-m', 'body', '-p', 'title', '-d', '1000', '-q' ];
|
128 |
|
129 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
130 | argsList.should.eql(expected);
|
131 | done();
|
132 | };
|
133 |
|
134 | var notifier = new Notify();
|
135 |
|
136 | notifier.notify({
|
137 | title: "title",
|
138 | message: "body",
|
139 | time: "1000"
|
140 | }, function (err) {
|
141 | should.not.exist(err);
|
142 | })
|
143 | });
|
144 |
|
145 | it('should not send false flags', function (done) {
|
146 | var expected = [ '-d', '1000', '-i', 'icon', '-m', 'body', '-p', 'title', '-q' ];
|
147 |
|
148 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
149 | argsList.should.eql(expected);
|
150 | done();
|
151 | };
|
152 |
|
153 | var notifier = new Notify();
|
154 |
|
155 | notifier.notify({
|
156 | title: "title",
|
157 | message: "body",
|
158 | d: "1000",
|
159 | icon: 'icon',
|
160 | w: false
|
161 | }, function (err) {
|
162 | should.not.exist(err);
|
163 | })
|
164 | });
|
165 |
|
166 |
|
167 | it('should send additional parameters as --"keyname"', function (done) {
|
168 | var expected = [ '-d', '1000', '-w', '-i', 'icon', '-m', 'body', '-p', 'title', '-q' ];
|
169 |
|
170 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
171 | argsList.should.eql(expected);
|
172 | done();
|
173 | };
|
174 |
|
175 | var notifier = new Notify();
|
176 |
|
177 | notifier.notify({
|
178 | title: "title",
|
179 | message: "body",
|
180 | d: "1000",
|
181 | icon: 'icon',
|
182 | w: true
|
183 | }, function (err) {
|
184 | should.not.exist(err);
|
185 | })
|
186 | });
|
187 |
|
188 | it('should remove extra options that are not supported by notifu', function (done) {
|
189 | var expected = [ '-m', 'body', '-p', 'title', '-q' ];
|
190 |
|
191 | utils.immediateFileCommand = function (notifier, argsList, callback) {
|
192 | argsList.should.eql(expected);
|
193 | done();
|
194 | };
|
195 |
|
196 | var notifier = new Notify();
|
197 |
|
198 | notifier.notify({
|
199 | title: "title",
|
200 | message: "body",
|
201 | tullball: "notValid"
|
202 | }, function (err) {
|
203 | should.not.exist(err);
|
204 | })
|
205 | });
|
206 |
|
207 | });
|