Respect macCycleLength in getCyclesBefore
This commit is contained in:
@@ -62,6 +62,8 @@ export default function config(opts) {
|
||||
return cycleStartsSortedByDate
|
||||
.slice(startFromHere)
|
||||
.map(getCycleForCycleStartDay)
|
||||
// filter the ones exceeding macCycleLength
|
||||
.filter(cycle => cycle)
|
||||
}
|
||||
|
||||
function getCycleForCycleStartDay(startDay) {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user