redmine-client/node_modules/node-notifier/test/notify-send.js
2014-12-26 04:41:54 +01:00

137 lines
3.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var Notify = require('../notifiers/notifysend')
, should = require('should')
, utils = require('../lib/utils')
, os = require('os')
, assert = require('assert');
describe('notify-send', function(){
before(function () {
this.original = utils.command;
this.originalType = os.type;
os.type = function () {
return "Linux";
};
});
after(function () {
utils.command = this.original;
os.type = this.originalType;
});
it('should pass on title and body', function (done) {
var expected = [ '"title"', '"body"' ];
utils.command = function (notifier, argsList, callback) {
argsList.should.eql(expected);
done();
};
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({
title: "title",
message: "body"
}, function (err) {
should.not.exist(err);
done();
})
});
it('should pass have default title', function (done) {
var expected = [ '"Node Notification:"', '"body"' ];
utils.command = function (notifier, argsList, callback) {
argsList.should.eql(expected);
done();
};
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({
message: "body"
}, function (err) {
should.not.exist(err);
done();
})
});
it('should throw error if no message is passed', function (done) {
utils.command = function (notifier, argsList, callback) {
should.not.exist(argsList);
done();
};
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({
}, function (err) {
err.message.should.equal("Message is required.");
done();
})
});
it('should escape message input', function (done) {
var expected = [ '"Node Notification:"', '"some \\"me\'ss\\`age\\`\\""' ];
utils.command = function (notifier, argsList, callback) {
argsList.should.eql(expected);
done();
};
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({
message: 'some "me\'ss`age`"'
}, function (err) {
should.not.exist(err);
done();
})
});
it('should send additional parameters as --"keyname"', function (done) {
var expected = [ '"title"', '"body"', '--icon', '"icon-string"' ]
utils.command = function (notifier, argsList, callback) {
argsList.should.eql(expected);
done();
};
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({
title: "title",
message: "body",
icon: "icon-string"
}, function (err) {
should.not.exist(err);
done();
})
});
it('should remove extra options that are not supported by notify-send', function (done) {
var expected = [ '"title"', '"body"', '--icon', '"icon-string"' ]
utils.command = function (notifier, argsList, callback) {
argsList.should.eql(expected);
done();
};
var notifier = new Notify({ suppressOsdCheck: true });
notifier.notify({
title: "title",
message: "body",
icon: "icon-string",
tullball: "notValid"
}, function (err) {
should.not.exist(err);
done();
})
});
});