Skip to content

Commit

Permalink
Fixes formatting of all files
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelbr committed Jan 26, 2017
1 parent 29fe519 commit aeaedd3
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 81 deletions.
27 changes: 15 additions & 12 deletions example/toaster.js
@@ -1,21 +1,24 @@
var notifier = require('../index');
var path = require('path');

notifier.notify({
message: 'Hello. This is a longer text\nWith "some" newlines.',
wait: true,
icon: path.join(__dirname, 'coulson.jpg'),
sound: true
}, function(err, data) {
// Will also wait until notification is closed.
console.log('Waited');
console.log(err, data);
});
notifier.notify(
{
message: 'Hello. This is a longer text\nWith "some" newlines.',
wait: true,
icon: path.join(__dirname, 'coulson.jpg'),
sound: true
},
function(err, data) {
// Will also wait until notification is closed.
console.log('Waited');
console.log(err, data);
}
);

notifier.on('timeout', function () {
notifier.on('timeout', function() {
console.log('Timed out!');
});

notifier.on('click', function () {
notifier.on('click', function() {
console.log('Clicked!');
});
19 changes: 14 additions & 5 deletions lib/utils.js
Expand Up @@ -313,8 +313,6 @@ function removeNewLines(str) {
return str.replace(/\r?\n/g, excapedNewline);
}



/*
---- Options ----
[-t] <title string> | Displayed on the first line of the toast.
Expand All @@ -328,7 +326,16 @@ function removeNewLines(str) {
-close <id> | Closes a currently displayed notification, in order to be able to close a notification the parameter -w must be used to create the notification.
*/
var allowedToasterFlags = [
't', 'm', 'p', 'w', 'id', 's', 'silent', 'appID', 'close', 'install'
't',
'm',
'p',
'w',
'id',
's',
'silent',
'appID',
'close',
'install'
];
var toasterSoundPrefix = 'Notification.';
var toasterDefaultSound = 'Notification.Default';
Expand Down Expand Up @@ -373,7 +380,7 @@ module.exports.mapToWin8 = function(options) {
options.s = options.sound;
delete options.sound;
}

if (options.s === false) {
options.silent = true;
delete options.s;
Expand All @@ -399,7 +406,9 @@ module.exports.mapToWin8 = function(options) {

for (var key in options) {
// Check if is allowed. If not, delete!
if (options.hasOwnProperty(key) && allowedToasterFlags.indexOf(key) === -1) {
if (
options.hasOwnProperty(key) && allowedToasterFlags.indexOf(key) === -1
) {
delete options[key];
}
}
Expand Down
11 changes: 7 additions & 4 deletions notifiers/toaster.js
Expand Up @@ -31,7 +31,7 @@ function noop() {
var timeoutMessage = 'the toast has timed out';
var successMessage = 'user clicked on the toast';

function hasText (str, txt) {
function hasText(str, txt) {
return str && str.indexOf(txt) !== -1;
}

Expand All @@ -53,14 +53,14 @@ WindowsToaster.prototype.notify = function(options, callback) {
var actionJackedCallback = utils.actionJackerDecorator(
this,
options,
function cb (err, data) {
function cb(err, data) {
// Needs to filter out timeout. Not an actual error.
if (err && hasText(data, timeoutMessage)) {
return callback(null, data);
}
callback(err, data);
},
function mapper (data) {
function mapper(data) {
if (hasText(data, successMessage)) {
return 'click';
}
Expand All @@ -72,7 +72,10 @@ WindowsToaster.prototype.notify = function(options, callback) {
);

options.title = options.title || 'Node Notification:';
if (typeof options.message === 'undefined' && typeof options.close === 'undefined') {
if (
typeof options.message === 'undefined' &&
typeof options.close === 'undefined'
) {
callback(new Error('Message or ID to close is required.'));
return this;
}
Expand Down
11 changes: 4 additions & 7 deletions test/_test_utils.js
@@ -1,17 +1,14 @@


module.exports.argsListHas = function argsListHas (args, field) {
return args.filter(function (item) {
module.exports.argsListHas = function argsListHas(args, field) {
return args.filter(function(item) {
return item === field;
}).length > 0;
};

module.exports.getOptionValue = function getOptionValue (args, field) {
for(var i = 0; i < args.length; i++){
module.exports.getOptionValue = function getOptionValue(args, field) {
for (var i = 0; i < args.length; i++) {
if (args[i] === field && i < args.length - 1) {
return args[i + 1];
}
}
return void 0;
};

2 changes: 1 addition & 1 deletion test/notify-send.js
Expand Up @@ -64,7 +64,7 @@ describe('notify-send', function() {
});

it('should escape message input', function(done) {
var excapedNewline = process.platform === 'win32' ? '\\r\\n' : '\\n';
var excapedNewline = process.platform === 'win32' ? '\\r\\n' : '\\n';
var expected = [
'"Node Notification:"',
'"some' + excapedNewline + ' \\"me\'ss\\`age\\`\\""'
Expand Down
31 changes: 18 additions & 13 deletions test/terminal-notifier.js
Expand Up @@ -187,19 +187,24 @@ describe('terminal-notifier', function() {
);
});

it('should validate and transform sound to default sound if Windows sound is selected', function(done) {
utils.fileCommandJson = function(notifier, argsList, callback) {
should(testUtils.getOptionValue(argsList, '-title')).equal('"Heya"');
should(testUtils.getOptionValue(argsList, '-sound')).equal('"Bottle"');
done();
};
var notifier = new NotificationCenter();
notifier.notify({
title: 'Heya',
message: 'foo bar',
sound: 'Notification.Default'
});
});
it(
'should validate and transform sound to default sound if Windows sound is selected',
function(done) {
utils.fileCommandJson = function(notifier, argsList, callback) {
should(testUtils.getOptionValue(argsList, '-title')).equal('"Heya"');
should(
testUtils.getOptionValue(argsList, '-sound')
).equal('"Bottle"');
done();
};
var notifier = new NotificationCenter();
notifier.notify({
title: 'Heya',
message: 'foo bar',
sound: 'Notification.Default'
});
}
);

it('should convert list of actions to flat list', function(done) {
var expected = [
Expand Down
67 changes: 28 additions & 39 deletions test/toaster.js
Expand Up @@ -26,7 +26,9 @@ describe('WindowsToaster', function() {
os.release = this.originalRelease;
});

it('should only pass allowed options and proper named properties', function(done) {
it('should only pass allowed options and proper named properties', function(
done
) {
utils.fileCommand = function(notifier, argsList, callback) {
testUtils.argsListHas(argsList, '-t').should.be.true();
testUtils.argsListHas(argsList, '-m').should.be.true();
Expand Down Expand Up @@ -98,16 +100,13 @@ describe('WindowsToaster', function() {
};
var notifier = new Notify();

notifier.notify({
message: 'Heya',
remove: 3
});
notifier.notify({ message: 'Heya', remove: 3 });
});

it('should fail if neither close or message is defined', function(done) {
var notifier = new Notify();

notifier.notify({ title: 'Heya' }, function (err) {
notifier.notify({ title: 'Heya' }, function(err) {
err.message.should.startWith('Message or ID to close is required');
done();
});
Expand All @@ -120,9 +119,7 @@ describe('WindowsToaster', function() {
};
var notifier = new Notify();

notifier.notify({
close: 3
}, function (err) {
notifier.notify({ close: 3 }, function(err) {
should.not.exist(err);
done();
});
Expand All @@ -135,9 +132,7 @@ describe('WindowsToaster', function() {
};
var notifier = new Notify();

notifier.notify({
message: 'Hello'
}, function (err) {
notifier.notify({ message: 'Hello' }, function(err) {
should.not.exist(err);
done();
});
Expand All @@ -150,7 +145,7 @@ describe('WindowsToaster', function() {
};
var notifier = new Notify();

notifier.notify('hello', function (err) {
notifier.notify('hello', function(err) {
should.not.exist(err);
done();
});
Expand All @@ -164,38 +159,35 @@ describe('WindowsToaster', function() {
};
var notifier = new Notify();

notifier.notify({
title: 'Heya',
message: 'foo bar'
});
notifier.notify({ title: 'Heya', message: 'foo bar' });
});

it('should validate and transform sound to default sound if Mac sound is selected', function(done) {
utils.fileCommand = function(notifier, argsList, callback) {
should(testUtils.getOptionValue(argsList, '-t')).equal('Heya');
should(testUtils.getOptionValue(argsList, '-s')).equal('Notification.Default');
done();
};
var notifier = new Notify();
it(
'should validate and transform sound to default sound if Mac sound is selected',
function(done) {
utils.fileCommand = function(notifier, argsList, callback) {
should(testUtils.getOptionValue(argsList, '-t')).equal('Heya');
should(
testUtils.getOptionValue(argsList, '-s')
).equal('Notification.Default');
done();
};
var notifier = new Notify();

notifier.notify({
title: 'Heya',
message: 'foo bar',
sound: 'Frog'
});
});
notifier.notify({ title: 'Heya', message: 'foo bar', sound: 'Frog' });
}
);

it('sound as true should select default value', function(done) {
utils.fileCommand = function(notifier, argsList, callback) {
should(testUtils.getOptionValue(argsList, '-s')).equal('Notification.Default');
should(
testUtils.getOptionValue(argsList, '-s')
).equal('Notification.Default');
done();
};
var notifier = new Notify();

notifier.notify({
message: 'foo bar',
sound: true
});
notifier.notify({ message: 'foo bar', sound: true });
});

it('sound as false should be same as silent', function(done) {
Expand All @@ -205,10 +197,7 @@ describe('WindowsToaster', function() {
};
var notifier = new Notify();

notifier.notify({
message: 'foo bar',
sound: false
});
notifier.notify({ message: 'foo bar', sound: false });
});

it('should override sound', function(done) {
Expand Down

0 comments on commit aeaedd3

Please sign in to comment.