Fix bug for just one bleeding day
This commit is contained in:
@@ -16,7 +16,13 @@ export default function config(opts = {}) {
|
|||||||
return day
|
return day
|
||||||
})
|
})
|
||||||
|
|
||||||
const firstBleedingDayBeforeTargetDayIndex = withWrappedDates.findIndex(day => day.wrappedDate.isBefore(targetDate))
|
const firstBleedingDayBeforeTargetDayIndex = withWrappedDates.findIndex(day => {
|
||||||
|
return (
|
||||||
|
day.wrappedDate.isEqual(targetDate) ||
|
||||||
|
day.wrappedDate.isBefore(targetDate)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
if (firstBleedingDayBeforeTargetDayIndex < 0) return null
|
if (firstBleedingDayBeforeTargetDayIndex < 0) return null
|
||||||
const previousBleedingDays = withWrappedDates.slice(firstBleedingDayBeforeTargetDayIndex)
|
const previousBleedingDays = withWrappedDates.slice(firstBleedingDayBeforeTargetDayIndex)
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,20 @@ describe('getCycleDay', () => {
|
|||||||
const result = getCycleDayNumber(targetDate)
|
const result = getCycleDayNumber(targetDate)
|
||||||
expect(result).to.eql(18)
|
expect(result).to.eql(18)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('gets the correct number if the target day is the only bleeding day', () => {
|
||||||
|
const bleedingDays = [{
|
||||||
|
date: '2018-05-13',
|
||||||
|
bleeding: {
|
||||||
|
value: 2
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
|
const targetDate = '2018-05-13'
|
||||||
|
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
|
||||||
|
const result = getCycleDayNumber(targetDate)
|
||||||
|
expect(result).to.eql(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getCycleDay returns null', () => {
|
describe('getCycleDay returns null', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user