forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupbat.test.js
120 lines (98 loc) · 3.42 KB
/
upbat.test.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
require('should');
describe('Uploader Battery', function ( ) {
var data = {devicestatus: [{mills: Date.now(), uploader: {battery: 20}}]};
it('display uploader battery status', function (done) {
var sandbox = require('../lib/sandbox')();
var ctx = {
settings: {}
, language: require('../lib/language')()
};
ctx.language.set('en');
ctx.levels = require('../lib/levels');
var sbx = sandbox.clientInit(ctx, Date.now(), data);
sbx.offerProperty = function mockedOfferProperty (name, setter) {
name.should.equal('upbat');
var result = setter();
result.display.should.equal('20%');
result.status.should.equal('urgent');
result.min.value.should.equal(20);
result.min.level.should.equal(25);
done();
};
var upbat = require('../lib/plugins/upbat')(ctx);
upbat.setProperties(sbx);
});
it('set a pill to the uploader battery status', function (done) {
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.value.should.equal('20%');
options.labelClass.should.equal('icon-battery-25');
options.pillClass.should.equal('urgent');
done();
}
}
, language: require('../lib/language')()
};
ctx.language.set('en');
var sandbox = require('../lib/sandbox')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
var upbat = require('../lib/plugins/upbat')(ctx);
upbat.setProperties(sbx);
upbat.updateVisualisation(sbx);
});
it('hide the pill if there is no uploader battery status', function (done) {
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText (plugin, options) {
options.hide.should.equal(true);
done();
}
}
, language: require('../lib/language')()
};
ctx.language.set('en');
var sandbox = require('../lib/sandbox')();
var sbx = sandbox.clientInit(ctx, Date.now(), {});
var upbat = require('../lib/plugins/upbat')(ctx);
upbat.setProperties(sbx);
upbat.updateVisualisation(sbx);
});
it('hide the pill if there is uploader battery status is -1', function (done) {
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.hide.should.equal(true);
done();
}
}, language: require('../lib/language')()
};
ctx.language.set('en');
var sandbox = require('../lib/sandbox')();
var sbx = sandbox.clientInit(ctx, Date.now(), {devicestatus: [{uploader: {battery: -1}}]});
var upbat = require('../lib/plugins/upbat')(ctx);
upbat.setProperties(sbx);
upbat.updateVisualisation(sbx);
});
it('should handle alexa requests', function (done) {
var ctx = {
settings: {}
, language: require('../lib/language')()
};
ctx.language.set('en');
var sandbox = require('../lib/sandbox')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
var upbat = require('../lib/plugins/upbat')(ctx);
upbat.setProperties(sbx);
upbat.alexa.intentHandlers.length.should.equal(1);
upbat.alexa.intentHandlers[0].intentHandler(function next(title, response) {
title.should.equal('Uploader battery');
response.should.equal('Your uploader battery is at 20%');
done();
}, [], sbx);
});
});