forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportstorage.test.js
60 lines (53 loc) · 1.99 KB
/
reportstorage.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
const should = require('should');
const defaultValues = {
insulin: true,
carbs: true,
basal: true,
notes: false,
food: true,
raw: false,
iob: false,
cob: false,
predicted: false,
openAps: false,
insulindistribution: true,
predictedTruncate: true
};
describe('reportstorage unit tests', () => {
let reportstorage, storage, mockStorage;
beforeEach(() => {
reportstorage = require('../lib/report/reportstorage');
storage = require('js-storage').localStorage;
mockStorage = require('./fixtures/localstorage');
storage.get = mockStorage.get;
storage.set = mockStorage.set;
});
afterEach(() => {
delete require.cache[require.resolve('js-storage')];
delete require.cache[require.resolve('./fixtures/localstorage')];
delete require.cache[require.resolve('../lib/report/reportstorage')];
});
it('reportstorage definition - returns saveProps and getValue function', () => {
reportstorage.should.not.be.undefined();
(reportstorage.getValue instanceof Function).should.be.true();
(reportstorage.saveProps instanceof Function).should.be.true();
});
it('reportstorage.getValue returns default properties', () => {
let keyCount = 0;
for (const v in defaultValues) {
reportstorage.getValue(v).should.equal(defaultValues[v]);
keyCount++;
}
keyCount.should.equal(Object.keys(defaultValues).length);
});
it('reportstorage.saveProps sets property in localstorage', () => {
reportstorage.saveProps({insulin: false});
should.exist(mockStorage.get('reportProperties'));
mockStorage.get('reportProperties').insulin.should.be.false();
});
it('reportstorage.saveProps ignores property not tracked', () => {
reportstorage.saveProps({foo: 'bar'});
should.exist(mockStorage.get('reportProperties'));
should.not.exist(mockStorage.get('reportProperties').foo);
});
});