Respect macCycleLength in getCyclesBefore

This commit is contained in:
Julia Friesel
2018-12-21 14:48:49 +01:00
parent 9bd0eedfaf
commit 9fd0105506
2 changed files with 126 additions and 0 deletions
+124
View File
@@ -265,6 +265,64 @@ describe('getPreviousCycle', () => {
const result = getPreviousCycle('2018-04-18')
expect(result).to.eql(null)
})
it('returns null when the previous cycle > maxcyclelength', () => {
const cycleDaysSortedByDate = [
{
date: '2018-07-05',
bleeding: { value: 2 }
},
{
date: '2018-06-05',
bleeding: { value: 2 }
},
{
date: '2018-05-05',
mucus: { value: 2 }
},
{
date: '2018-05-04',
bleeding: { value: 2 }
},
{
date: '2018-05-03',
bleeding: { value: 2 }
},
{
date: '2018-04-05',
mucus: { value: 2 }
},
{
date: '2018-04-04',
mucus: { value: 2 }
},
{
date: '2018-04-03',
mucus: { value: 2 }
},
{
date: '2018-04-02',
bleeding: { value: 2 }
},
]
const cycleStarts = [
'2018-07-05',
'2018-06-05',
'2018-05-03',
'2018-04-02'
]
const { getPreviousCycle } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
return cycleStarts.includes(d.date)
}),
maxCycleLength: 2
})
const result = getPreviousCycle('2018-06-08')
expect(result).to.eql(null)
})
})
describe('getCyclesBefore', () => {
@@ -362,6 +420,72 @@ describe('getCyclesBefore', () => {
]
])
})
it('skips cycle that are longer than max', () => {
const cycleDaysSortedByDate = [
{
date: '2018-07-05',
bleeding: { value: 2 }
},
{
date: '2018-06-05',
bleeding: { value: 2 }
},
{
date: '2018-05-05',
mucus: { value: 2 }
},
{
date: '2018-05-04',
bleeding: { value: 2 }
},
{
date: '2018-05-03',
bleeding: { value: 2 }
},
{
date: '2018-04-05',
mucus: { value: 2 }
},
{
date: '2018-04-04',
mucus: { value: 2 }
},
{
date: '2018-04-03',
mucus: { value: 2 }
},
{
date: '2018-04-02',
bleeding: { value: 2 }
},
]
const cycleStarts = [
'2018-07-05',
'2018-06-05',
'2018-05-03',
'2018-04-02'
]
const { getCyclesBefore } = cycleModule({
cycleDaysSortedByDate,
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
return cycleStarts.includes(d.date)
}),
maxCycleLength: 2
})
const result = getCyclesBefore(cycleDaysSortedByDate[0])
expect(result.length).to.eql(1)
expect(result).to.eql([
[
{
date: '2018-06-05',
bleeding: { value: 2 }
}
]
])
})
})
describe('getCycleForDay', () => {