Skip to content

Commit

Permalink
Breakfast-time is a special case
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 19, 2016
1 parent d28d8a4 commit b5c7af4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
13 changes: 12 additions & 1 deletion app/assets/javascripts/correctiondose.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ function points(json, y_field) {
}
}

function classForBG(value) {
function isBreakfastTime(time) {
if(time >= '06:30' && time <= '11:00') {
return true
}
return false
}

function classForBG(value, time) {
if(isBreakfastTime(time) && value > 7) {
return 'bg-high'
}

if(value > 8) {
return 'bg-high'
}
Expand Down
4 changes: 3 additions & 1 deletion app/views/shared/_javascripts.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script>
$('.glucose-measurement-value .value .number').each(function() {
$(this).parents('td').addClass(classForBG($(this).text()))
var time = $(this).parents('tr').children()[0].innerText
var value = $(this).text()
$(this).parents('td').addClass(classForBG(value, time))
})

$(function () {
Expand Down
21 changes: 18 additions & 3 deletions spec/javascripts/correctiondose_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,31 @@ describe ('ChartWrangler', function() {
})
})

describe('isBreakfastTime()', function() {
it('knows when it is breakfast-time', function() {
expect(isBreakfastTime('08:00')).toEqual(true)
})

it('knows when it is not breakfast-time', function() {
expect(isBreakfastTime('06:15')).toEqual(false)
expect(isBreakfastTime('11:30')).toEqual(false)
})
})

describe('classForBG()', function() {
it('gives the class for a high reading', function() {
expect(classForBG(9)).toEqual('bg-high')
expect(classForBG(9, '12:00')).toEqual('bg-high')
})

it('gives the class for a low reading', function() {
expect(classForBG(4.1)).toEqual('bg-low')
expect(classForBG(4.1, '12:00')).toEqual('bg-low')
})

it('does nothing for an in-range reading', function() {
expect(classForBG(6)).toEqual('bg-ok')
expect(classForBG(6, '12:00')).toEqual('bg-ok')
})

it('knows that breakfast-time is a special case', function() {
expect(classForBG(7.5, '07:30')).toEqual('bg-high')
})
})

0 comments on commit b5c7af4

Please sign in to comment.