Skip to content

Commit

Permalink
nightscout#6701 Report storage tests
Browse files Browse the repository at this point in the history
Functional and unit tests
  • Loading branch information
mg80 committed Jan 29, 2021
1 parent c91ec78 commit a45d4ae
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/reports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,19 @@ describe('reports', function ( ) {
});

});

it ('Report preferences should stick when refreshing page', function (done) {
const client = window.Nightscout.client;
window.Nightscout.reportclient();
client.init(function afterInit ( ) {
client.dataUpdate(nowData);
( $('#rp_optionsinsulin').prop('checked')).should.be.true();
$('#rp_optionsinsulin').click();
$('#rp_show').click();
location.reload();
($('#rp_optionsinsulin').prop('checked')).should.be.false();
done()
});
});

});
54 changes: 54 additions & 0 deletions tests/reportstorage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const should = require('should');
const reportstorage = require('../lib/report/reportstorage');

describe('reportstorage unit tests', () => {

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', () => {
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
};
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', () => {
const storage = require('js-storage').localStorage;
const mockStorage = require('./fixtures/localstorage');
storage.get = mockStorage.get;
storage.set = mockStorage.set;
reportstorage.saveProps({insulin: false});
should.exist(mockStorage.get('reportProperties'));
mockStorage.get('reportProperties').insulin.should.be.false();
});

it('reportstorage.saveProps ignores property not tracked', () => {
const storage = require('js-storage').localStorage;
const mockStorage = require('./fixtures/localstorage');
storage.get = mockStorage.get;
storage.set = mockStorage.set;
reportstorage.saveProps({foo: 'bar'});
should.exist(mockStorage.get('reportProperties'));
should.not.exist(mockStorage.get('reportProperties').foo);
});
});

0 comments on commit a45d4ae

Please sign in to comment.