forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profileeditor.test.js
182 lines (151 loc) · 4.79 KB
/
profileeditor.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
'use strict';
require('should');
var _ = require('lodash');
var benv = require('benv');
var read = require('fs').readFileSync;
var nowData = require('../lib/data/ddata')();
nowData.sgvs.push({ mgdl: 100, mills: Date.now(), direction: 'Flat', type: 'sgv' });
var exampleProfile = {
defaultProfile : 'Default'
, store: {
'Default' : {
//General values
'dia':3,
// Simple style values, 'from' are in minutes from midnight
'carbratio': [
{
'time': '00:00',
'value': 30
}],
'carbs_hr':30,
'delay': 20,
'sens': [
{
'time': '00:00',
'value': 100
}
, {
'time': '8:00',
'value': 80
}],
'startDate': new Date(),
'timezone': 'UTC',
//perGIvalues style values
'perGIvalues': false,
'carbs_hr_high': 30,
'carbs_hr_medium': 30,
'carbs_hr_low': 30,
'delay_high': 15,
'delay_medium': 20,
'delay_low': 20,
'basal':[
{
'time': '00:00',
'value': 0.1
}],
'target_low':[
{
'time': '00:00',
'value': 100
}],
'target_high':[
{
'time': '00:00',
'value': 120
}]
}
}
};
var someData = {
'/api/v1/profile.json?count=20': [exampleProfile]
};
describe('Profile editor', function ( ) {
this.timeout(40000); //TODO: see why this test takes longer on Travis to complete
var headless = require('./fixtures/headless')(benv, this);
before(function (done) {
done( );
});
after(function (done) {
done( );
});
beforeEach(function (done) {
var opts = {
htmlFile: __dirname + '/../views/profileindex.html'
, mockProfileEditor: true
, mockAjax: someData
, benvRequires: [
__dirname + '/../static/js/profileinit.js'
]
};
headless.setup(opts, done);
});
afterEach(function (done) {
headless.teardown( );
done( );
});
it ('should produce some html', function (done) {
var client = require('../lib/client');
var hashauth = require('../lib/client/hashauth');
hashauth.init(client,$);
hashauth.verifyAuthentication = function mockVerifyAuthentication(next) {
hashauth.authenticated = true;
next(true);
};
window.confirm = function mockConfirm (text) {
console.log('Confirm:', text);
return true;
};
window.alert = function mockAlert () {
return true;
};
window.Nightscout.profileclient();
client.init();
client.dataUpdate(nowData);
// var result = $('body').html();
// console.log(result);
//var filesys = require('fs');
//var logfile = filesys.createWriteStream('out.html', { flags: 'a'} )
//logfile.write($('body').html());
// database records manipulation
$('#pe_databaserecords option').length.should.be.equal(1);
$('#pe_records_add').click();
$('#pe_databaserecords option').length.should.be.equal(2);
$('#pe_records_remove').click();
$('#pe_databaserecords option').length.should.be.equal(1);
$('#pe_records_clone').click();
$('#pe_databaserecords option').length.should.be.equal(2);
$('#pe_databaserecords option').val(0);
//console.log($('#pe_databaserecords').html());
//console.log($('#pe_databaserecords').val());
// database records manipulation
$('#pe_profiles option').length.should.be.equal(1);
$('#pe_profile_add').click();
$('#pe_profiles option').length.should.be.equal(2);
$('#pe_profile_name').val('Test');
$('#pe_profiles option').val('Default');
$('#pe_profiles option').val('Test');
$('#pe_profile_remove').click();
$('#pe_profiles option').length.should.be.equal(1);
$('#pe_profile_clone').click();
$('#pe_profiles option').length.should.be.equal(2);
$('#pe_profiles option').val('Default');
//console.log($('#pe_profiles').html());
//console.log($('#pe_profiles').val());
// I:C range
$('#pe_ic_val_0').val().should.be.equal('30');
$('#pe_ic_placeholder').find('img.addsingle').click();
$('#pe_ic_val_0').val().should.be.equal('0');
$('#pe_ic_val_1').val().should.be.equal('30');
$('#pe_ic_placeholder').find('img.delsingle').click();
$('#pe_ic_val_0').val().should.be.equal('30');
// traget bg range
$('#pe_targetbg_low_0').val().should.be.equal('100');
$('#pe_targetbg_placeholder').find('img.addtargetbg').click();
$('#pe_targetbg_low_0').val().should.be.equal('0');
$('#pe_targetbg_low_1').val().should.be.equal('100');
$('#pe_targetbg_placeholder').find('img.deltargetbg').click();
$('#pe_targetbg_low_0').val().should.be.equal('100');
$('#pe_submit').click();
done();
});
});