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