forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.test.js.temporary_removed
138 lines (118 loc) · 3.69 KB
/
client.test.js.temporary_removed
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict';
require('should');
var times = require('../lib/times');
var benv = require('benv');
var read = require('fs').readFileSync;
var serverSettings = require('./fixtures/default-server-settings');
var TEST_TITLE = 'Test Title';
var stored = { };
var removed = { };
var now = Date.now();
var next = Date.now() + times.mins(5).msecs;
var nowData = {
sgvs: [
{ device: 'dexcom', mgdl: 100, mills: now, direction: 'Flat', type: 'sgv', filtered: 113984, unfiltered: 111920, rssi: 179, noise: 1 }
], mbgs: [
{ mgdl: 100, mills: now }
], cals: [
{
device: 'dexcom'
, slope: 895.8571693029189
, intercept: 34281.06876195567
, scale: 1
, type: 'cal'
}
], devicestatus: { uploaderBattery: 100 }
, treatments: [
{
eventType: 'Snack Bolus'
, insulin: '1.00'
, carbs: '18'
, mills: now
}
]
};
var nextData = {
sgvs: [
{ device: 'dexcom', mgdl: 101, mills: next, direction: 'Flat', type: 'sgv', filtered: 113984, unfiltered: 111920, rssi: 179, noise: 1 }
], mbgs: [ ]
, cals: []
, devicestatus: { uploaderBattery: 100 }
, treatments: []
};
describe('client', function ( ) {
var self = this;
before(function (done) {
benv.setup(function() {
self.$ = require('jquery');
self.$.localStorage = {
get: function mockGet (name) {
return name === 'alarmTimeagoWarnMins' ? 99 : undefined;
}
, set: function mockSet (name, value) {
stored[name] = value;
}
, remove: function mockRemove (name) {
removed[name] = true;
}
};
self.$.fn.tipsy = function mockTipsy ( ) { };
var indexHtml = read(__dirname + '/../static/index.html', 'utf8');
self.$('body').html(indexHtml);
var d3 = require('d3');
//disable all d3 transitions so most of the other code can run with jsdom
d3.timer = function mockTimer() { };
benv.expose({
$: self.$
, jQuery: self.$
, d3: d3
, io: {
connect: function mockConnect ( ) {
return {
on: function mockOn ( ) { }
};
}
}
});
done();
});
});
after(function (done) {
benv.teardown();
done();
});
it ('not blow up with mg/dl', function () {
var plugins = require('../lib/plugins/')().registerClientDefaults();
var client = require('../lib/client');
client.init(serverSettings, plugins);
client.dataUpdate(nowData);
});
it ('handle 2 updates', function () {
var plugins = require('../lib/plugins/')().registerClientDefaults();
var client = require('../lib/client');
client.init(serverSettings, plugins);
client.dataUpdate(nowData);
client.dataUpdate(nextData);
});
it ('not blow up with mmol', function () {
serverSettings.settings.units = 'mmol';
serverSettings.settings.timeFormat = 24;
var plugins = require('../lib/plugins/')().registerClientDefaults();
var client = require('../lib/client');
client.init(serverSettings, plugins);
client.dataUpdate(nowData);
});
it ('load, store, and clear settings', function () {
var plugins = require('../lib/plugins/')().registerClientDefaults();
var client = require('../lib/client');
client.init(serverSettings, plugins);
client.dataUpdate(nowData);
var browserSettings = require('../lib/client/browser-settings')(client, plugins, serverSettings, self.$);
browserSettings.alarmTimeagoWarnMins.should.equal(99);
browserSettings.customTitle.should.equal(TEST_TITLE);
self.$('#save').click();
stored.customTitle.should.equal(TEST_TITLE);
self.$('#useDefaults').click();
removed.customTitle.should.equal(true);
});
});