/
utils.js
100 lines (80 loc) · 2.6 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var path = require('path');
var fs = require('fs');
var _ = require('../lib/utils');
describe('utils', function () {
describe('clone', function () {
it('should clone nested objects', function () {
var obj = { a: { b: 42 }, c: 123 };
var obj2 = _.clone(obj);
expect(obj).toEqual(obj2);
obj.a.b += 2;
obj.c += 2;
expect(obj).not.toEqual(obj2);
});
});
describe('mapping', function () {
it('should map icon for notify-send', function () {
var expected = {
title: 'Foo',
message: 'Bar',
icon: 'foobar',
'expire-time': 10000
};
expect(
_.mapToNotifySend({ title: 'Foo', message: 'Bar', appIcon: 'foobar' })
).toEqual(expected);
expect(
_.mapToNotifySend({ title: 'Foo', message: 'Bar', i: 'foobar' })
).toEqual(expected);
});
it('should map short hand for notify-sned', function () {
var expected = {
urgency: 'a',
'expire-time': 'b',
category: 'c',
icon: 'd',
hint: 'e'
};
expect(
_.mapToNotifySend({ u: 'a', e: 'b', c: 'c', i: 'd', h: 'e' })
).toEqual(expected);
});
it('should map icon for notification center', function () {
var expected = {
title: 'Foo',
message: 'Bar',
appIcon: 'foobar',
timeout: 10,
json: true
};
expect(
_.mapToMac({ title: 'Foo', message: 'Bar', icon: 'foobar' })
).toEqual(expected);
expect(_.mapToMac({ title: 'Foo', message: 'Bar', i: 'foobar' })).toEqual(
expected
);
});
it('should map icon for growl', function () {
var icon = path.join(__dirname, 'fixture', 'coulson.jpg');
var iconRead = fs.readFileSync(icon);
var expected = { title: 'Foo', message: 'Bar', icon: iconRead };
var obj = _.mapToGrowl({ title: 'Foo', message: 'Bar', icon: icon });
expect(obj).toEqual(expected);
expect(obj.icon).toBeTruthy();
expect(Buffer.isBuffer(obj.icon)).toBeTruthy();
obj = _.mapToGrowl({ title: 'Foo', message: 'Bar', appIcon: icon });
expect(obj.icon).toBeTruthy();
expect(Buffer.isBuffer(obj.icon)).toBeTruthy();
});
it('should not map icon url for growl', function () {
var icon = 'http://hostname.com/logo.png';
var expected = { title: 'Foo', message: 'Bar', icon: icon };
expect(
_.mapToGrowl({ title: 'Foo', message: 'Bar', icon: icon })
).toEqual(expected);
expect(
_.mapToGrowl({ title: 'Foo', message: 'Bar', appIcon: icon })
).toEqual(expected);
});
});
});