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

Shorten line lengths in cycle

parent 63154be2
No related branches found
No related tags found
No related merge requests found
......@@ -28,19 +28,20 @@ export default function config(opts) {
return day
})
const firstBleedingBeforeTargetDayIndex = withWrappedDates.findIndex(day => {
// the index of the first bleeding day before the target day
const index = withWrappedDates.findIndex(day => {
return (
day.wrappedDate.isEqual(targetDate) ||
day.wrappedDate.isBefore(targetDate)
)
})
if (firstBleedingBeforeTargetDayIndex < 0) {
if (index < 0) {
withWrappedDates.forEach(day => delete day.wrappedDate)
return null
}
const prevBleedingDays = withWrappedDates.slice(firstBleedingBeforeTargetDayIndex)
const prevBleedingDays = withWrappedDates.slice(index)
const lastMensesStart = prevBleedingDays.find((day, i) => {
return noBleedingDayWithinThreshold(day, prevBleedingDays.slice(i + 1))
......
......@@ -5,6 +5,10 @@ import cycleModule from '../lib/cycle'
const expect = chai.expect
chai.use(dirtyChai)
function useBleedingDays(days) {
return cycleModule({ bleedingDaysSortedByDate: days }).getCycleDayNumber
}
describe('getCycleDay', () => {
it('works for a simple example', () => {
const bleedingDays = [{
......@@ -23,7 +27,7 @@ describe('getCycleDay', () => {
value: 2
}
}]
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const getCycleDayNumber = useBleedingDays(bleedingDays)
const targetDate = '2018-05-17'
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(9)
......@@ -49,7 +53,7 @@ describe('getCycleDay', () => {
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(15)
})
......@@ -73,7 +77,7 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-04-27'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(18)
})
......@@ -87,7 +91,7 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-05-13'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(1)
})
......@@ -96,7 +100,7 @@ describe('getCycleDay', () => {
it('if there are no bleeding days', function () {
const bleedingDays = []
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays }).getCycleDayNumber
const getCycleDayNumber = useBleedingDays(bleedingDays)
const result = getCycleDayNumber(targetDate)
expect(result).to.be.null()
})
......@@ -119,7 +123,10 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const getCycleDayNumber = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
}).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8)
})
......@@ -137,7 +144,10 @@ describe('getCycleDay', () => {
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = cycleModule({ bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }).getCycleDayNumber
const getCycleDayNumber = cycleModule({
bleedingDaysSortedByDate: bleedingDays,
maxBreakInBleeding
}).getCycleDayNumber
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4)
})
......
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