Respect maxcyclelength in getCycleForStartDay
This commit is contained in:
+5
-2
@@ -65,17 +65,20 @@ export default function config(opts) {
|
||||
}
|
||||
|
||||
function getCycleForCycleStartDay(startDay) {
|
||||
// TODO this needs to be made cycle length aware. all other places can go?
|
||||
const cycleStartIndex = cycleDaysSortedByDate.indexOf(startDay)
|
||||
const i = cycleStartsSortedByDate.indexOf(startDay)
|
||||
const nextMensesStart = cycleStartsSortedByDate[i - 1]
|
||||
let cycle
|
||||
if (nextMensesStart) {
|
||||
return cycleDaysSortedByDate.slice(
|
||||
cycle = cycleDaysSortedByDate.slice(
|
||||
cycleDaysSortedByDate.indexOf(nextMensesStart) + 1,
|
||||
cycleStartIndex + 1,
|
||||
)
|
||||
} else {
|
||||
return cycleDaysSortedByDate.slice(0, cycleStartIndex + 1)
|
||||
cycle = cycleDaysSortedByDate.slice(0, cycleStartIndex + 1)
|
||||
}
|
||||
return cycle.length > maxCycleLength ? null : cycle
|
||||
}
|
||||
|
||||
function getCycleForDay(dayOrDate) {
|
||||
|
||||
+41
-2
@@ -71,8 +71,6 @@ describe('getCycleDayNumber', () => {
|
||||
const result = getCycleDayNumber(targetDate)
|
||||
expect(result).to.be.null()
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
describe('getPreviousCycle', () => {
|
||||
@@ -433,6 +431,47 @@ describe('getCycleForDay', () => {
|
||||
expect(result).to.eql(null)
|
||||
})
|
||||
|
||||
it('returns null if the cycle is longer than the max', () => {
|
||||
const { getCycleForDay } = cycleModule({
|
||||
cycleDaysSortedByDate,
|
||||
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
|
||||
return cycleStarts.includes(d.date)
|
||||
}),
|
||||
maxCycleLength: 3
|
||||
})
|
||||
const result = getCycleForDay('2018-04-04')
|
||||
expect(result).to.eql(null)
|
||||
})
|
||||
|
||||
it('returns the cycle if the cycle is shorter or equal max', () => {
|
||||
const { getCycleForDay } = cycleModule({
|
||||
cycleDaysSortedByDate,
|
||||
cycleStartsSortedByDate: cycleDaysSortedByDate.filter(d => {
|
||||
return cycleStarts.includes(d.date)
|
||||
}),
|
||||
maxCycleLength: 4
|
||||
})
|
||||
const result = getCycleForDay('2018-04-04')
|
||||
expect(result).to.eql([
|
||||
{
|
||||
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 }
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('gets cycle for day', () => {
|
||||
const result = getCycleForDay('2018-04-04')
|
||||
expect(result.length).to.eql(4)
|
||||
|
||||
Reference in New Issue
Block a user