UNPKG

3.39 kBJavaScriptView Raw
1var should = require('should'),
2 path = require('path'),
3 os = require('os'),
4 fs = require('fs');
5
6var _ = require('../lib/utils');
7
8var originalType = os.type;
9var originalVersion = _.getOSXVersion;
10
11describe('utils', function(){
12
13 before(function () {
14 os.type = function () {
15 return "Darwin";
16 };
17 });
18
19 after(function () {
20 os.type = originalType;
21 _.getOSXVersion = originalVersion;
22 });
23
24 it('should support mac 10.8', function (done) {
25 _.getOSXVersion = function (cb) {
26 cb(null, "10.8");
27 };
28
29 _.isMacOSX(function (error, msg) {
30 error.should.be.false;
31 (msg === void 0).should.be.true;
32 done();
33 });
34 });
35
36 it('should support not mac 10.7', function (done) {
37 _.getOSXVersion = function (cb) {
38 cb(null, "10.7");
39 };
40
41 _.isMacOSX(function (error, msg) {
42 error.should.equal('old');
43 (msg === void 0).should.be.false;
44 done();
45 });
46 });
47
48 it('should support 10.10', function (done) {
49 _.getOSXVersion = function (cb) {
50 cb(null, "10.10");
51 };
52
53 _.isMacOSX(function (error, msg) {
54 error.should.be.false;
55 (msg === void 0).should.be.true;
56 done();
57 });
58 });
59
60 it('should sopport 10.10 with newline', function (done) {
61 _.getOSXVersion = function (cb) {
62 cb(null, "10.10\n");
63 };
64
65 _.isMacOSX(function (error, msg) {
66 error.should.be.false;
67 (msg === void 0).should.be.true;
68 done();
69 });
70 });
71
72 describe('mapping', function () {
73
74 it('should map icon for notify-send', function () {
75 var expected = {
76 title: 'Foo',
77 message: 'Bar',
78 icon: 'foobar'
79 };
80
81 _.mapToNotifySend({
82 title: 'Foo',
83 message: 'Bar',
84 appIcon: 'foobar'
85 }).should.eql(expected);
86
87 _.mapToNotifySend({
88 title: 'Foo',
89 message: 'Bar',
90 i: 'foobar'
91 }).should.eql(expected);
92 });
93
94 it('should map short hand for notify-sned', function () {
95 var expected = {
96 urgency: 'a',
97 'expire-time': 'b',
98 category: 'c',
99 icon: 'd',
100 hint: 'e'
101 };
102
103 _.mapToNotifySend({
104 u: 'a',
105 e: 'b',
106 c: 'c',
107 i: 'd',
108 h: 'e'
109 }).should.eql(expected);
110 });
111
112 it('should map icon for notification center', function () {
113 var expected = {
114 title: 'Foo',
115 message: 'Bar',
116 appIcon: 'foobar'
117 };
118
119 _.mapToMac({
120 title: 'Foo',
121 message: 'Bar',
122 icon: 'foobar'
123 }).should.eql(expected);
124
125 _.mapToMac({
126 title: 'Foo',
127 message: 'Bar',
128 i: 'foobar'
129 }).should.eql(expected);
130 });
131
132 it('should map icon for growl', function () {
133 var icon = path.join(__dirname, 'fixture', 'coulson.jpg');
134 var iconRead = fs.readFileSync(icon);
135
136 var expected = {
137 title: 'Foo',
138 message: 'Bar',
139 icon: fs.readFileSync(icon)
140 };
141
142 var obj = _.mapToGrowl({
143 title: 'Foo',
144 message: 'Bar',
145 icon: icon
146 });
147
148 obj.should.have.property('icon');
149 (Buffer.isBuffer(obj.icon)).should.be.true;
150
151 var obj = _.mapToGrowl({
152 title: 'Foo',
153 message: 'Bar',
154 appIcon: icon
155 });
156
157 obj.should.have.property('icon');
158 (Buffer.isBuffer(obj.icon)).should.be.true;
159 });
160
161 });
162
163});