Skip to content
Snippets Groups Projects
Commit 9922b2e7 authored by Julia Friesel's avatar Julia Friesel
Browse files

Fix bug for just one bleeding day

parent ab1ed969
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment