Fix bug for just one bleeding day

This commit is contained in:
Julia Friesel
2018-06-11 14:56:34 +02:00
parent ab1ed96966
commit 9922b2e7b8
2 changed files with 21 additions and 1 deletions
+7 -1
View File
@@ -16,7 +16,13 @@ export default function config(opts = {}) {
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
const previousBleedingDays = withWrappedDates.slice(firstBleedingDayBeforeTargetDayIndex)
+14
View File
@@ -78,6 +78,20 @@ describe('getCycleDay', () => {
const result = getCycleDayNumber(targetDate)
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', () => {