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